From dbb024815e4e58331c5aecbf2e7fca0eb1c72361 Mon Sep 17 00:00:00 2001 From: tycrek Date: Mon, 14 Mar 2022 19:20:23 -0600 Subject: [PATCH] Fix type importing (simple diffs) --- src/ass.ts | 18 ++++++++++++------ src/hash.ts | 2 +- src/routers/resource.ts | 7 ++++--- src/routers/upload.ts | 7 ++++--- src/skynet.ts | 4 ++-- src/storage.ts | 9 +++++---- src/thumbnails.ts | 6 ++++-- src/utils.ts | 2 +- src/vibrant.ts | 2 +- 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/ass.ts b/src/ass.ts index ac7de40..6a99e85 100644 --- a/src/ass.ts +++ b/src/ass.ts @@ -1,5 +1,5 @@ -import { ErrWrap } from './definitions'; - +import { ErrWrap } from './types/definitions'; +import { Config, MagicNumbers, Package } from 'ass-json'; let doSetup = null; try { // Check if config.json exists @@ -25,15 +25,21 @@ import nofavicon from '@tycrek/express-nofavicon'; import epcss from '@tycrek/express-postcss'; import tailwindcss from 'tailwindcss'; import helmet from 'helmet'; + +import { path, log, getTrueHttp, getTrueDomain } from './utils'; +//#endregion +// Load the JSON +const { host, port, useSsl, isProxied, s3enabled, frontendName, indexFile, useSia }: Config = fs.readJsonSync(path('config.json')); +const { CODE_INTERNAL_SERVER_ERROR }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); +const { name, version, homepage }: Package = fs.readJsonSync(path('package.json')); + +//#region Local imports import uploadRouter from './routers/upload'; import resourceRouter from './routers/resource'; -import { path, log, getTrueHttp, getTrueDomain } from './utils'; -const { CODE_INTERNAL_SERVER_ERROR } = require('../MagicNumbers.json'); -const { name: ASS_NAME, version: ASS_VERSION, homepage } = require('../package.json'); //#endregion // Welcome :D -log.blank().info(`* ${ASS_NAME} v${ASS_VERSION} *`).blank(); +log.blank().info(`* ${name} v${version} *`).blank(); //#region Variables, module setup const app = express(); diff --git a/src/hash.ts b/src/hash.ts index f4cfb53..cf59c20 100644 --- a/src/hash.ts +++ b/src/hash.ts @@ -1,4 +1,4 @@ -import { FileData } from './definitions'; +import { FileData } from './types/definitions'; import fs from 'fs-extra'; import crypto from 'crypto'; import toArray from 'stream-to-array'; diff --git a/src/routers/resource.ts b/src/routers/resource.ts index c15f4f1..ea0ace3 100644 --- a/src/routers/resource.ts +++ b/src/routers/resource.ts @@ -1,4 +1,5 @@ -import { FileData, IsPossible } from '../definitions'; +import { FileData, IsPossible } from '../types/definitions'; +import { Config, MagicNumbers } from 'ass-json'; import fs from 'fs-extra'; import escape from 'escape-html'; @@ -6,9 +7,9 @@ import fetch, { Response as FetchResponse } from 'node-fetch'; import { Request, Response } from 'express'; import { deleteS3 } from '../storage'; import { SkynetDelete, SkynetDownload } from '../skynet'; -const { diskFilePath, s3enabled, viewDirect, useSia } = require('../../config.json'); import { path, log, getTrueHttp, getTrueDomain, formatBytes, formatTimestamp, getS3url, getDirectUrl, getResourceColor, replaceholder } from '../utils'; -const { CODE_UNAUTHORIZED, CODE_NOT_FOUND, } = require('../../MagicNumbers.json'); +const { diskFilePath, s3enabled, viewDirect, useSia }: Config = fs.readJsonSync(path('config.json')); +const { CODE_UNAUTHORIZED, CODE_NOT_FOUND, }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); import { data } from '../data'; import { users } from '../auth'; diff --git a/src/routers/upload.ts b/src/routers/upload.ts index 7256562..bfeb059 100644 --- a/src/routers/upload.ts +++ b/src/routers/upload.ts @@ -1,4 +1,5 @@ -import { ErrWrap, User } from "../definitions"; +import { ErrWrap, User } from '../types/definitions'; +import { Config, MagicNumbers } from 'ass-json'; import fs from 'fs-extra'; import bb from 'express-busboy'; @@ -6,11 +7,11 @@ import bb from 'express-busboy'; import { DateTime } from 'luxon'; import { Webhook, MessageBuilder } from 'discord-webhook-node'; import { processUploaded } from '../storage'; -const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType, spaceReplace } = require('../../config.json'); import { path, log, verify, getTrueHttp, getTrueDomain, generateId, formatBytes } from '../utils'; -const { CODE_UNAUTHORIZED, CODE_PAYLOAD_TOO_LARGE } = require('../../MagicNumbers.json'); import { data } from '../data'; import { users } from '../auth'; +const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType, spaceReplace }: Config = fs.readJsonSync(path('config.json')); +const { CODE_UNAUTHORIZED, CODE_PAYLOAD_TOO_LARGE }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); const ASS_LOGO = 'https://cdn.discordapp.com/icons/848274994375294986/8d339d4a2f3f54b2295e5e0ff62bd9e6.png?size=1024'; import express, { Request, Response } from 'express'; diff --git a/src/skynet.ts b/src/skynet.ts index e5e8bd5..b6f1cb2 100644 --- a/src/skynet.ts +++ b/src/skynet.ts @@ -1,7 +1,7 @@ -import { FileData } from "./definitions"; +import { FileData } from './types/definitions'; import fs, { ReadStream } from 'fs-extra'; import { path } from './utils'; -const { SkynetClient } = require('@skynetlabs/skynet-nodejs'); +import { SkynetClient } from '@skynetlabs/skynet-nodejs'; function getFullPath(fileData: FileData) { return path('share', '.skynet', `${fileData.randomId}${fileData.ext}`.replace(/sia\:\/\//gi, '')); diff --git a/src/storage.ts b/src/storage.ts index d31669b..7545f99 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -1,17 +1,18 @@ // https://docs.digitalocean.com/products/spaces/resources/s3-sdk-examples/ // https://www.digitalocean.com/community/tutorials/how-to-upload-a-file-to-object-storage-with-node-js -import { FileData } from './definitions'; +import { FileData } from './types/definitions'; +import { Config, MagicNumbers } from 'ass-json' import fs, { Stats } from 'fs-extra'; import aws from 'aws-sdk'; import Thumbnail from './thumbnails'; import Vibrant from './vibrant'; import Hash from './hash'; -import { generateId, log } from './utils'; +import { path, generateId, log } from './utils'; import { SkynetUpload } from './skynet'; import { Request, Response } from 'express'; -const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, diskFilePath, saveAsOriginal, saveWithDate, mediaStrict, maxUploadSize, useSia } = require('../config.json'); -const { CODE_UNSUPPORTED_MEDIA_TYPE } = require('../MagicNumbers.json'); +const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, diskFilePath, saveAsOriginal, saveWithDate, mediaStrict, maxUploadSize, useSia }: Config = fs.readJsonSync(path('config.json')); +const { CODE_UNSUPPORTED_MEDIA_TYPE }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); const ID_GEN_LENGTH = 32; const ALLOWED_MIMETYPES = /(image)|(video)|(audio)\//; diff --git a/src/thumbnails.ts b/src/thumbnails.ts index 752258b..3eeaccf 100644 --- a/src/thumbnails.ts +++ b/src/thumbnails.ts @@ -1,11 +1,13 @@ -import { FileData } from "./definitions"; +import { FileData } from './types/definitions'; +import { Config } from 'ass-json'; +import fs from 'fs-extra'; import ffmpeg from 'ffmpeg-static'; import Jimp from 'jimp'; // @ts-ignore import shell from 'any-shell-escape'; import { exec } from 'child_process'; import { isProd, path } from './utils'; -const { diskFilePath } = require('../config.json'); +const { diskFilePath }: Config = fs.readJsonSync(path('config.json')); // Thumbnail parameters const THUMBNAIL = { diff --git a/src/utils.ts b/src/utils.ts index 3b90710..d7a78b6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { FileData } from './definitions'; +import { FileData } from './types/definitions'; import fs from 'fs-extra'; import Path from 'path'; import fetch from 'node-fetch'; diff --git a/src/vibrant.ts b/src/vibrant.ts index b81510c..f6bdbf0 100644 --- a/src/vibrant.ts +++ b/src/vibrant.ts @@ -1,4 +1,4 @@ -import { FileData } from './definitions'; +import { FileData } from './types/definitions'; import Vibrant from 'node-vibrant'; import { randomHexColour } from './utils';