From fb7199f27a54879f45c12e888bef3fbb3bb76410 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 12 Jun 2026 16:49:37 +0200 Subject: [PATCH] CDN: unify imports layout --- src/cdn/Server.ts | 2 +- src/cdn/routes/app-assets.ts | 8 +++----- src/cdn/routes/app-icons.ts | 8 +++----- src/cdn/routes/attachments.ts | 4 +--- src/cdn/routes/avatar-decoration-presets.ts | 3 +-- src/cdn/routes/avatars.ts | 4 +--- src/cdn/routes/badge-icons.ts | 3 +-- src/cdn/routes/banners.ts | 8 +++----- src/cdn/routes/channel-icons.ts | 8 +++----- src/cdn/routes/discover-splashes.ts | 8 +++----- src/cdn/routes/discovery-splashes.ts | 8 +++----- src/cdn/routes/embed.ts | 6 +++--- src/cdn/routes/emojis.ts | 8 +++----- src/cdn/routes/guild-profiles.ts | 8 +++----- src/cdn/routes/icons.ts | 8 +++----- src/cdn/routes/role-icons.ts | 8 +++----- src/cdn/routes/splashes.ts | 8 +++----- src/cdn/routes/stickers.ts | 8 +++----- src/cdn/routes/team-icons.ts | 8 +++----- src/cdn/util/FileStorage.ts | 2 +- src/cdn/util/Storage.ts | 2 +- src/cdn/util/index.ts | 2 +- 22 files changed, 50 insertions(+), 82 deletions(-) diff --git a/src/cdn/Server.ts b/src/cdn/Server.ts index cd0d8dee6..a6a4330e0 100644 --- a/src/cdn/Server.ts +++ b/src/cdn/Server.ts @@ -19,7 +19,7 @@ import path from "node:path"; import morgan from "morgan"; import { Server, ServerOptions } from "lambert-server/Server"; -import { CORS, BodyParser } from "@spacebar/api"; +import { CORS, BodyParser } from "@spacebar/api/middlewares"; import { Attachment, initDatabase } from "@spacebar/database"; import { Config, registerRoutes } from "@spacebar/util"; import { ProcessLifecycle } from "../util/util/ProcessLifecycle"; diff --git a/src/cdn/routes/app-assets.ts b/src/cdn/routes/app-assets.ts index fc20cb17e..f67051ac6 100644 --- a/src/cdn/routes/app-assets.ts +++ b/src/cdn/routes/app-assets.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/app-icons.ts b/src/cdn/routes/app-icons.ts index 4cff5754e..46599ad9c 100644 --- a/src/cdn/routes/app-icons.ts +++ b/src/cdn/routes/app-icons.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts index 01621be10..ef91b7d94 100644 --- a/src/cdn/routes/attachments.ts +++ b/src/cdn/routes/attachments.ts @@ -22,9 +22,7 @@ import imageSize from "image-size"; import { HTTPError } from "lambert-server/HTTPError"; import { CloudAttachment } from "@spacebar/database"; import { Config, hasValidSignature, NewUrlUserSignatureData, Snowflake, UrlSignResult } from "@spacebar/util"; -import { storage } from "@spacebar/cdn/util/Storage"; -import { multer } from "@spacebar/cdn/util/multer"; -import { cache } from "@spacebar/cdn/util/cache"; +import { storage, multer, cache } from "@spacebar/cdn/util"; const router = Router({ mergeParams: true }); diff --git a/src/cdn/routes/avatar-decoration-presets.ts b/src/cdn/routes/avatar-decoration-presets.ts index a2df4de4c..e52ae710d 100644 --- a/src/cdn/routes/avatar-decoration-presets.ts +++ b/src/cdn/routes/avatar-decoration-presets.ts @@ -17,10 +17,9 @@ */ import { Router, Response, Request } from "express"; -import { storage } from "@spacebar/cdn"; import { HTTPError } from "lambert-server/HTTPError"; import { fileTypeFromBuffer } from "file-type"; -import { cache } from "../util/cache"; +import { storage, cache } from "@spacebar/cdn/util"; const router = Router({ mergeParams: true }); diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts index 3a6991e0e..099e0ad9d 100644 --- a/src/cdn/routes/avatars.ts +++ b/src/cdn/routes/avatars.ts @@ -20,10 +20,8 @@ import crypto from "node:crypto"; import { Router, Response, Request } from "express"; import { fileTypeFromBuffer } from "file-type"; import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { HTTPError } from "lambert-server/HTTPError"; -import { multer } from "../util/multer"; -import { cache } from "../util/cache"; +import { storage, multer, cache } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/badge-icons.ts b/src/cdn/routes/badge-icons.ts index 4eaed5998..a2fc0ea01 100644 --- a/src/cdn/routes/badge-icons.ts +++ b/src/cdn/routes/badge-icons.ts @@ -17,10 +17,9 @@ */ import { Router, Response, Request } from "express"; -import { storage } from "@spacebar/cdn"; import { HTTPError } from "lambert-server/HTTPError"; import { fileTypeFromBuffer } from "file-type"; -import { cache } from "../util/cache"; +import { storage, cache } from "@spacebar/cdn/util"; const router = Router({ mergeParams: true }); diff --git a/src/cdn/routes/banners.ts b/src/cdn/routes/banners.ts index af0d194d8..6e3a6bf95 100644 --- a/src/cdn/routes/banners.ts +++ b/src/cdn/routes/banners.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/channel-icons.ts b/src/cdn/routes/channel-icons.ts index 3f345bbcd..91bfe1230 100644 --- a/src/cdn/routes/channel-icons.ts +++ b/src/cdn/routes/channel-icons.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/discover-splashes.ts b/src/cdn/routes/discover-splashes.ts index c3aa8444b..c43f35f0c 100644 --- a/src/cdn/routes/discover-splashes.ts +++ b/src/cdn/routes/discover-splashes.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/discovery-splashes.ts b/src/cdn/routes/discovery-splashes.ts index c5ab5b377..d1c3f0792 100644 --- a/src/cdn/routes/discovery-splashes.ts +++ b/src/cdn/routes/discovery-splashes.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/embed.ts b/src/cdn/routes/embed.ts index 0ca4908fc..965d6a94d 100644 --- a/src/cdn/routes/embed.ts +++ b/src/cdn/routes/embed.ts @@ -16,12 +16,12 @@ along with this program. If not, see . */ -import { Request, Response, Router } from "express"; import fs from "node:fs/promises"; -import { HTTPError } from "lambert-server/HTTPError"; import { join } from "node:path"; +import { Request, Response, Router } from "express"; import { fileTypeFromBuffer } from "file-type"; -import { cache } from "../util/cache"; +import { HTTPError } from "lambert-server/HTTPError"; +import { cache } from "@spacebar/cdn/util"; const defaultAvatarHashMap = new Map([ ["0", "4a8562cf00887030c416d3ec2d46385a"], diff --git a/src/cdn/routes/emojis.ts b/src/cdn/routes/emojis.ts index a0a14ac34..aaf6af9fc 100644 --- a/src/cdn/routes/emojis.ts +++ b/src/cdn/routes/emojis.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/guild-profiles.ts b/src/cdn/routes/guild-profiles.ts index a38ef4c95..fe87e9a4b 100644 --- a/src/cdn/routes/guild-profiles.ts +++ b/src/cdn/routes/guild-profiles.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ -import { Config } from "@spacebar/util"; import crypto from "node:crypto"; import { Request, Response, Router } from "express"; -import { HTTPError } from "lambert-server/HTTPError"; -import { multer } from "../util/multer"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; -import { cache } from "../util/cache"; +import { HTTPError } from "lambert-server/HTTPError"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/icons.ts b/src/cdn/routes/icons.ts index e2d4341f5..bacc046b4 100644 --- a/src/cdn/routes/icons.ts +++ b/src/cdn/routes/icons.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts index 55da7f02a..86037cd31 100644 --- a/src/cdn/routes/role-icons.ts +++ b/src/cdn/routes/role-icons.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache } from "@spacebar/cdn/util"; //Role icons ---> avatars.ts modified diff --git a/src/cdn/routes/splashes.ts b/src/cdn/routes/splashes.ts index 68f4cede6..21556167e 100644 --- a/src/cdn/routes/splashes.ts +++ b/src/cdn/routes/splashes.ts @@ -17,13 +17,11 @@ */ import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; +import crypto from "node:crypto"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/stickers.ts b/src/cdn/routes/stickers.ts index 536c617b8..dade992d9 100644 --- a/src/cdn/routes/stickers.ts +++ b/src/cdn/routes/stickers.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/routes/team-icons.ts b/src/cdn/routes/team-icons.ts index 99de19c67..e171dc750 100644 --- a/src/cdn/routes/team-icons.ts +++ b/src/cdn/routes/team-icons.ts @@ -16,14 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; -import { Config } from "@spacebar/util"; -import { storage } from "@spacebar/cdn"; import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server/HTTPError"; -import crypto from "node:crypto"; -import { multer } from "../util/multer"; -import { cache, cacheNotFound } from "../util/cache"; +import { Config } from "@spacebar/util"; +import { storage, multer, cache, cacheNotFound } from "@spacebar/cdn/util"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon diff --git a/src/cdn/util/FileStorage.ts b/src/cdn/util/FileStorage.ts index eaedbc905..068e2c738 100644 --- a/src/cdn/util/FileStorage.ts +++ b/src/cdn/util/FileStorage.ts @@ -16,11 +16,11 @@ along with this program. If not, see . */ -import { Storage } from "./Storage"; import fs from "node:fs"; import fsp from "node:fs/promises"; import { join, dirname } from "node:path"; import { Readable } from "node:stream"; +import { Storage } from "./Storage"; import ExifTransformer from "exif-be-gone"; export class FileStorage implements Storage { diff --git a/src/cdn/util/Storage.ts b/src/cdn/util/Storage.ts index 3245f6557..7fa768522 100644 --- a/src/cdn/util/Storage.ts +++ b/src/cdn/util/Storage.ts @@ -16,7 +16,6 @@ along with this program. If not, see . */ -import { FileStorage } from "./FileStorage"; import path from "node:path"; import fs from "node:fs"; import { red } from "picocolors"; @@ -46,6 +45,7 @@ if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) { if (!fs.existsSync(location)) fs.mkdirSync(location); process.env.STORAGE_LOCATION = location; + const { FileStorage } = require("./FileStorage"); storage = new FileStorage(); } else if (process.env.STORAGE_PROVIDER === "s3") { try { diff --git a/src/cdn/util/index.ts b/src/cdn/util/index.ts index ba249845c..7d4e2758b 100644 --- a/src/cdn/util/index.ts +++ b/src/cdn/util/index.ts @@ -16,6 +16,6 @@ along with this program. If not, see . */ -export * from "./FileStorage"; +export * from "./cache"; export * from "./multer"; export * from "./Storage";