minor fixes

pull/15/head
tycrek 4 years ago
parent f93053481a
commit 5f9af34ac6
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -19,25 +19,25 @@ const { path, saveData, log, verify, generateToken, generateId } = require('./ut
//#region Variables, module setup
const app = express();
// Configure filename and location settings
const storage = multer.diskStorage({
destination: saveWithDate ? (req, file, cb) => {
filename: saveAsOriginal ? (_req, file, callback) => callback(null, file.originalname) : null,
destination: !saveWithDate ? diskFilePath : (_req, _file, callback) => {
// Get current month and year
const [month, day, year] = new Date().toLocaleDateString("en-US").split("/")
let [month, _day, year] = new Date().toLocaleDateString("en-US").split("/");
// Add 0 before single digit months eg ( 6 turns into 06)
const folder = `${diskFilePath}/${year}-${("0" + month).slice(-2)}`
let folder = `${diskFilePath}/${year}-${("0" + month).slice(-2)}`;
// Create folder if it doesn't exist
fs.ensureDirSync(folder)
fs.ensureDirSync(folder);
cb(null, folder)
} : diskFilePath,
callback(null, folder);
}
});
filename: saveAsOriginal ? (req, file, cb) => cb(null, file.originalname) : null,
})
var upload = multer({ storage: storage })
var upload = multer({ storage });
var tokens = [];
var data = {};
//#endregion

@ -68,20 +68,20 @@ const setupSchema = {
pattern: /(original|zws|random)/gi,
message: 'Must be one of: original, zws, random'
},
saveWithDate: {
description: 'Do you want to use date folder structure? Eg (uploads/2021-04/image.png)',
type: 'boolean',
default: config.saveWithDate,
required: false
},
diskFilePath: {
description: 'Where on the disk do you want to save?',
description: 'Relative path to save uploads to',
type: 'string',
default: config.diskFilePath,
required: false
},
saveWithDate: {
description: 'Use date folder structure (e.x. uploads/2021-04/image.png)',
type: 'boolean',
default: config.saveWithDate,
required: false
},
saveAsOriginal: {
description: 'Save as original file name? (Use file name instead of randomly generated characters)',
description: 'Save as original file name instead of random',
type: 'boolean',
default: config.saveAsOriginal,
required: false

Loading…
Cancel
Save