refactor: added missing explicit semicolons

pull/241/head
Josh Moore 1 year ago
parent a559866453
commit fae0d0b69b

@ -35,10 +35,7 @@ const Checkers: UserConfigTypeChecker = {
return false;
}
},
idType: (val) => {
const options = ['random', 'original', 'gfycat', 'timestamp', 'zws'];
return options.includes(val);
},
idType: (val) => ['random', 'original', 'gfycat', 'timestamp', 'zws'].includes(val),
idSize: numChecker,
gfySize: numChecker,
maximumFileSize: numChecker,
@ -61,7 +58,7 @@ const Checkers: UserConfigTypeChecker = {
database: basicStringChecker
}
}
}
};
export class UserConfig {
private static _config: UserConfiguration;

@ -14,17 +14,16 @@ import { MySql } from './sql/mysql';
*/
export const App = {
pkgVersion: ''
}
};
/**
* Custom middleware to attach the ass object (and construct the `host` property)
*/
function assMetaMiddleware(port: number, proxied: boolean): RequestHandler {
return (req: Request, _res: Response, next: NextFunction) => {
const assMetaMiddleware = (port: number, proxied: boolean): RequestHandler =>
(req: Request, _res: Response, next: NextFunction) => {
req.ass = { host: `${req.protocol}://${req.hostname}${proxied ? '' : `:${port}`}` };
next();
}
}
};
/**
* Main function.
@ -111,8 +110,8 @@ async function main() {
app.get('/.ass.host', (req, res) => res.send(req.ass.host));
// ! I did not want to do it like this how tf did I back myself into this shit
app.get('/admin', (req, res) => res.render('admin', { version: App.pkgVersion }))
app.get('/login', (req, res) => res.render('login', { version: App.pkgVersion }))
app.get('/admin', (req, res) => res.render('admin', { version: App.pkgVersion }));
app.get('/login', (req, res) => res.render('login', { version: App.pkgVersion }));
// Routing
app.use('/setup', (await import('./routers/setup.js')).router);

@ -133,7 +133,7 @@ export const put = (sector: DataSector, key: NID, data: AssFile | AssUser): Prom
// ? SQL
if (!(await MySql.get('assfiles', key))) await MySql.put('assfiles', key, data);
else return reject(new Error(`File key ${key} already exists`))
else return reject(new Error(`File key ${key} already exists`));
// todo: modify users SQL files property
}

@ -13,21 +13,19 @@ type SrcDest = { src: string, dest: string };
/**
* Strips GPS EXIF data from a file
*/
export const removeGPS = (file: string): Promise<boolean> => {
return new Promise((resolve, reject) =>
fs.open(file, 'r+')
.then((fd) => removeLocation(file,
// Read function
(size: number, offset: number): Promise<Buffer> =>
fs.read(fd, Buffer.alloc(size), 0, size, offset)
.then(({ buffer }) => Promise.resolve(buffer)),
// Write function
(val: string, offset: number, enc: BufferEncoding): Promise<void> =>
fs.write(fd, Buffer.alloc(val.length, val, enc), 0, val.length, offset)
.then(() => Promise.resolve())))
.then(resolve)
.catch(reject));
}
export const removeGPS = (file: string): Promise<boolean> => new Promise((resolve, reject) =>
fs.open(file, 'r+')
.then((fd) => removeLocation(file,
// Read function
(size: number, offset: number): Promise<Buffer> =>
fs.read(fd, Buffer.alloc(size), 0, size, offset)
.then(({ buffer }) => Promise.resolve(buffer)),
// Write function
(val: string, offset: number, enc: BufferEncoding): Promise<void> =>
fs.write(fd, Buffer.alloc(val.length, val, enc), 0, val.length, offset)
.then(() => Promise.resolve())))
.then(resolve)
.catch(reject));
const VIBRANT = { COLOURS: 256, QUALITY: 3 };
export const vibrant = (file: string, mimetype: string): Promise<string> => new Promise((resolve, reject) =>
@ -39,8 +37,7 @@ export const vibrant = (file: string, mimetype: string): Promise<string> => new
.quality(VIBRANT.QUALITY)
.getPalette())
.then((palettes) => resolve(palettes[Object.keys(palettes).sort((a, b) => palettes[b]!.population - palettes[a]!.population)[0]]!.hex))
.catch((err) => reject(err))
)
.catch((err) => reject(err)));
/**
* Thumbnail operations
@ -64,7 +61,7 @@ export class Thumbnail {
}
private static getVideoThumbnail({ src, dest }: SrcDest) {
exec(this.getCommand({ src, dest }))
exec(this.getCommand({ src, dest }));
}
private static getCommand({ src, dest }: SrcDest) {

@ -21,12 +21,12 @@ router.post('/user', BodyParserJson(), async (req, res) => {
try {
// Username check
if (!newUser.username) issue = 'Missing username'
if (!newUser.username) issue = 'Missing username';
newUser.username.replaceAll(/[^A-z0-9_-]/g, '');
if (newUser.username === '') issue = 'Invalid username';
// Password check
if (!newUser.password) issue = 'Missing password'
if (!newUser.password) issue = 'Missing password';
if (newUser.password === '') issue = 'Invalid password';
newUser.password = newUser.password.substring(0, 128);
@ -48,7 +48,7 @@ router.post('/user', BodyParserJson(), async (req, res) => {
// todo: also check duplicate usernames
await data.put('users', user.id, user);
} catch (err: any) { issue = `Error: ${err.message}` }
} catch (err: any) { issue = `Error: ${err.message}`; }
if (issue) return res.status(400).json({ success: false, messsage: issue });

@ -48,7 +48,7 @@ const s3 = (): S3Client | null => {
}
return _s3client;
}
};
/**
* Basic single file upload

@ -87,7 +87,7 @@ export class MySql {
if (tablesExist.files && tablesExist.users)
log.info('MySQL', 'Tables exist, ready').callback(() => {
MySql._ready = true;
resolve(void 0)
resolve(void 0);
});
else throw new Error('Table(s) missing!');
}

@ -6,15 +6,14 @@ export const randomHexColour = () => { // From: https://www.geeksforgeeks.org/ja
for (let i = 0; i < 6; i++)
colour += letters[(Math.floor(Math.random() * letters.length))];
return colour;
}
};
export const formatTimestamp = (timestamp: number, timeoffset: string) =>
DateTime.fromMillis(timestamp).setZone(timeoffset).toLocaleString(DateTime.DATETIME_MED);
export const formatBytes = (bytes: number, decimals = 2) => {
if (bytes === 0) return '0 Bytes';
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]}`);
}
};

Loading…
Cancel
Save