diff --git a/routers/upload.js b/routers/upload.js index 7898865..65af9e7 100644 --- a/routers/upload.js +++ b/routers/upload.js @@ -3,7 +3,7 @@ const fs = require('fs-extra'); const { DateTime } = require('luxon'); const { WebhookClient, MessageEmbed } = require('discord.js'); const { doUpload, processUploaded } = require('../storage'); -const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType } = require('../config.json'); +const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType, spaceReplace } = require('../config.json'); const { path, log, verify, getTrueHttp, getTrueDomain, generateId, formatBytes } = require('../utils'); const { CODE_UNAUTHORIZED, CODE_PAYLOAD_TOO_LARGE } = require('../MagicNumbers.json'); const data = require('../data'); @@ -61,6 +61,9 @@ router.post('/', (req, res, next) => { color: req.headers['x-ass-og-color'] }; + // Fix spaces in originalname + req.file.originalname = req.file.originalname.replace(/\s/g, spaceReplace === '!' ? '' : spaceReplace); + // Save the file information const resourceId = generateId(generator, resourceIdSize, req.headers['x-ass-gfycat'] || gfyIdSize, req.file.originalname); log.debug('Saving data', data.name); diff --git a/setup.js b/setup.js index 246f2b8..238d503 100755 --- a/setup.js +++ b/setup.js @@ -9,6 +9,7 @@ const config = { resourceIdSize: 12, gfyIdSize: 2, resourceIdType: 'random', + spaceReplace: '_', mediaStrict: false, viewDirect: false, frontendName: 'ass-x', @@ -132,6 +133,14 @@ function doSetup() { pattern: /(original|zws|random|gfycat)/gi, // skipcq: JS-0113 message: 'Must be one of: zws, random, gfycat, original' }, + spaceReplace: { + description: 'Character to replace spaces in filenames with (must be a hyphen -, underscore _, or use ! to remove spaces)', + type: 'string', + default: config.spaceReplace, + required: false, + pattern: /^[-_!]$/gim, + message: 'Must be a - , _ , or !' + }, gfyIdSize: { description: 'Adjective count for "gfycat" URL type', type: 'integer',