added configurable upload limits & proper upload limit handling (need to re-run setup)

pull/20/head
tycrek 3 years ago
parent 8add5f7ecd
commit 0919939ac7
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -7,7 +7,7 @@ try {
}
// Load the config
const { host, port, useSsl, resourceIdSize, diskFilePath, gfyIdSize, resourceIdType, isProxied, s3enabled } = require('./config.json');
const { host, port, maxUploadSize, useSsl, resourceIdSize, diskFilePath, gfyIdSize, resourceIdType, isProxied, s3enabled } = require('./config.json');
//#region Imports
const fs = require('fs-extra');
@ -113,6 +113,7 @@ function startup() {
// Upload file
app.post('/', doUpload, processUploaded, ({ next }) => next());
app.use('/', (err, _req, res, next) => err.code && err.code === 'LIMIT_FILE_SIZE' ? res.status(413).send(`Max upload size: ${maxUploadSize}MB`) : next(err));
// Process uploaded file
app.post('/', (req, res) => {

@ -3,6 +3,7 @@ const config = {
host: '0.0.0.0',
port: 40115,
domain: 'upload.example.com',
maxUploadSize: 50,
useSsl: true,
isProxied: true,
resourceIdSize: 12,
@ -55,6 +56,12 @@ if (require.main === module) {
required: true,
message: 'You must input a valid domain name or IP to continue'
},
maxUploadSize: {
description: `Max allowable uploaded filesize, in megabytes`,
type: 'integer',
default: config.maxUploadSize,
require: false
},
useSsl: {
description: 'Use SSL (requires reverse proxy!)',
type: 'boolean',

@ -8,7 +8,7 @@ const Thumbnail = require('./thumbnails');
const Vibrant = require('./vibrant');
const Hash = require('./hash');
const { getSafeExt, getDatedDirname, sanitize, generateId } = require('./utils');
const { s3enabled, s3endpoint, s3bucket, s3accessKey, s3secretKey, saveAsOriginal } = require('./config.json');
const { s3enabled, s3endpoint, s3bucket, s3accessKey, s3secretKey, saveAsOriginal, maxUploadSize } = require('./config.json');
const s3 = new aws.S3({
endpoint: new aws.Endpoint(s3endpoint),
@ -97,7 +97,7 @@ function listAllKeys(resolve, reject, token) {
}
module.exports = {
doUpload: multer({ limits: { fileSize: '100MB' } }).single('file'),
doUpload: multer({ limits: { fileSize: `${maxUploadSize}MB` } }).single('file'),
processUploaded,
deleteS3,
bucketSize

Loading…
Cancel
Save