✨ icons + banners route
This commit is contained in:
parent
a6eac74236
commit
ede8ed4b71
1955
package-lock.json
generated
1955
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -29,6 +29,7 @@
|
|||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-async-errors": "^3.1.1",
|
"express-async-errors": "^3.1.1",
|
||||||
"file-type": "^16.5.0",
|
"file-type": "^16.5.0",
|
||||||
|
"fs-extra": "^10.0.0",
|
||||||
"image-size": "^1.0.0",
|
"image-size": "^1.0.0",
|
||||||
"lambert-db": "^1.2.3",
|
"lambert-db": "^1.2.3",
|
||||||
"lambert-server": "^1.2.8",
|
"lambert-server": "^1.2.8",
|
||||||
@ -42,6 +43,7 @@
|
|||||||
"@types/btoa": "^1.2.3",
|
"@types/btoa": "^1.2.3",
|
||||||
"@types/dotenv": "^8.2.0",
|
"@types/dotenv": "^8.2.0",
|
||||||
"@types/express": "^4.17.12",
|
"@types/express": "^4.17.12",
|
||||||
|
"@types/fs-extra": "^9.0.12",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.7",
|
||||||
"@types/node": "^14.17.0",
|
"@types/node": "^14.17.0",
|
||||||
"@types/node-fetch": "^2.5.7",
|
"@types/node-fetch": "^2.5.7",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Server, ServerOptions } from "lambert-server";
|
import { Server, ServerOptions } from "lambert-server";
|
||||||
import { Config, db } from "@fosscord/server-util";
|
import { Config, db } from "@fosscord/server-util";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import multerConfig from "multer";
|
import avatarsRoute from "./routes/avatars";
|
||||||
|
|
||||||
export interface CDNServerOptions extends ServerOptions {}
|
export interface CDNServerOptions extends ServerOptions {}
|
||||||
|
|
||||||
@ -20,6 +20,10 @@ export class CDNServer extends Server {
|
|||||||
console.log("[Database] connected");
|
console.log("[Database] connected");
|
||||||
|
|
||||||
await this.registerRoutes(path.join(__dirname, "routes/"));
|
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();
|
return super.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,12 +31,3 @@ export class CDNServer extends Server {
|
|||||||
return super.stop();
|
return super.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const multer = multerConfig({
|
|
||||||
storage: multerConfig.memoryStorage(),
|
|
||||||
limits: {
|
|
||||||
fields: 10,
|
|
||||||
files: 10,
|
|
||||||
fileSize: 1024 * 1024 * 100, // 100 mb
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
@ -3,7 +3,7 @@ import { Config, Snowflake } from "@fosscord/server-util";
|
|||||||
import { storage } from "../util/Storage";
|
import { storage } from "../util/Storage";
|
||||||
import FileType from "file-type";
|
import FileType from "file-type";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { multer } from "../Server";
|
import { multer } from "../util/multer";
|
||||||
import imageSize from "image-size";
|
import imageSize from "image-size";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
@ -3,7 +3,7 @@ import { Config, Snowflake } from "@fosscord/server-util";
|
|||||||
import { storage } from "../util/Storage";
|
import { storage } from "../util/Storage";
|
||||||
import FileType from "file-type";
|
import FileType from "file-type";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { multer } from "../Server";
|
import { multer } from "../util/multer";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|
||||||
// TODO: check premium and animated pfp are allowed in the config
|
// 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
|
// TODO: check request signature for modify methods
|
||||||
|
|
||||||
const ANIMATED_MIME_TYPES = ["image/apng", "image/gif", "image/gifv"];
|
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 ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES];
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
@ -38,7 +38,7 @@ router.post("/:user_id", multer.single("file"), async (req: Request, res: Respon
|
|||||||
id,
|
id,
|
||||||
content_type: type.mime,
|
content_type: type.mime,
|
||||||
size,
|
size,
|
||||||
url: `${endpoint}/path`,
|
url: `${endpoint}${req.baseUrl}/${user_id}/${id}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
22
src/start.ts
22
src/start.ts
@ -1,17 +1,23 @@
|
|||||||
|
import path from "path";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
import fse from "fs-extra";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
import { CDNServer } from "./Server";
|
if (!process.env.STORAGE_PROVIDER) process.env.STORAGE_PROVIDER = "file";
|
||||||
|
// TODO:nodejs path.join trailing slash windows compatible
|
||||||
if (process.env.STORAGE_LOCATION) {
|
if (process.env.STORAGE_PROVIDER === "file") {
|
||||||
if (!process.env.STORAGE_LOCATION.startsWith("/")) {
|
if (process.env.STORAGE_LOCATION) {
|
||||||
process.env.STORAGE_LOCATION = __dirname + "/../" + 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 {
|
fse.ensureDirSync(process.env.STORAGE_LOCATION);
|
||||||
process.env.STORAGE_LOCATION = __dirname + "/../files/";
|
|
||||||
process.env.STORAGE_PROVIDER = "file";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import { CDNServer } from "./Server";
|
||||||
|
|
||||||
const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
|
const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
|
||||||
server
|
server
|
||||||
.start()
|
.start()
|
||||||
|
10
src/util/multer.ts
Normal file
10
src/util/multer.ts
Normal file
@ -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
|
||||||
|
},
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user