Merge pull request #12 from UncleBen69/master

Add Options For File Saving
pull/15/head
Josh Moore 4 years ago committed by GitHub
commit ef9a9a5623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,7 +7,7 @@ try {
}
// Load the config
const { host, port, domain, useSsl, resourceIdSize, resourceIdType, isProxied } = require('./config.json');
const { host, port, domain, useSsl, resourceIdSize, resourceIdType, isProxied, diskFilePath, saveWithDate, saveAsOriginal } = require('./config.json');
//#region Imports
const fs = require('fs-extra');
@ -19,7 +19,25 @@ const { path, saveData, log, verify, generateToken, generateId } = require('./ut
//#region Variables, module setup
const app = express();
const upload = multer({ dest: 'uploads/' });
// Configure filename and location settings
const storage = multer.diskStorage({
destination: saveWithDate ? (req, file, cb) => {
// Get current month and year
const [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)}`
// Create folder if it doesn't exist
fs.ensureDirSync(folder)
cb(null, folder)
} : diskFilePath,
filename: saveAsOriginal ? (req, file, cb) => cb(null, file.originalname) : null,
})
var upload = multer({ storage: storage })
var tokens = [];
var data = {};
//#endregion

@ -15,7 +15,10 @@ const config = {
useSsl: true,
isProxied: true,
resourceIdSize: 12,
resourceIdType: 'zws'
resourceIdType: 'zws',
saveWithDate: false,
diskFilePath: "uploads/",
saveAsOriginal: true,
};
// Schema for setup prompts
@ -64,7 +67,25 @@ const setupSchema = {
require: false,
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?',
type: 'string',
default: config.diskFilePath,
required: false
},
saveAsOriginal: {
description: 'Save as original file name? (Use file name instead of randomly generated characters)',
type: 'boolean',
default: config.saveAsOriginal,
required: false
},
}
};

Loading…
Cancel
Save