You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ass/utils.js

21 lines
807 B

4 years ago
const fs = require('fs-extra');
const Path = require('path');
const zwsGen = require('./idgen/zws');
4 years ago
const randomGen = require('./idgen/random');
const idModes = {
zws: 'zws', // Zero-width spaces (see: https://zws.im/)
og: 'original', // Use original uploaded filename
r: 'random' // Use a randomly generated ID with a mixed-case alphanumeric character set
};
4 years ago
module.exports = {
log: console.log,
path: (...paths) => Path.join(__dirname, ...paths),
saveData: (data) => fs.writeJsonSync(Path.join(__dirname, 'data.json'), data, { spaces: 4 }),
verify: (req, tokens) => req.headers.authorization && tokens.includes(req.headers.authorization),
generateId: (mode, lenth, originalName) =>
(mode == idModes.zws) ? zwsGen(lenth)
4 years ago
: (mode == idModes.r) ? randomGen(lenth)
: originalName
4 years ago
}