more uhhhhh what are these, DeepSource iirc

pull/20/head
tycrek 3 years ago
parent 82736a236c
commit f3e0f9c70d
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -49,7 +49,7 @@ function preStartup() {
// Make sure auth.json exists and generate the first key
if (!fs.existsSync(path('auth.json'))) {
let token = generateToken();
const token = generateToken();
users[token] = { username: 'ass', count: 0 };
fs.writeJsonSync(path('auth.json'), { users }, { spaces: 4 });
log(`File [auth.json] created\n!! Important: save this token in a secure spot: ${Object.keys(users)[0]}\n`);
@ -94,8 +94,8 @@ function startup() {
});
// Generate ID's to use for other functions
app.post('/', (req, _res, next) => (req.randomId = generateId('random', 32, null, null), next()));
app.post('/', (req, _res, next) => (req.deleteId = generateId('random', 32, null, null), next()));
app.post('/', (req, _res, next) => (req.randomId = generateId('random', 32, null, null), next())); // skipcq: JS-0086
app.post('/', (req, _res, next) => (req.deleteId = generateId('random', 32, null, null), next())); // skipcq: JS-0086
// Upload file (local & S3) // skipcq: JS-0093
s3enabled
@ -115,6 +115,7 @@ function startup() {
// Generate the Thumbnail, Vibrant, and SHA1 hash
.then(() => Promise.all([Thumbnail(req.file), Vibrant(req.file), Hash(req.file)]))
// skipcq: JS-0086
.then(([thumbnail, vibrant, sha1]) => (
req.file.thumbnail = thumbnail,
req.file.vibrant = vibrant,
@ -129,7 +130,7 @@ function startup() {
function renameFile(newName) {
return new Promise((resolve, reject) => {
try {
let paths = [req.file.destination, newName];
const paths = [req.file.destination, newName];
fs.rename(path(req.file.path), path(...paths));
req.file.path = Path.join(...paths);
resolve();
@ -143,8 +144,8 @@ function startup() {
// Process uploaded file
app.post('/', (req, res) => {
// Load overrides
let trueDomain = getTrueDomain(req.headers["x-ass-domain"]);
let generator = req.headers["x-ass-access"] || resourceIdType;
const trueDomain = getTrueDomain(req.headers["x-ass-domain"]);
const generator = req.headers["x-ass-access"] || resourceIdType;
// Get the uploaded time in milliseconds
req.file.timestamp = DateTime.now().toMillis();
@ -164,18 +165,18 @@ function startup() {
};
// Save the file information
let resourceId = generateId(generator, resourceIdSize, req.headers['x-ass-gfycat'] || gfyIdSize, req.file.originalname);
const resourceId = generateId(generator, resourceIdSize, req.headers['x-ass-gfycat'] || gfyIdSize, req.file.originalname);
data[resourceId.split('.')[0]] = req.file;
saveData(data);
// Log the upload
let logInfo = `${req.file.originalname} (${req.file.mimetype})`;
const logInfo = `${req.file.originalname} (${req.file.mimetype})`;
log(`Uploaded: ${logInfo} (user: ${users[req.token] ? users[req.token].username : '<token-only>'})`);
// Build the URLs
let resourceUrl = `${getTrueHttp()}${trueDomain}/${resourceId}`;
let thumbnailUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/thumbnail`;
let deleteUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/delete/${req.file.deleteId}`;
const resourceUrl = `${getTrueHttp()}${trueDomain}/${resourceId}`;
const thumbnailUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/thumbnail`;
const deleteUrl = `${getTrueHttp()}${trueDomain}/${resourceId}/delete/${req.file.deleteId}`;
// Send the response
res.type('json').send({ resource: resourceUrl, thumbnail: thumbnailUrl, delete: deleteUrl })
@ -185,8 +186,8 @@ function startup() {
if (req.headers['x-ass-webhook-client'] && req.headers['x-ass-webhook-token']) {
// Build the webhook client & embed
let whc = new WebhookClient(req.headers['x-ass-webhook-client'], req.headers['x-ass-webhook-token']);
let embed = new MessageEmbed()
const whc = new WebhookClient(req.headers['x-ass-webhook-client'], req.headers['x-ass-webhook-token']);
const embed = new MessageEmbed()
.setTitle(logInfo)
.setURL(resourceUrl)
.setDescription(`**Size:** \`${formatBytes(req.file.size)}\`\n**[Delete](${deleteUrl})**`)
@ -204,9 +205,9 @@ function startup() {
// Also update the users upload count
if (!users[req.token]) {
let generateUsername = () => generateId('random', 20, null);
const generateUsername = () => generateId('random', 20, null);
let username = generateUsername();
while (Object.values(users).findIndex((user) => user.username === username) !== -1)
while (Object.values(users).findIndex((user) => user.username === username) !== -1) // skipcq: JS-0073
username = generateUsername();
users[req.token] = { username, count: 0 };
}
@ -226,10 +227,10 @@ function startup() {
// View file
app.get('/:resourceId', (req, res) => {
let { resourceId } = req.ass;
let fileData = data[resourceId];
const { resourceId } = req.ass;
const fileData = data[resourceId];
let requiredItems = {
const requiredItems = {
randomId: fileData.randomId,
originalname: escape(fileData.originalname),
mimetype: fileData.mimetype,
@ -243,7 +244,7 @@ function startup() {
if (req.useragent.isBot) return res.type('html').send(new OpenGraph(getTrueHttp(), getTrueDomain(), resourceId, requiredItems).build());
// Return the file differently depending on what storage option was used
let uploaders = {
const uploaders = {
s3: () => fetch(getS3url(fileData.randomId, fileData.mimetype)).then((file) => {
file.headers.forEach((value, header) => res.setHeader(header, value));
file.body.pipe(res);
@ -259,7 +260,7 @@ function startup() {
// Thumbnail response
app.get('/:resourceId/thumbnail', (req, res) => {
let { resourceId } = req.ass;
const { resourceId } = req.ass;
// Read the file and send it to the client
fs.readFile(path('uploads/thumbnails/', data[resourceId].thumbnail))
@ -271,10 +272,10 @@ function startup() {
// https://oembed.com/
// https://old.reddit.com/r/discordapp/comments/82p8i6/a_basic_tutorial_on_how_to_get_the_most_out_of/
app.get('/:resourceId/oembed.json', (req, res) => {
let { resourceId } = req.ass;
const { resourceId } = req.ass;
// Build the oEmbed object & send the response
let { opengraph, mimetype } = data[resourceId];
const { opengraph, mimetype } = data[resourceId];
res.type('json').send({
version: '1.0',
type: mimetype.includes('video') ? 'video' : 'photo',
@ -287,9 +288,9 @@ function startup() {
// Delete file
app.get('/:resourceId/delete/:deleteId', (req, res) => {
let { resourceId } = req.ass;
let deleteId = escape(req.params.deleteId);
let fileData = data[resourceId];
const { resourceId } = req.ass;
const deleteId = escape(req.params.deleteId);
const fileData = data[resourceId];
// If the delete ID doesn't match, don't delete the file
if (deleteId !== fileData.deleteId) return res.sendStatus(401);

@ -9,13 +9,13 @@ module.exports = () => uuid().replace(/-/g, '');
// If directly called on the command line, generate a new token
if (require.main === module) {
let token = module.exports();
let authPath = path.join(__dirname, '..', 'auth.json');
const token = module.exports();
const authPath = path.join(__dirname, '..', 'auth.json');
fs.readJson(authPath)
.then((auth) => {
// Generate the user
let username = process.argv[2] ? process.argv[2].replace(/[^\da-z_]/gi, '').substring(0, MAX_USERNAME) : randomGen({ length: 20 });
const username = process.argv[2] ? process.argv[2].replace(/[^\da-z_]/gi, '').substring(0, MAX_USERNAME) : randomGen({ length: 20 });
if (!auth.users) auth.users = {};
if (Object.values(auth.users).findIndex((user) => user.username === username) !== -1) {
console.log('Username already exists!');

@ -5,8 +5,8 @@ const { formatBytes } = require('./utils');
const { bucketSize } = require('./storage');
module.exports = () => {
let data = fs.readJsonSync(path.join(__dirname, 'data.json'));
let { users } = fs.readJsonSync(path.join(__dirname, 'auth.json'));
const data = fs.readJsonSync(path.join(__dirname, 'data.json'));
const { users } = fs.readJsonSync(path.join(__dirname, 'auth.json'));
let totalSize = 0;
let oldSize = 0;

@ -25,7 +25,7 @@ if (require.main === module) {
const prompt = require('prompt');
try {
let existingConfig = require('./config.json');
const existingConfig = require('./config.json');
Object.keys(existingConfig).forEach((key) => Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key]))
} catch (ex) { console.log(ex) }
@ -156,7 +156,7 @@ if (require.main === module) {
log('<<< ass setup >>>\n');
let results = {};
prompt.get(setupSchema)
.then((r) => results = r)
.then((r) => results = r) // skipcq: JS-0086
.then(() => Object.keys(results).map((result) => (` ${result}: ${results[result]}`)).join('\n'))
.then((resultString) => log(`\nPlease verify your information:\n\n${resultString}\n`))
.then(() => prompt.get(confirmSchema))

@ -31,10 +31,10 @@ const uploadLocal = multer({
storage: multer.diskStorage({
destination: !saveWithDate ? diskFilePath : (_req, _file, cb) => {
// Get current month and year
let [month, , year] = new Date().toLocaleDateString('en-US').split('/');
const [month, , year] = new Date().toLocaleDateString('en-US').split('/');
// Add 0 before single digit months (6 turns into 06)
let folder = `${diskFilePath}/${year}-${`0${month}`.slice(-2)}`;
const folder = `${diskFilePath}/${year}-${`0${month}`.slice(-2)}`;
// Create folder if it doesn't exist
fs.ensureDirSync(folder);
@ -50,7 +50,7 @@ const bucketSize = () =>
function listAllKeys(resolve, reject, token) {
let allKeys = [];
s3.listObjectsV2({ Bucket: s3bucket, ContinuationToken: token }).promise()
.then((data) => (allKeys = allKeys.concat(data.Contents), data.IsTruncated ? listAllKeys(resolve, reject, data.NextContinuationToken) : resolve(allKeys.length)))
.then((data) => (allKeys = allKeys.concat(data.Contents), data.IsTruncated ? listAllKeys(resolve, reject, data.NextContinuationToken) : resolve(allKeys.length))) // skipcq: JS-0086
.catch(reject);
}

@ -29,12 +29,12 @@ module.exports = {
generateId: (mode, length, gfyLength, originalName) => GENERATORS.has(mode) ? GENERATORS.get(mode)({ length, gfyLength }) : originalName,
formatBytes: (bytes, decimals = 2) => {
if (bytes === 0) return '0 Bytes';
let sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let i = Math.floor(Math.log(bytes) / Math.log(1024));
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(1024));
return parseFloat((bytes / Math.pow(1024, i)).toFixed(decimals < 0 ? 0 : decimals)).toString().concat(` ${sizes[i]}`);
},
randomHexColour: () => { // From: https://www.geeksforgeeks.org/javascript-generate-random-hex-codes-color/
let letters = "0123456789ABCDEF";
const letters = "0123456789ABCDEF";
let colour = '#';
for (let i = 0; i < 6; i++)
colour += letters[(Math.floor(Math.random() * letters.length))];

Loading…
Cancel
Save