mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-30 19:07:58 +03:00
Change the arrangement of CDN from /users/(banner|pfp)/userID to /users/userID/(banner|pfp).
This commit is contained in:
@@ -44,7 +44,6 @@ jobs:
|
||||
PORT: 8080
|
||||
MONGO_URL: "127.0.0.1"
|
||||
REDIS_URL: "127.0.0.1"
|
||||
CDN_FILE_ROOT: "./test-cdn"
|
||||
|
||||
- name: Lint Code
|
||||
run: pnpm lint
|
||||
|
||||
@@ -12,6 +12,10 @@ if (!options.dir) {
|
||||
throw new Error(`No dir provided, yet one is necessary.`);
|
||||
}
|
||||
|
||||
// @warn THIS SCRIPT IS OUTDATED!
|
||||
// Tachi now uses /users/${userID}/banner instead of
|
||||
// /users/banner/${userID}
|
||||
|
||||
fs.mkdirSync("users/banner", { recursive: true });
|
||||
fs.mkdirSync("users/pfp", { recursive: true });
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ const logger = CreateLogCtx(__filename);
|
||||
* @danger - This function should **NEVER** be called with unsanitised user input!
|
||||
* Path directory traversal *is* possible, and *will* ruin your day.
|
||||
*/
|
||||
function CDNFileSystemRoot(fileLoc: string) {
|
||||
export function CDNFileSystemRoot(fileLoc: string) {
|
||||
if (ServerConfig.CDN_CONFIG.SAVE_LOCATION.TYPE !== "LOCAL_FILESYSTEM") {
|
||||
logger.severe(
|
||||
`Attempted to run CDNFileSystemRoot, but was not using LOCAL_FILESYSTEM as a CDN.`,
|
||||
@@ -54,6 +54,8 @@ export function CDNRedirect(res: Response, fileLoc: string) {
|
||||
throw new Error(`Invalid fileLoc - did not start with /.`);
|
||||
}
|
||||
|
||||
logger.debug(`CDN Redirecting to ${ServerConfig.CDN_CONFIG.WEB_LOCATION}${fileLoc}.`);
|
||||
|
||||
return res.redirect(`${ServerConfig.CDN_CONFIG.WEB_LOCATION}${fileLoc}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ export function GetUSCIRReplayURL(scoreID: string) {
|
||||
}
|
||||
|
||||
export function GetProfilePictureURL(userID: integer) {
|
||||
return `/users/pfp/${userID}`;
|
||||
return `/users/${userID}/pfp`;
|
||||
}
|
||||
|
||||
export function GetProfileBannerURL(userID: integer) {
|
||||
return `/users/banner/${userID}`;
|
||||
return `/users/${userID}/banner`;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ export interface TachiServerConfig {
|
||||
CDN_CONFIG: {
|
||||
WEB_LOCATION: string;
|
||||
SAVE_LOCATION:
|
||||
| { TYPE: "LOCAL_FILESYSTEM"; LOCATION: string; RUN_OWN_CDN?: boolean }
|
||||
| { TYPE: "LOCAL_FILESYSTEM"; LOCATION: string; SERVE_OWN_CDN?: boolean }
|
||||
| {
|
||||
TYPE: "S3_BUCKET";
|
||||
ENDPOINT: string;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import t from "tap";
|
||||
import db from "external/mongo/db";
|
||||
import { CDNStoreOrOverwrite } from "lib/cdn/cdn";
|
||||
import { GetProfileBannerURL } from "lib/cdn/url-format";
|
||||
|
||||
import t from "tap";
|
||||
import mockApi from "test-utils/mock-api";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
import { GetKTDataBuffer } from "test-utils/test-data";
|
||||
@@ -14,6 +13,8 @@ t.test("GET /api/v1/users/:userID/banner", (t) => {
|
||||
await CDNStoreOrOverwrite("/users/default/banner", "test");
|
||||
const res = await mockApi.get("/api/v1/users/1/banner").redirects(1);
|
||||
|
||||
t.equal(res.statusCode, 200, "Should return 200.");
|
||||
|
||||
t.equal(res.body.toString(), "test");
|
||||
|
||||
t.end();
|
||||
@@ -24,6 +25,7 @@ t.test("GET /api/v1/users/:userID/banner", (t) => {
|
||||
await db.users.update({ id: 1 }, { $set: { customBanner: true } });
|
||||
const res = await mockApi.get("/api/v1/users/1/banner").redirects(1);
|
||||
|
||||
t.equal(res.statusCode, 200, "Should return 200.");
|
||||
t.equal(res.body.toString(), "foo");
|
||||
|
||||
t.end();
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Router } from "express";
|
||||
import db from "external/mongo/db";
|
||||
import { CDNStoreOrOverwrite, CDNRedirect, CDNDelete } from "lib/cdn/cdn";
|
||||
import { CDNDelete, CDNRedirect, CDNStoreOrOverwrite } from "lib/cdn/cdn";
|
||||
import { GetProfileBannerURL } from "lib/cdn/url-format";
|
||||
import { ONE_MEGABYTE } from "lib/constants/filesize";
|
||||
import { SYMBOL_TachiData } from "lib/constants/tachi";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
import { FormatUserDoc } from "utils/user";
|
||||
import { RequirePermissions } from "server/middleware/auth";
|
||||
import { CreateMulterSingleUploadMiddleware } from "server/middleware/multer-upload";
|
||||
import { FormatUserDoc } from "utils/user";
|
||||
import { RequireAuthedAsUser } from "../middleware";
|
||||
|
||||
// note: this is just the ../pfp/router.ts code copied and altered.
|
||||
|
||||
@@ -108,12 +108,12 @@ app.use(RequestLoggerMiddleware);
|
||||
|
||||
app.use("/", mainRouter);
|
||||
|
||||
// The RUN_OWN_CDN option means that our /cdn path has to be hosted by us. In production,
|
||||
// The SERVE_OWN_CDN option means that our /cdn path has to be hosted by us. In production,
|
||||
// this is not the case (we have a dedicated nginx box for it running in a separate process).
|
||||
// In dev, this is a pain to setup, so we can just run it locally.
|
||||
if (
|
||||
ServerConfig.CDN_CONFIG.SAVE_LOCATION.TYPE === "LOCAL_FILESYSTEM" &&
|
||||
ServerConfig.CDN_CONFIG.SAVE_LOCATION.RUN_OWN_CDN
|
||||
ServerConfig.CDN_CONFIG.SAVE_LOCATION.SERVE_OWN_CDN
|
||||
) {
|
||||
if (Environment.nodeEnv === "production") {
|
||||
logger.warn(
|
||||
@@ -126,7 +126,7 @@ if (
|
||||
});
|
||||
}
|
||||
|
||||
app.use("/cdn", express.static(ServerConfig.CDN_CONFIG.SAVE_LOCATION.LOCATION));
|
||||
app.use("/cdn", express.static("/home/zkldi/Repos/Projects/Tachi/tachi-server/test-cdn"));
|
||||
app.get("/cdn/*", (req, res) => res.status(404).send("No content here."));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user