TannerReynolds / ShareX-Upload-Server

AKA ShareS - Feature full & Stable ShareX and file server in node. Includes images, videos, code, text, markdown rendering, password protected uploads, logging via discord, administration through Discord, url shortening, and a full front end. Use standalone or via reverse proxy
GNU General Public License v3.0
392 stars 111 forks source link
api custom discord discordapp discordbot easy ejs express file-upload gallery nodejs screenshot shares sharex sharex-server uploader url-shortener webserver website

ShareS - A Nodejs ShareX Upload Server

Join Our Discord!

Features

Installation (Ubuntu 16.04 Server)

git clone https://github.com/TannerReynolds/ShareX-Upload-Server.git
cd ShareX-Upload-Server
chmod +x install.sh
./install.sh

Docker

docker build -t sharex-upload-server .
docker run --name "sharex-upload-server" -d \
    -v $(pwd)/src/config.json:/usr/src/app/config.json \
    -v $(pwd)/src/db.json:/usr/src/app/db.json \
    -v $(pwd)/src/server/uploads/:/usr/src/app/server/uploads/ \
    -p 8000:80 -p 8443:443 \
    sharex-upload-server
docker logs -f sharex-upload-server

/src/config.json will be the config file used if you used the above command to start the server. The web UI will be available on https://server-ip:8443 if https is enabled, and http://server-ip:8000 if it isn't.

Configuration

In the files you downloaded from this repository, you will see a file called config.json You must fill this out for the webserver to work properly. Below explains the configuration file and what each part does

{
  "key": [""], // Password(s) for private uploading
  "domain": "*.example.com", // Domain server will use. Will error if domain not used in request. Place "*" as the subdomain to enable wildcard subdomains for the webserver.
  "puploadKeyGenLength": 64, // Amount of characters server should use for pupload files
  "public": false, // Disables auth and does not render a password field for /upload
  "maxUploadSize": 50, // max upload size for non-admins using regular key in MB
  "markdown": true, // enables markdown rendering (upload whole .md file for render)
  "port": 80, // port to listen on
  "secure": true, // Whether or not you want https. (make sure key and cert.pem are in src directory)
  "fileNameLength": 4, // File name length
  "shortUrlLength": 3, // File name length for short URLs
  "securePort": 443, // Port to use when secure is true
  "ratelimit": 1000, // Ratelimit for POSTing in milliseconds
  "dateURLPath": false, // Set to true to prefix uploads with the date (Ex: https://domain.com/2020/04/22/ghNa.pdf)
  "allowed":[
    "png", "jpg", "gif", "mp4", "mp3", "jpeg", "tiff", "bmp", "ico", "psd", "eps", "raw", "cr2", "nef", "sr2", "orf", "svg", "wav", "webm", "aac", "flac", "ogg", "wma", "m4a", "gifv"
  ], // Allowed file types for non-admins
  "admin":{
    "key": [""], // Admin password(s) for uploading & for gallery access
    "maxUploadSize": 1024, // Max upload size for admin in MB
    "allowed": [
    "png", "jpg", "gif", "mp4", "mp3","jpeg", "tiff", "bmp", "ico", "psd", "eps", "raw", "cr2", "nef", "sr2", "orf", "svg", "wav", "webm", "aac", "flac", "ogg", "wma", "m4a", "gifv", "html"
     ] // Allowed file types for admins
  },
  "paste": {
    "maxUploadSize": 20 // allowed paste upload size in MB
  },
  "discordToken": "", // Discord bot token
  "discordAdminIDs": ["discord IDs of people who can run commands go here", "Like this"], // User IDs in an array
  "discordChannelID": "", // Channel ID for monitoring uploads to
  "prefix": "" // Bot Prefix
}

Running The Server

Once you've properly configured your server, you can run node index.js in the src folder to start the server. You can keep your server running forever if you use a process manager, like pm2. pm2 installs along with your server if you used the install.sh script to install your server. Otherwise you can run npm i -g pm2 to install pm2. Then you can run your server by running pm2 start index.js, and monitor logs and such using pm2 monit

Note: Nginx/reverse proxy users

If you're configuring this webserver to run through an Nginx reverse proxy, make sure you add these lines to your reverse proxy config

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

This is generally some things you want to add to your config, and is what's actually required for ShareS to work properly. This is because ShareS returns uploads like [http/https]://[requested url]/[filename] and since you're running ShareS through a reverse proxy, unless you're passing along the original headers, ShareS is most likely just going to send you something like http://[server's real ip address]/[filename]

Note: Users of multiple domains

If you have multiple domains pointed to this webserver, only one (can include wildcard subdomain) can be used, unless the domain setting is set to just a single like so: `"domain": "",`. This means that any domain will be accepted as a valid domain by the server, regardless of subdomain.

Setting up Discord logging

if you wish to log your webserver's activity in a Discord channel for whatever reason, you can. Here is information on how to setup a bot account and get the information needed for Discord logging

Configuring Your ShareX Client

Configuring for Password Protected Uploading

Auto Password Generation

In addition to being able to use any password you want for puploads, if you type in *random* as your pupload field, the server will automatically generate a password for you. This password will include letters, numbers, and special characters. It will generate a key based on the length you specify in your config (puploadKeyGenLength). When making requests, the server will return the image URL with the key like so URL: https://qoilo.com/lhHr | KEY: Np$[CBk>X[c^YY{MDlCHH0|Qfm1uK0*lld^Mi$f4d62R5x6C2>~yaL}3*QYnziuZ

Showcase Field

Using with Flameshot (Linux)

In order to use ShareS with Flameshot you will need to use a simple script, here is an example:

key="YourPassword"
# Only needed for multi-domain support, if you only have one simply set the url
# 2 lines below to url="https://your.domain/api/files"
urls=("https://example.com/api/files" "https://example.org/api/files")
url=${urls[$RANDOM % ${#urls[@]}]}

temp_file="/tmp/screenshot.png"

# Run flameshot --help for options
flameshot gui -r > $temp_file

# For some reason flameshot always seems to exit with 0 even when aborting the process
# so we had to find a way around that.
if [[ $(file --mime-type -b $temp_file) != "image/png" ]]; then
    rm $temp_file
  notify-send "Screenshot aborted" -a "Flameshot" && exit 1
fi

image_url=$(curl -X POST -F "fdata=@"$temp_file -F "key="$key -v "$url" 2>/dev/null)
echo -n $image_url | xclip -sel c
notify-send "Image URL copied to clipboard" "$image_url" -a "Flameshot" -i $temp_file
rm $temp_file

When running this script simply hit enter when you're satisfied with your image, Flameshot will then save the image to your clipboard which will then be replaced with the image URL once it's uploaded. For the best results I suggest disabling notifications in the Flameshot app.

Contributing

Pull Requests

Bug Reports

Credits

Ken - Initial File Uploader

Aetheryx - Webserver Structure

Jaex - ShareX

FancyApps - Gallery lightbox script for displaying images, videos and more

Cheap Hosting Options For Your Uploader