mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-23 10:53:01 +00:00
Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
This commit is contained in:
1 parent
0c815fde91
commit
084dc0be08
157 files changed
+737
-666
No files matched your search
+1
-1
@@ -24,7 +24,7 @@ import guildProfilesRoute from "./routes/guild-profiles";
|
||||
import iconsRoute from "./routes/role-icons";
|
||||
import bodyParser from "body-parser";
|
||||
|
||||
export interface CDNServerOptions extends ServerOptions {}
|
||||
export type CDNServerOptions = ServerOptions;
|
||||
|
||||
export class CDNServer extends Server {
|
||||
public declare options: CDNServerOptions;
|
||||
|
||||
@@ -41,7 +41,7 @@ router.post(
|
||||
throw new HTTPError("Invalid request signature");
|
||||
if (!req.file) throw new HTTPError("file missing");
|
||||
|
||||
const { buffer, mimetype, size, originalname, fieldname } = req.file;
|
||||
const { buffer, mimetype, size, originalname } = req.file;
|
||||
const { channel_id } = req.params;
|
||||
const filename = originalname
|
||||
.replaceAll(" ", "_")
|
||||
@@ -53,8 +53,8 @@ router.post(
|
||||
Config.get()?.cdn.endpointPublic || "http://localhost:3003";
|
||||
|
||||
await storage.set(path, buffer);
|
||||
var width;
|
||||
var height;
|
||||
let width;
|
||||
let height;
|
||||
if (mimetype.includes("image")) {
|
||||
const dimensions = imageSize(buffer);
|
||||
if (dimensions) {
|
||||
@@ -81,10 +81,10 @@ router.get(
|
||||
"/:channel_id/:id/:filename",
|
||||
async (req: Request, res: Response) => {
|
||||
const { channel_id, id, filename } = req.params;
|
||||
const { format } = req.query;
|
||||
// const { format } = req.query;
|
||||
|
||||
const path = `attachments/${channel_id}/${id}/${filename}`;
|
||||
let file = await storage.get(path);
|
||||
const file = await storage.get(path);
|
||||
if (!file) throw new HTTPError("File not found");
|
||||
const type = await FileType.fromBuffer(file);
|
||||
let content_type = type?.mime || "application/octet-stream";
|
||||
|
||||
@@ -48,10 +48,10 @@ router.post(
|
||||
if (req.headers.signature !== Config.get().security.requestSignature)
|
||||
throw new HTTPError("Invalid request signature");
|
||||
if (!req.file) throw new HTTPError("Missing file");
|
||||
const { buffer, mimetype, size, originalname, fieldname } = req.file;
|
||||
const { buffer, size } = req.file;
|
||||
const { user_id } = req.params;
|
||||
|
||||
var hash = crypto
|
||||
let hash = crypto
|
||||
.createHash("md5")
|
||||
.update(Snowflake.generate())
|
||||
.digest("hex");
|
||||
@@ -77,7 +77,7 @@ router.post(
|
||||
);
|
||||
|
||||
router.get("/:user_id", async (req: Request, res: Response) => {
|
||||
var { user_id } = req.params;
|
||||
let { user_id } = req.params;
|
||||
user_id = user_id.split(".")[0]; // remove .file extension
|
||||
const path = `avatars/${user_id}`;
|
||||
|
||||
@@ -92,7 +92,8 @@ router.get("/:user_id", async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
export const getAvatar = async (req: Request, res: Response) => {
|
||||
var { user_id, hash } = req.params;
|
||||
const { user_id } = req.params;
|
||||
let { hash } = req.params;
|
||||
hash = hash.split(".")[0]; // remove .file extension
|
||||
const path = `avatars/${user_id}/${hash}`;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => {
|
||||
if (req.headers.signature !== Config.get().security.requestSignature)
|
||||
throw new HTTPError("Invalid request signature");
|
||||
if (!req.file) throw new HTTPError("Missing file");
|
||||
const { buffer, mimetype, size, originalname, fieldname } = req.file;
|
||||
const { buffer, size } = req.file;
|
||||
const { guild_id, user_id } = req.params;
|
||||
|
||||
let hash = crypto
|
||||
@@ -72,7 +72,8 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
router.get("/", async (req: Request, res: Response) => {
|
||||
let { guild_id, user_id } = req.params;
|
||||
const { guild_id } = req.params;
|
||||
let { user_id } = req.params;
|
||||
user_id = user_id.split(".")[0]; // remove .file extension
|
||||
const path = `guilds/${guild_id}/users/${user_id}/avatars`;
|
||||
|
||||
@@ -87,7 +88,8 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
router.get("/:hash", async (req: Request, res: Response) => {
|
||||
let { guild_id, user_id, hash } = req.params;
|
||||
const { guild_id, user_id } = req.params;
|
||||
let { hash } = req.params;
|
||||
hash = hash.split(".")[0]; // remove .file extension
|
||||
const path = `guilds/${guild_id}/users/${user_id}/avatars/${hash}`;
|
||||
|
||||
|
||||
@@ -48,10 +48,10 @@ router.post(
|
||||
if (req.headers.signature !== Config.get().security.requestSignature)
|
||||
throw new HTTPError("Invalid request signature");
|
||||
if (!req.file) throw new HTTPError("Missing file");
|
||||
const { buffer, mimetype, size, originalname, fieldname } = req.file;
|
||||
const { buffer, size } = req.file;
|
||||
const { role_id } = req.params;
|
||||
|
||||
var hash = crypto
|
||||
const hash = crypto
|
||||
.createHash("md5")
|
||||
.update(Snowflake.generate())
|
||||
.digest("hex");
|
||||
@@ -76,7 +76,7 @@ router.post(
|
||||
);
|
||||
|
||||
router.get("/:role_id", async (req: Request, res: Response) => {
|
||||
var { role_id } = req.params;
|
||||
const { role_id } = req.params;
|
||||
//role_id = role_id.split(".")[0]; // remove .file extension
|
||||
const path = `role-icons/${role_id}`;
|
||||
|
||||
@@ -91,7 +91,7 @@ router.get("/:role_id", async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
router.get("/:role_id/:hash", async (req: Request, res: Response) => {
|
||||
var { role_id, hash } = req.params;
|
||||
const { role_id, hash } = req.params;
|
||||
//hash = hash.split(".")[0]; // remove .file extension
|
||||
const path = `role-icons/${role_id}/${hash}`;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import ExifTransformer from "exif-be-gone";
|
||||
function getPath(path: string) {
|
||||
// STORAGE_LOCATION has a default value in start.ts
|
||||
const root = process.env.STORAGE_LOCATION || "../";
|
||||
var filename = join(root, path);
|
||||
const filename = join(root, path);
|
||||
|
||||
if (path.indexOf("\0") !== -1 || !filename.startsWith(root))
|
||||
throw new Error("invalid path");
|
||||
@@ -51,15 +51,15 @@ export class FileStorage implements Storage {
|
||||
}
|
||||
}
|
||||
|
||||
async set(path: string, value: any) {
|
||||
async set(path: string, value: Buffer) {
|
||||
path = getPath(path);
|
||||
if (!fs.existsSync(dirname(path)))
|
||||
fs.mkdirSync(dirname(path), { recursive: true });
|
||||
|
||||
value = Readable.from(value);
|
||||
const ret = Readable.from(value);
|
||||
const cleaned_file = fs.createWriteStream(path);
|
||||
|
||||
return value.pipe(new ExifTransformer()).pipe(cleaned_file);
|
||||
ret.pipe(new ExifTransformer()).pipe(cleaned_file);
|
||||
}
|
||||
|
||||
async delete(path: string) {
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
import { FileStorage } from "./FileStorage";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { bgCyan, black } from "picocolors";
|
||||
import { S3 } from "@aws-sdk/client-s3";
|
||||
import { S3Storage } from "./S3Storage";
|
||||
process.cwd();
|
||||
|
||||
Reference in new issue
Block a user