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

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

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

@ -31,10 +31,10 @@ const uploadLocal = multer({
storage: multer.diskStorage({ storage: multer.diskStorage({
destination: !saveWithDate ? diskFilePath : (_req, _file, cb) => { destination: !saveWithDate ? diskFilePath : (_req, _file, cb) => {
// Get current month and year // 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) // 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 // Create folder if it doesn't exist
fs.ensureDirSync(folder); fs.ensureDirSync(folder);
@ -50,7 +50,7 @@ const bucketSize = () =>
function listAllKeys(resolve, reject, token) { function listAllKeys(resolve, reject, token) {
let allKeys = []; let allKeys = [];
s3.listObjectsV2({ Bucket: s3bucket, ContinuationToken: token }).promise() 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); .catch(reject);
} }

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

Loading…
Cancel
Save