diff --git a/src/Server.ts b/src/Server.ts
index 57dfa536..9996f07a 100644
--- a/src/Server.ts
+++ b/src/Server.ts
@@ -1,7 +1,7 @@
import { Server, ServerOptions } from "lambert-server";
import { Config, db } from "@fosscord/server-util";
import path from "path";
-import multerConfig from "multer";
+import avatarsRoute from "./routes/avatars";
export interface CDNServerOptions extends ServerOptions {}
@@ -20,6 +20,10 @@ export class CDNServer extends Server {
console.log("[Database] connected");
await this.registerRoutes(path.join(__dirname, "routes/"));
+ this.app.use("/icons/", avatarsRoute);
+ this.log("info", "[Server] Route /icons registered");
+ this.app.use("/banners/", avatarsRoute);
+ this.log("info", "[Server] Route /banners registered");
return super.start();
}
@@ -27,12 +31,3 @@ export class CDNServer extends Server {
return super.stop();
}
}
-
-export const multer = multerConfig({
- storage: multerConfig.memoryStorage(),
- limits: {
- fields: 10,
- files: 10,
- fileSize: 1024 * 1024 * 100, // 100 mb
- },
-});
diff --git a/src/routes/attachments.ts b/src/routes/attachments.ts
index 9d43a921..9d208485 100644
--- a/src/routes/attachments.ts
+++ b/src/routes/attachments.ts
@@ -3,7 +3,7 @@ import { Config, Snowflake } from "@fosscord/server-util";
import { storage } from "../util/Storage";
import FileType from "file-type";
import { HTTPError } from "lambert-server";
-import { multer } from "../Server";
+import { multer } from "../util/multer";
import imageSize from "image-size";
const router = Router();
diff --git a/src/routes/avatars.ts b/src/routes/avatars.ts
index fea7c5f4..476daacd 100644
--- a/src/routes/avatars.ts
+++ b/src/routes/avatars.ts
@@ -3,7 +3,7 @@ import { Config, Snowflake } from "@fosscord/server-util";
import { storage } from "../util/Storage";
import FileType from "file-type";
import { HTTPError } from "lambert-server";
-import { multer } from "../Server";
+import { multer } from "../util/multer";
import crypto from "crypto";
// TODO: check premium and animated pfp are allowed in the config
@@ -13,7 +13,7 @@ import crypto from "crypto";
// TODO: check request signature for modify methods
const ANIMATED_MIME_TYPES = ["image/apng", "image/gif", "image/gifv"];
-const STATIC_MIME_TYPES = ["image/png", "image/jpeg", "image/webp"];
+const STATIC_MIME_TYPES = ["image/png", "image/jpeg", "image/webp", "image/svg+xml", "image/svg"];
const ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES];
const router = Router();
@@ -38,7 +38,7 @@ router.post("/:user_id", multer.single("file"), async (req: Request, res: Respon
id,
content_type: type.mime,
size,
- url: `${endpoint}/path`,
+ url: `${endpoint}${req.baseUrl}/${user_id}/${id}`,
});
});
diff --git a/src/start.ts b/src/start.ts
index 822a749f..57c9f704 100644
--- a/src/start.ts
+++ b/src/start.ts
@@ -1,17 +1,23 @@
+import path from "path";
import dotenv from "dotenv";
+import fse from "fs-extra";
dotenv.config();
-import { CDNServer } from "./Server";
-
-if (process.env.STORAGE_LOCATION) {
- if (!process.env.STORAGE_LOCATION.startsWith("/")) {
- process.env.STORAGE_LOCATION = __dirname + "/../" + process.env.STORAGE_LOCATION;
+if (!process.env.STORAGE_PROVIDER) process.env.STORAGE_PROVIDER = "file";
+// TODO:nodejs path.join trailing slash windows compatible
+if (process.env.STORAGE_PROVIDER === "file") {
+ if (process.env.STORAGE_LOCATION) {
+ if (!process.env.STORAGE_LOCATION.startsWith("/")) {
+ process.env.STORAGE_LOCATION = path.join(__dirname, "..", process.env.STORAGE_LOCATION, "/");
+ }
+ } else {
+ process.env.STORAGE_LOCATION = path.join(__dirname, "..", "files", "/");
}
-} else {
- process.env.STORAGE_LOCATION = __dirname + "/../files/";
- process.env.STORAGE_PROVIDER = "file";
+ fse.ensureDirSync(process.env.STORAGE_LOCATION);
}
+import { CDNServer } from "./Server";
+
const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
server
.start()
diff --git a/src/util/multer.ts b/src/util/multer.ts
new file mode 100644
index 00000000..bfdf6aff
--- /dev/null
+++ b/src/util/multer.ts
@@ -0,0 +1,10 @@
+import multerConfig from "multer";
+
+export const multer = multerConfig({
+ storage: multerConfig.memoryStorage(),
+ limits: {
+ fields: 10,
+ files: 10,
+ fileSize: 1024 * 1024 * 100, // 100 mb
+ },
+});
|