Compare commits

..

2 Commits

Author SHA1 Message Date
7f57c0ed23 Merge branch 'master' of gitea.moe:lamp/qonq 2021-10-22 17:43:22 -05:00
292ff9297d custom url gen 2021-10-22 17:42:17 -05:00
2 changed files with 6 additions and 7 deletions

View File

@ -17,8 +17,8 @@ The following environment variables are optional.
| Variable | Description | Default |
|----------|-------------|---------|
| `HOSTNAMES` | Comma-separated list of hostnames that will be chosen at random for the URL sent back after an upload. | request hostname |
| `DISCORD_WEBHOOK` | Discord webhook url that uploads will be sent to to make them pre-load the embed, which theoretically makes it faster. | `undefined` (disabled) |
| `HOSTNAME` | Overrides the hostname for generating URLs. | hostname of the upload request |
| `DISCORD_WEBHOOK` | Discord webhook url that newly-uploaded URLs will be sent to to pre-load their embed, which theoretically makes them embed again faster. | `undefined` (disabled) |
| `PORT` | TCP port to listen on | `8568` |
| `ADDRESS` | Address to bind to | `'0.0.0.0'` (all) |
| `FILES_DIR` | Directory to store the files in | `'files'` (relative of working directory) |

View File

@ -6,12 +6,11 @@ var serveIndex = require("serve-index");
var serveFavicon = require("serve-favicon");
var path = require("path");
var fs = require("fs");
try {
var customUrlGen = require("./custom-urlgen");
} catch(e) {}
var FILES_DIR = process.env.FILES_DIR || "files";
if (process.env.HOSTNAMES) {
var HOSTNAMES = process.env.HOSTNAMES.split(',');
var randomHostname = () => HOSTNAMES[Math.floor(Math.random() * HOSTNAMES.length)];
}
var app = express();
app.set("env", "production");
@ -53,7 +52,7 @@ app.post("*", (req, res, next) => {
else {
fs.rename(file.path, path.join(webroot, file.name), function (error) {
if (error) return void next(error);
let url = `${req.protocol}://${filecode}.${randomHostname?.() || req.hostname}`;
var url = customUrlGen?.(filecode, req) || `${req.protocol}://${filecode}.${process.env.HOSTNAME || req.hostname}`;
res.send(url);
require("./discord-preloader.js")(url);
});