Added options to replace or remove spaces in filenames (must run `npm run setup`)

pull/67/head
tycrek 3 years ago
parent 1dfcb0489e
commit 0c1758cea1
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -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);

@ -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',

Loading…
Cancel
Save