refactor: delete a lot of old stuff

pull/243/head
Josh Moore 1 year ago
parent d5bd01b814
commit c4b43ddf68

@ -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
}

@ -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));

@ -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;

@ -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);
}

@ -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;

Loading…
Cancel
Save