Merge pull request #250 from WilliamDavidHarrison/dev/0.15.0

pull/220/head
Sylvie 5 months ago committed by GitHub
commit f0dd773c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@ import { UserConfiguration, UserConfigTypeChecker, PostgresConfiguration } from
import fs from 'fs-extra';
import { path } from '@tycrek/joint';
import { log } from './log.js';
import { validate } from 'william.js';
const FILEPATH = path.join('.ass-data/userconfig.json');
@ -40,6 +41,7 @@ const Checkers: UserConfigTypeChecker = {
idSize: numChecker,
gfySize: numChecker,
maximumFileSize: numChecker,
discordWebhook: (val) => validate.discord.webhook(val),
s3: {
endpoint: basicStringChecker,
@ -96,6 +98,7 @@ export class UserConfig {
if (!Checkers.idSize(config.idSize)) throw new Error('Invalid ID size');
if (!Checkers.gfySize(config.gfySize)) throw new Error('Invalid Gfy size');
if (!Checkers.maximumFileSize(config.maximumFileSize)) throw new Error('Invalid maximum file size');
if (!Checkers.discordWebhook(config.discordWebhook)) throw new Error('Invalid Discord webhook');
// * Optional S3 config
if (config.s3 != null) {
@ -118,7 +121,7 @@ export class UserConfig {
if (!Checkers.sql.mySql.port(config.database.options.port)) throw new Error('Invalid database port');
if (config.database.kind == 'postgres') {
if (!Checkers.sql.postgres.port((config.database.options as PostgresConfiguration).port)) {
throw new Error("Invalid database port");
throw new Error('Invalid database port');
}
}
} else throw new Error('Database options missing');

@ -1,5 +1,6 @@
import { BusBoyFile, AssFile } from 'ass';
import axios from 'axios';
import fs from 'fs-extra';
import bb from 'express-busboy';
import crypto from 'crypto';
@ -88,7 +89,19 @@ router.post('/', rateLimiterMiddleware("upload", UserConfig.config?.rateLimit?.u
data.put('files', assFile.fakeid, assFile);
log.debug('File saved to', !s3 ? assFile.save.local! : 'S3');
return res.type('json').send({ resource: `${req.ass.host}/${assFile.fakeid}` });
await res.type('json').send({ resource: `${req.ass.host}/${assFile.fakeid}` });
// Send to Discord webhook
try {
await axios.post(UserConfig.config.discordWebhook, {
body: JSON.stringify({
content: `New upload: ${req.ass.host}/${assFile.fakeid}`
})
})
} catch (err) {
log.warn('Failed to send request to Discord webhook');
console.error(err);
}
} catch (err) {
log.error('Failed to upload file', bbFile.filename);
console.error(err);

@ -1,4 +1,7 @@
import { DateTime } from 'luxon';
import { id } from 'william.js';
export const customId = (length: number, alphabet: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') => id(length, 1, alphabet);
export const randomHexColour = () => { // From: https://www.geeksforgeeks.org/javascript-generate-random-hex-codes-color/
const letters = '0123456789ABCDEF';

2
common/types.d.ts vendored

@ -25,6 +25,7 @@ declare module 'ass' {
idSize: number;
gfySize: number;
maximumFileSize: number;
discordWebhook: string;
s3?: S3Configuration;
database?: DatabaseConfiguration;
@ -154,6 +155,7 @@ declare module 'ass' {
idSize: (val: any) => boolean;
gfySize: (val: any) => boolean;
maximumFileSize: (val: any) => boolean;
discordWebhook: (val: any) => boolean;
s3: {
endpoint: (val: any) => boolean;
bucket: (val: any) => boolean;

16876
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -42,6 +42,7 @@
"@xoi/gps-metadata-remover": "^1.1.2",
"any-shell-escape": "^0.1.1",
"autoprefixer": "^10.4.16",
"axios": "^1.6.2",
"bcrypt": "^5.1.1",
"crypto-random-string": "3.3.1",
"cssnano": "^6.0.1",
@ -61,7 +62,8 @@
"shoelace-fontawesome-pug": "^6.4.3",
"shoelace-pug-loader": "^2.11.0",
"tailwindcss": "^3.3.6",
"typescript": "^5.3.2"
"typescript": "^5.3.2",
"william.js": "^1.3.1"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",

Loading…
Cancel
Save