attempt fixing DeepSource issues

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

@ -17,7 +17,7 @@ const useragent = require('express-useragent');
const rateLimit = require("express-rate-limit");
const fetch = require('node-fetch');
const marked = require('marked');
const DateTime = require('luxon').DateTime;
const { DateTime } = require('luxon');
const { WebhookClient, MessageEmbed } = require('discord.js');
const OpenGraph = require('./ogp');
const Thumbnail = require('./thumbnails');
@ -33,8 +33,8 @@ const ASS_LOGO = 'https://cdn.discordapp.com/icons/848274994375294986/8d339d4a2f
const app = express();
// Configure filename and location settings
var users = {};
var data = {};
let users = {};
let data = {};
//#endregion
preStartup();
@ -61,7 +61,7 @@ function preStartup() {
log('Users & data read from filesystem');
// Monitor auth.json for changes (triggered by running 'npm run new-token')
fs.watch(path('auth.json'), { persistent: false }, (eventType, _filename) => eventType === 'change' && fs.readJson(path('auth.json'))
fs.watch(path('auth.json'), { persistent: false }, (eventType) => eventType === 'change' && fs.readJson(path('auth.json'))
.then((json) => !(arrayEquals(Object.keys(users), Object.keys(json.users))) && (users = json.users) && log(`New token added: ${Object.keys(users)[Object.keys(users).length - 1]}`))
.catch(console.error));
@ -199,15 +199,15 @@ function startup() {
username: req.headers['x-ass-webhook-username'] || 'ass',
avatarURL: req.headers['x-ass-webhook-avatar'] || ASS_LOGO,
embeds: [embed]
}).then((_msg) => whc.destroy());
}).then(() => whc.destroy());
}
// Also update the users upload count
if (!users[req.token]) {
let generator = () => generateId('random', 20, null);
let username = generator();
while (Object.values(users).findIndex((user) => user.username == username) != -1)
username = generator();
let generateUsername = () => generateId('random', 20, null);
let username = generateUsername();
while (Object.values(users).findIndex((user) => user.username === username) !== -1)
username = generateUsername();
users[req.token] = { username, count: 0 };
}
users[req.token].count += 1;
@ -226,7 +226,7 @@ function startup() {
// View file
app.get('/:resourceId', (req, res) => {
let resourceId = req.ass.resourceId;
let { resourceId } = req.ass;
let fileData = data[resourceId];
let requiredItems = {
@ -259,7 +259,7 @@ function startup() {
// Thumbnail response
app.get('/:resourceId/thumbnail', (req, res) => {
let resourceId = req.ass.resourceId;
let { resourceId } = req.ass;
// Read the file and send it to the client
fs.readFile(path('uploads/thumbnails/', data[resourceId].thumbnail))
@ -271,7 +271,7 @@ 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.resourceId;
let { resourceId } = req.ass;
// Build the oEmbed object & send the response
let { opengraph, mimetype } = data[resourceId];
@ -287,7 +287,7 @@ function startup() {
// Delete file
app.get('/:resourceId/delete/:deleteId', (req, res) => {
let resourceId = req.ass.resourceId;
let { resourceId } = req.ass;
let deleteId = escape(req.params.deleteId);
let fileData = data[resourceId];
@ -317,5 +317,5 @@ function getTrueHttp() {
}
function getTrueDomain(d = domain) {
return d.concat((port == 80 || port == 443 || isProxied) ? '' : `:${port}`);
return d.concat((port === 80 || port === 443 || isProxied) ? '' : `:${port}`);
}

@ -5,7 +5,7 @@ const MIN_LENGTH = require('../setup').gfyIdSize;
function genString(count = MIN_LENGTH) {
let gfycat = '';
for (i = 0; i < (count < MIN_LENGTH ? MIN_LENGTH : count); i++)
for (let i = 0; i < (count < MIN_LENGTH ? MIN_LENGTH : count); i++)
gfycat += getWord(adjectives, '-');
return gfycat.concat(getWord(animals));
};

@ -17,7 +17,7 @@ if (require.main === module) {
// Generate the user
let 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) {
if (Object.values(auth.users).findIndex((user) => user.username === username) !== -1) {
console.log('Username already exists!');
process.exit(1);
}

@ -1,3 +1,3 @@
const { randomBytes } = require('crypto');
const zeroWidthChars = ['\u200B', '\u200C', '\u200D', '\u2060'];
module.exports = ({ length }) => [...randomBytes(length)].map(byte => zeroWidthChars[+byte % zeroWidthChars.length]).join('').slice(1) + zeroWidthChars[0];
module.exports = ({ length }) => [...randomBytes(length)].map(byte => zeroWidthChars[Number(byte) % zeroWidthChars.length]).join('').slice(1) + zeroWidthChars[0];

@ -13,7 +13,7 @@ module.exports = () => {
Object.values(data).forEach(({ token, size }) => {
try {
totalSize += size;
if (token == null) oldSize += size;
if (token === undefined) oldSize += size;
else {
if (!users[token].size) users[token].size = 0;
users[token].size += size;

@ -1,5 +1,5 @@
// Default configuration
var config = {
const config = {
host: '0.0.0.0',
port: 40115,
domain: 'upload.example.com',
@ -26,7 +26,7 @@ if (require.main === module) {
try {
let existingConfig = require('./config.json');
Object.keys(existingConfig).forEach((key) => config.hasOwnProperty(key) && (config[key] = existingConfig[key]))
Object.keys(existingConfig).forEach((key) => Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key]))
} catch (ex) { console.log(ex) }
// Disabled the annoying "prompt: " prefix and removes colours
@ -153,19 +153,16 @@ if (require.main === module) {
}
};
function setup() {
log('<<< ass setup >>>\n');
let results;
prompt.get(setupSchema)
.then((r) => results = r)
.then(() => log('\nPlease verify your information:\n\n' + Object.keys(results).map((result) => (` ${result}: ${results[result]}`)).join('\n') + '\n'))
.then(() => prompt.get(confirmSchema))
.then(({ confirm }) => confirm ? fs.writeJson(path('config.json'), results, { spaces: 4 }) : process.exit(1))
.then(() => log('\nConfig has been saved!'))
.catch((err) => console.error(err));
}
setup();
log('<<< ass setup >>>\n');
let results = {};
prompt.get(setupSchema)
.then((r) => results = r)
.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))
.then(({ confirm }) => confirm ? fs.writeJson(path('config.json'), results, { spaces: 4 }) : process.exit(1))
.then(() => log('\nConfig has been saved!'))
.catch((err) => console.error(err));
}
module.exports = config;

@ -15,7 +15,7 @@ const s3 = new aws.S3({
const uploadS3 = multer({
storage: multerS3({
s3: s3,
s3,
bucket: s3bucket,
acl: 'public-read',
key: (req, file, cb) => cb(null, req.randomId.concat(getSafeExt(file.mimetype))),
@ -31,10 +31,10 @@ const uploadLocal = multer({
storage: multer.diskStorage({
destination: !saveWithDate ? diskFilePath : (_req, _file, cb) => {
// Get current month and year
let [month, _day, year] = new Date().toLocaleDateString("en-US").split("/");
let [month, , year] = new Date().toLocaleDateString('en-US').split('/');
// Add 0 before single digit months eg ( 6 turns into 06)
let folder = `${diskFilePath}/${year}-${("0" + month).slice(-2)}`;
// Add 0 before single digit months (6 turns into 06)
let folder = `${diskFilePath}/${year}-${`0${month}`.slice(-2)}`;
// Create folder if it doesn't exist
fs.ensureDirSync(folder);

@ -10,7 +10,7 @@ const THUMBNAIL_SIZE = 512;
function getCommand(src, dest) {
return shell([
ffmpeg, '-y', '-v', process.env.NODE_ENV == 'production' ? 'error' : 'debug',
ffmpeg, '-y', '-v', process.env.NODE_ENV === 'production' ? 'error' : 'debug',
'-i', src,
'-ss', '00:00:01.000',
'-frames:v', '1',

@ -24,20 +24,20 @@ 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, users) => req.headers.authorization && users.hasOwnProperty(req.headers.authorization),
verify: (req, users) => req.headers.authorization && Object.prototype.hasOwnProperty.call(users, req.headers.authorization),
generateToken: () => token(),
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));
return parseFloat((bytes / Math.pow(1024, i)).toFixed(decimals < 0 ? 0 : decimals)) + ' ' + sizes[i];
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";
let colour = '#';
for (var i = 0; i < 6; i++)
colour += letters[(Math.floor(Math.random() * 16))];
for (let i = 0; i < 6; i++)
colour += letters[(Math.floor(Math.random() * letters.length))];
return colour;
},
arrayEquals: (arr1, arr2) => arr1.length === arr2.length && arr1.slice().sort().every((value, index) => value === arr2.slice().sort()[index]),

Loading…
Cancel
Save