mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-29 10:28:04 +03:00
fix: just always use absolute urls in tables
raja i hate you and you're bringing me down
This commit is contained in:
@@ -1,11 +1,34 @@
|
||||
import { ServerConfig } from "lib/setup/config";
|
||||
import t from "tap";
|
||||
import mockApi from "test-utils/mock-api";
|
||||
|
||||
t.test("GET /api/v1/games/bms/7K/content/sieglindeEC", (t) => {
|
||||
t.test("html compatibility return should point to the right file", async (t) => {
|
||||
const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeEC");
|
||||
|
||||
const content = /<meta\s+name="bmstable"\s+content="(.*)">/u.exec(res.text);
|
||||
|
||||
if (content) {
|
||||
const maybeMatch = content[1];
|
||||
|
||||
t.equal(
|
||||
maybeMatch,
|
||||
`${ServerConfig.OUR_URL}/api/v1/games/bms/7K/content/sieglindeEC/header.json`
|
||||
);
|
||||
} else {
|
||||
t.fail(`Didn't match regexp for having a bmstable header?`);
|
||||
}
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should point to the right file.", async (t) => {
|
||||
const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeEC/header.json");
|
||||
|
||||
t.equal(res.body.data_url, "./body.json");
|
||||
t.equal(
|
||||
res.body.data_url,
|
||||
`${ServerConfig.OUR_URL}/api/v1/games/bms/7K/content/sieglindeEC/body.json`
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
@@ -25,11 +48,13 @@ t.test("GET /api/v1/games/bms/7K/content/sieglindeHC", (t) => {
|
||||
t.test("Should point to the right file.", async (t) => {
|
||||
const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeHC/header.json");
|
||||
|
||||
t.equal(res.body.data_url, "./body.json");
|
||||
t.equal(
|
||||
res.body.data_url,
|
||||
`${ServerConfig.OUR_URL}/api/v1/games/bms/7K/content/sieglindeHC/body.json`
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("`body.json` should return an array.", async (t) => {
|
||||
const res = await mockApi.get("/api/v1/games/bms/7K/content/sieglindeHC/body.json");
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Router } from "express";
|
||||
import db from "external/mongo/db";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
import { ServerConfig } from "lib/setup/config";
|
||||
import { CreateSongMap } from "tachi-common";
|
||||
import { GetFolderCharts, GetFoldersFromTable } from "utils/folder";
|
||||
import path from "path";
|
||||
import type { Request, Response } from "express";
|
||||
import type { ChartDocument } from "tachi-common/types";
|
||||
|
||||
@@ -10,6 +12,13 @@ const logger = CreateLogCtx(__filename);
|
||||
|
||||
const router: Router = Router({ mergeParams: true });
|
||||
|
||||
function mkAbsoluteURL(tableName: string, headerOrBody: "body" | "header") {
|
||||
return (
|
||||
ServerConfig.OUR_URL +
|
||||
path.join("/api/v1/games/bms/7K/content/", tableName, `${headerOrBody}.json`)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function for mounting a BMS-style Table. This defines
|
||||
* a header.json endpoint, and a body.json endpoint.
|
||||
@@ -24,9 +33,11 @@ function CreateAndMountTable(
|
||||
bodyHandler: (req: Request, res: Response) => unknown
|
||||
) {
|
||||
router.get(`/${tableName}`, (req, res) => {
|
||||
const ABS_URL = mkAbsoluteURL(tableName, "header");
|
||||
|
||||
return res.status(200).send(`<html>
|
||||
<head>
|
||||
<meta name="bmstable" value="./header.json">
|
||||
<meta name="bmstable" content="${ABS_URL}">
|
||||
</head>
|
||||
<body>This is a stub page for the ${tableName} table. <a href="/">Go Home?</a></body>
|
||||
</html>`);
|
||||
@@ -49,7 +60,7 @@ CreateAndMountTable(
|
||||
return res.status(200).send({
|
||||
name: "Sieglinde EC",
|
||||
symbol: "sgl-",
|
||||
data_url: "./body.json",
|
||||
data_url: mkAbsoluteURL("sieglindeEC", "body"),
|
||||
});
|
||||
},
|
||||
/* body.json */ async (req, res) => {
|
||||
@@ -111,7 +122,7 @@ CreateAndMountTable(
|
||||
return res.status(200).send({
|
||||
name: "Sieglinde HC",
|
||||
symbol: "sgl-",
|
||||
data_url: "./body.json",
|
||||
data_url: mkAbsoluteURL("sieglindeHC", "body"),
|
||||
});
|
||||
},
|
||||
/* body.json */ async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user