Open-source image host interfaced via a Discord Bot. It features Customizable embeds, config generators, and many more features!
You need Node.js and a package manager such as yarn or NPM.
When hosting, only make the ./users/*
directory public!
For the Discord bot, you need to have a Bot Application and its token.
Create a 'User' role in your Discord Server and get its ID. This role can be given to members who are allowed to use the image host. If a member doesn't have the role he can't use it.
Now fill in config.json
with your domain (without www
or http/https
), your Discord Bot token, a custom prefix and the ID of the role.
{
"domain": "your.domain",
"token": "DISCORD_TOKEN",
"prefix": "CUSTOM_PREFIX",
"userRoleID": "USER_ROLE_ID"
}
In this example, we are using yarn as our package manager. Feel free to use any other package manager and to install [email protected]
and chokidar
with it.
yarn install
Installing without lockfile
If you want to create a new lockfile / set up a new project, you can use the following command to add the required packages:
yarn add [email protected]
yarn add chokidar
node index.js
This code has been designed and written to run on an Ubuntu Server (Ubuntu server LTS 20.04.4). To avoid unnecessary bugs, do not attempt to set this up on a Windows server or home pc because the chances are high, that it will not work.
Service | Installation |
---|---|
nginx (or Apache II) | sudo apt-get install nginx |
php fpm | sudo apt-get install php8.1-fpm |
Node.js | sudo apt-get install node |
npm | sudo apt-get install npm |
After editing all necessary config files, you can upload the code to your server.
You will need to create a directory called /var/www/api.YOUR.HOST/
and place the file structure in it.
You will need to create a directory called /var/www/YOUR.HOST/
which will host your main homepage.
After installing all necessary services and after creating the 2 file paths, you can create the nginx config files which are located in /etc/nginx/sites-enabled
.
The first important config file is for the API. It is important to implement PHP here. Simply copy and paste the below config file to /etc/nxing/sites-enabled/api.YOUR.DOMAIN.conf
.
server {
root /var/www/api.YOUR.DOMAIN;
index index.php;
server_name api.YOUR.DOMAIN;
location / { try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
location ~ /(db|handler|cfg|scripts|node_modules|config.json) {
deny all;
return 404;
}
location ~ /\.ht {
deny all;
}
#
#MAKE SURE YOU SET UP SSL IN THIS CONFIG FILE USING CERTBOT!
#
The second important config file is for the main website. Nothing is needed here apart from setting the document root and web socket. Simply copy and paste the below config file to /etc/nxing/sites-enabled/YOUR.DOMAIN.conf
.
server {
root /var/www/YOUR.DOMAIN;
index index.php;
server_name YOUR.DOMAIN;
location / { try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.ht {
deny all;
}
#
#MAKE SURE YOU SET UP SSL IN THIS CONFIG FILE USING CERTBOT!
#
Now simply run these commands to test if everything works:
sudo systemctl status nginx
sudo systemctl status php8.1-fpm
sudo nginx -t
If you see all services are running and nginx -t
doesn't have any error outputs, you are good to go and can follow the rest of the installation.
If you are using a third party DNS, make sure you create 2 records, the main A record that points to your website to host your frontend (not included in this repo) and an A
record that hosts this API. Both records point to the same IP address, but the API endpoints DNS needs to be a api.YOUR.DOMAIN
subdomain.
This setup is needed to make nginx serve a different root depending on your call.
If everything is set up, your DNS should look something like this:
Make sure to forward port 443
if you are running SSL on your domain or port 80
for ipv6 AND v4 to the local IP of your server / cluster to make the server accessible from the outside world.
Now, the setup should be completed, and you are good to launch the backend.
screen sudo -u www-data node /var/www/api.YOUR.DOMAIN/handler/handler.js
screen sudo -u www-data node /var/www/api.YOUR.DOMAIN/index.js
Your API should be running now!
This project is licensed under the GNU Affero General Public License v3.0.
All contributions (Issues, Pull Requests etc.) are welcome.