From fae0d0b69be30c207d46117fa038f6a65814fc5e Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sat, 14 Oct 2023 12:33:13 -0600 Subject: [PATCH] refactor: added missing explicit semicolons --- backend/UserConfig.ts | 7 ++----- backend/app.ts | 13 ++++++------- backend/data.ts | 2 +- backend/operations.ts | 33 +++++++++++++++------------------ backend/routers/api.ts | 6 +++--- backend/s3.ts | 2 +- backend/sql/mysql.ts | 2 +- backend/utils.ts | 5 ++--- 8 files changed, 31 insertions(+), 39 deletions(-) diff --git a/backend/UserConfig.ts b/backend/UserConfig.ts index 77bca22..1dddbbc 100644 --- a/backend/UserConfig.ts +++ b/backend/UserConfig.ts @@ -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; diff --git a/backend/app.ts b/backend/app.ts index d1d2a2d..b6c56ae 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -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); diff --git a/backend/data.ts b/backend/data.ts index b62a391..65321ab 100644 --- a/backend/data.ts +++ b/backend/data.ts @@ -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 } diff --git a/backend/operations.ts b/backend/operations.ts index 3855c94..009e89e 100644 --- a/backend/operations.ts +++ b/backend/operations.ts @@ -13,21 +13,19 @@ type SrcDest = { src: string, dest: string }; /** * Strips GPS EXIF data from a file */ -export const removeGPS = (file: string): Promise => { - return new Promise((resolve, reject) => - fs.open(file, 'r+') - .then((fd) => removeLocation(file, - // Read function - (size: number, offset: number): Promise => - fs.read(fd, Buffer.alloc(size), 0, size, offset) - .then(({ buffer }) => Promise.resolve(buffer)), - // Write function - (val: string, offset: number, enc: BufferEncoding): Promise => - 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 => new Promise((resolve, reject) => + fs.open(file, 'r+') + .then((fd) => removeLocation(file, + // Read function + (size: number, offset: number): Promise => + fs.read(fd, Buffer.alloc(size), 0, size, offset) + .then(({ buffer }) => Promise.resolve(buffer)), + // Write function + (val: string, offset: number, enc: BufferEncoding): Promise => + 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 => new Promise((resolve, reject) => @@ -39,8 +37,7 @@ export const vibrant = (file: string, mimetype: string): Promise => 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) { diff --git a/backend/routers/api.ts b/backend/routers/api.ts index a91da49..753e8c9 100644 --- a/backend/routers/api.ts +++ b/backend/routers/api.ts @@ -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 }); diff --git a/backend/s3.ts b/backend/s3.ts index 97b1866..2c6a8e2 100644 --- a/backend/s3.ts +++ b/backend/s3.ts @@ -48,7 +48,7 @@ const s3 = (): S3Client | null => { } return _s3client; -} +}; /** * Basic single file upload diff --git a/backend/sql/mysql.ts b/backend/sql/mysql.ts index d4e5122..544e7b5 100644 --- a/backend/sql/mysql.ts +++ b/backend/sql/mysql.ts @@ -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!'); } diff --git a/backend/utils.ts b/backend/utils.ts index 60a23b0..64df481 100644 --- a/backend/utils.ts +++ b/backend/utils.ts @@ -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]}`); -} +};