From c4b43ddf68cce8393557c09529c73faf1841012f Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 28 Sep 2023 09:28:17 -0600 Subject: [PATCH] refactor: delete a lot of old stuff --- MagicNumbers.json | 14 -------------- src/checkEngine.js | 22 --------------------- src/logger.ts | 10 ---------- src/purge.ts | 16 ---------------- src/utils.ts | 48 ---------------------------------------------- 5 files changed, 110 deletions(-) delete mode 100644 MagicNumbers.json delete mode 100644 src/checkEngine.js delete mode 100644 src/logger.ts delete mode 100644 src/purge.ts diff --git a/MagicNumbers.json b/MagicNumbers.json deleted file mode 100644 index af2737c..0000000 --- a/MagicNumbers.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "HTTP": 80, - "HTTPS": 443, - "CODE_OK": 200, - "CODE_NO_CONTENT": 204, - "CODE_BAD_REQUEST": 400, - "CODE_UNAUTHORIZED": 401, - "CODE_NOT_FOUND": 404, - "CODE_CONFLICT": 409, - "CODE_PAYLOAD_TOO_LARGE": 413, - "CODE_UNSUPPORTED_MEDIA_TYPE": 415, - "CODE_INTERNAL_SERVER_ERROR": 500, - "KILOBYTES": 1024 -} \ No newline at end of file diff --git a/src/checkEngine.js b/src/checkEngine.js deleted file mode 100644 index e01c131..0000000 --- a/src/checkEngine.js +++ /dev/null @@ -1,22 +0,0 @@ -const check = require("check-node-version"); -const ENGINES = require('../package.json').engines; - -const { TLog } = require('@tycrek/log'); -const logger = new TLog(); - -function doCheck() { - return new Promise((resolve, reject) => - check(ENGINES, (err, { isSatisfied: allSatisfied, versions }) => - err ? reject(err) : allSatisfied ? resolve('Node & npm version requirements satisfied!') - : reject(Object.entries(versions) - .filter(([, { isSatisfied }]) => (!isSatisfied)) - .map(([packageName, { version: current, wanted: minimum }]) => - `\nInvalid ${packageName} version!\n- Current: ${current}\n- Required: ${minimum}`) - .join('') - .concat('\nPlease update to continue!')))); -} - -if (require.main !== module) module.exports = doCheck; -else doCheck() - .then((result) => logger.comment(`Wanted: ${ENGINES.node} (npm ${ENGINES.npm})`)/* .node() */.success(result)) - .catch((err) => logger.error(err) && process.exit(1)); diff --git a/src/logger.ts b/src/logger.ts deleted file mode 100644 index 7746b3e..0000000 --- a/src/logger.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { TLog } from '@tycrek/log'; -import { DateTime } from 'luxon'; - -// Set up logging -const logger = new TLog(process.env.NODE_ENV === 'production' ? 'info' : 'debug') - .setTimestamp({ preset: DateTime.DATETIME_MED }); - -// todo: re-enable the Express logger - -export default logger; diff --git a/src/purge.ts b/src/purge.ts deleted file mode 100644 index 41f2178..0000000 --- a/src/purge.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TLog } from '@tycrek/log'; -import fs from 'fs-extra'; -import path from 'path'; - -const log = new TLog(); -const uploadsPath = path.join(process.cwd(), 'uploads/'); -const dataPath = path.join(process.cwd(), 'data.json'); - -if (fs.existsSync(uploadsPath)) { - fs.removeSync(uploadsPath); - log.success('Deleted', uploadsPath); -} -if (fs.existsSync(dataPath)) { - fs.removeSync(dataPath); - log.success('Deleted', dataPath); -} diff --git a/src/utils.ts b/src/utils.ts index 8ef7a39..1593a0c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,3 @@ -import { Config } from 'ass-json'; import { FileData } from './types/definitions'; import fs from 'fs-extra'; import Path from 'path'; @@ -10,22 +9,10 @@ import zwsGen from './generators/zws'; import randomGen from './generators/random'; import gfyGen from './generators/gfycat'; import tsGen from './generators/timestamp'; -import logger from './logger'; import { Request } from 'express'; import { isProd as ip } from '@tycrek/joint'; const { HTTP, HTTPS, KILOBYTES } = require('../MagicNumbers.json'); -// Catch config.json not existing when running setup script -try { - // todo: fix this - const configPath = Path.join(process.cwd(), 'config.json'); - if (!fs.existsSync(configPath)) throw new Error('Config file not found'); - var { useSsl, port, domain, isProxied, diskFilePath, s3bucket, s3endpoint, s3usePathStyle }: Config = fs.readJsonSync(configPath); -} catch (ex) { - // @ts-ignore - if (ex.code !== 'MODULE_NOT_FOUND' || !ex.toString().includes('Unexpected end')) console.error(ex); -} - export function getTrueHttp() { return ('http').concat(useSsl ? 's' : '').concat('://'); } @@ -92,38 +79,3 @@ export function generateId(mode: string, length: number, gfyLength: number, orig export const path = (...paths: string[]) => Path.join(process.cwd(), ...paths); export const isProd = ip(); -module.exports = { - path, - getTrueHttp, - getTrueDomain, - getS3url, - getDirectUrl, - getResourceColor, - formatTimestamp, - formatBytes, - replaceholder, - randomHexColour, - sanitize, - renameFile: (req: Request, newName: string) => new Promise((resolve: Function, reject) => { - try { - const paths = [req.file.destination, newName]; - fs.rename(path(req.file.path), path(...paths)); - req.file.path = Path.join(...paths); - resolve(); - } catch (err) { - reject(err); - } - }), - generateToken: () => token(), - generateId, - downloadTempS3: (file: FileData) => new Promise((resolve: Function, reject) => - fetch(getS3url(file.randomId, file.ext)) - .then((f2) => f2.body!.pipe(fs.createWriteStream(Path.join(__dirname, diskFilePath, sanitize(file.originalname))).on('close', () => resolve()))) - .catch(reject)), -} - -export const log = logger; -/** - * @type {TLog} - */ -module.exports.log = logger;