Prettier
This commit is contained in:
+4
-4
@@ -5,7 +5,7 @@ import avatarsRoute from "./routes/avatars";
|
||||
import iconsRoute from "./routes/role-icons";
|
||||
import bodyParser from "body-parser";
|
||||
|
||||
export interface CDNServerOptions extends ServerOptions { }
|
||||
export interface CDNServerOptions extends ServerOptions {}
|
||||
|
||||
export class CDNServer extends Server {
|
||||
public declare options: CDNServerOptions;
|
||||
@@ -22,15 +22,15 @@ export class CDNServer extends Server {
|
||||
// TODO: use better CSP policy
|
||||
res.set(
|
||||
"Content-security-policy",
|
||||
"default-src * data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';"
|
||||
"default-src * data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';",
|
||||
);
|
||||
res.set(
|
||||
"Access-Control-Allow-Headers",
|
||||
req.header("Access-Control-Request-Headers") || "*"
|
||||
req.header("Access-Control-Request-Headers") || "*",
|
||||
);
|
||||
res.set(
|
||||
"Access-Control-Allow-Methods",
|
||||
req.header("Access-Control-Request-Methods") || "*"
|
||||
req.header("Access-Control-Request-Methods") || "*",
|
||||
);
|
||||
next();
|
||||
});
|
||||
|
||||
@@ -56,7 +56,7 @@ router.post(
|
||||
};
|
||||
|
||||
return res.json(file);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
router.get(
|
||||
@@ -65,7 +65,7 @@ router.get(
|
||||
const { channel_id, id, filename } = req.params;
|
||||
|
||||
const file = await storage.get(
|
||||
`attachments/${channel_id}/${id}/${filename}`
|
||||
`attachments/${channel_id}/${id}/${filename}`,
|
||||
);
|
||||
if (!file) throw new HTTPError("File not found");
|
||||
const type = await FileType.fromBuffer(file);
|
||||
@@ -79,7 +79,7 @@ router.get(
|
||||
res.set("Cache-Control", "public, max-age=31536000");
|
||||
|
||||
return res.send(file);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
router.delete(
|
||||
@@ -94,7 +94,7 @@ router.delete(
|
||||
await storage.delete(path);
|
||||
|
||||
return res.send({ success: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -55,7 +55,7 @@ router.post(
|
||||
size,
|
||||
url: `${endpoint}${req.baseUrl}/${user_id}/${hash}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
router.get("/:user_id", async (req: Request, res: Response) => {
|
||||
@@ -86,7 +86,7 @@ export const getAvatar = async (req: Request, res: Response) => {
|
||||
res.set("Cache-Control", "public, max-age=31536000");
|
||||
|
||||
return res.send(file);
|
||||
}
|
||||
};
|
||||
|
||||
router.get("/:user_id/:hash", getAvatar);
|
||||
|
||||
|
||||
@@ -66,14 +66,14 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
|
||||
const { resizeHeightMax, resizeWidthMax } = Config.get().cdn;
|
||||
const w = Math.min(parseInt(width as string), resizeWidthMax ?? 100);
|
||||
const h = Math.min(parseInt(height as string), resizeHeightMax ?? 100);
|
||||
if (w < 1 || h < 1) throw new HTTPError("Width and height must be greater than 0");
|
||||
if (w < 1 || h < 1)
|
||||
throw new HTTPError("Width and height must be greater than 0");
|
||||
|
||||
let buffer, response;
|
||||
try {
|
||||
response = await fetch(url, DEFAULT_FETCH_OPTIONS);
|
||||
buffer = await response.buffer();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
throw new HTTPError("Couldn't fetch website");
|
||||
}
|
||||
|
||||
@@ -84,7 +84,10 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
|
||||
.toBuffer();
|
||||
|
||||
res.setHeader("Content-Disposition", "attachment");
|
||||
res.setHeader("Content-Type", response.headers.get("content-type") ?? "image/png");
|
||||
res.setHeader(
|
||||
"Content-Type",
|
||||
response.headers.get("content-type") ?? "image/png",
|
||||
);
|
||||
return res.end(resizedBuffer);
|
||||
});
|
||||
|
||||
|
||||
@@ -7,4 +7,4 @@ const router = Router();
|
||||
router.get("/:guild_id/users/:user_id/avatars/:hash", getAvatar);
|
||||
router.get("/:guild_id/users/:user_id/banners/:hash", getAvatar);
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
||||
@@ -54,7 +54,7 @@ router.post(
|
||||
size,
|
||||
url: `${endpoint}${req.baseUrl}/${role_id}/${hash}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
router.get("/:role_id", async (req: Request, res: Response) => {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
require('module-alias/register')
|
||||
require("module-alias/register");
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export class S3Storage implements Storage {
|
||||
public constructor(
|
||||
private client: S3,
|
||||
private bucket: string,
|
||||
private basePath?: string
|
||||
private basePath?: string,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,14 +33,14 @@ if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
|
||||
|
||||
if (!region) {
|
||||
console.error(
|
||||
`[CDN] You must provide a region when using the S3 storage provider.`
|
||||
`[CDN] You must provide a region when using the S3 storage provider.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!bucket) {
|
||||
console.error(
|
||||
`[CDN] You must provide a bucket when using the S3 storage provider.`
|
||||
`[CDN] You must provide a bucket when using the S3 storage provider.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
|
||||
|
||||
if (!location) {
|
||||
console.warn(
|
||||
`[CDN] STORAGE_LOCATION unconfigured for S3 provider, defaulting to the bucket root...`
|
||||
`[CDN] STORAGE_LOCATION unconfigured for S3 provider, defaulting to the bucket root...`,
|
||||
);
|
||||
location = undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user