mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 04:32:35 +01:00
Rearrange assets a bit, fix anything that uses assets folder
This commit is contained in:
parent
427e1d0bed
commit
fa89b18d95
Before Width: | Height: | Size: 312 KiB After Width: | Height: | Size: 312 KiB |
@ -5,10 +5,12 @@ import fetch, { Response as FetchResponse } from "node-fetch";
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import { Config } from "@fosscord/util";
|
||||
|
||||
const ASSET_FOLDER_PATH = path.join(__dirname, "..", "..", "..", "assets");
|
||||
|
||||
export default function TestClient(app: Application) {
|
||||
const agent = new ProxyAgent();
|
||||
const assetCache = new Map<string, { response: FetchResponse; buffer: Buffer; }>();
|
||||
const indexHTML = fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "client_test", "index.html"), { encoding: "utf8" });
|
||||
const indexHTML = fs.readFileSync(path.join(ASSET_FOLDER_PATH, "client_test", "index.html"), { encoding: "utf8" });
|
||||
|
||||
var html = indexHTML;
|
||||
const CDN_ENDPOINT = (Config.get().cdn.endpointClient || Config.get()?.cdn.endpointPublic || process.env.CDN || "").replace(
|
||||
@ -24,24 +26,24 @@ export default function TestClient(app: Application) {
|
||||
html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`);
|
||||
}
|
||||
// inline plugins
|
||||
var files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins"));
|
||||
var files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "preload-plugins"));
|
||||
var plugins = "";
|
||||
files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins", x))}</script>\n`; });
|
||||
files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(ASSET_FOLDER_PATH, "preload-plugins", x))}</script>\n`; });
|
||||
html = html.replaceAll("<!-- preload plugin marker -->", plugins);
|
||||
|
||||
// plugins
|
||||
files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "plugins"));
|
||||
files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "plugins"));
|
||||
plugins = "";
|
||||
files.forEach(x => { if (x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; });
|
||||
html = html.replaceAll("<!-- plugin marker -->", plugins);
|
||||
//preload plugins
|
||||
files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins"));
|
||||
files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "preload-plugins"));
|
||||
plugins = "";
|
||||
files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins", x))}</script>\n`; });
|
||||
files.forEach(x => { if (x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(ASSET_FOLDER_PATH, "preload-plugins", x))}</script>\n`; });
|
||||
html = html.replaceAll("<!-- preload plugin marker -->", plugins);
|
||||
|
||||
|
||||
app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets")));
|
||||
app.use("/assets", express.static(path.join(ASSET_FOLDER_PATH, "public")));
|
||||
|
||||
app.get("/assets/:file", async (req: Request, res: Response) => {
|
||||
delete req.headers.host;
|
||||
@ -90,7 +92,7 @@ export default function TestClient(app: Application) {
|
||||
|
||||
if (!useTestClient) return res.send("Test client is disabled on this instance. Use a stand-alone client to connect this instance.");
|
||||
|
||||
res.send(fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "developers.html"), { encoding: "utf8" }));
|
||||
res.send(fs.readFileSync(path.join(ASSET_FOLDER_PATH, "client_test", "developers.html"), { encoding: "utf8" }));
|
||||
});
|
||||
app.get("*", (req: Request, res: Response) => {
|
||||
const { useTestClient } = Config.get().client;
|
||||
|
@ -5,9 +5,11 @@ import i18nextMiddleware from "i18next-http-middleware";
|
||||
import i18nextBackend from "i18next-node-fs-backend";
|
||||
import { Router } from "express";
|
||||
|
||||
const ASSET_FOLDER_PATH = path.join(__dirname, "..", "..", "..", "assets");
|
||||
|
||||
export async function initTranslation(router: Router) {
|
||||
const languages = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "locales"));
|
||||
const namespaces = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "locales", "en"));
|
||||
const languages = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "locales"));
|
||||
const namespaces = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "locales", "en"));
|
||||
const ns = namespaces.filter((x) => x.endsWith(".json")).map((x) => x.slice(0, x.length - 5));
|
||||
|
||||
await i18next
|
||||
@ -19,7 +21,7 @@ export async function initTranslation(router: Router) {
|
||||
fallbackLng: "en",
|
||||
ns,
|
||||
backend: {
|
||||
loadPath: __dirname + "/../../locales/{{lng}}/{{ns}}.json"
|
||||
loadPath: path.join(ASSET_FOLDER_PATH, "locales") + "/{{lng}}/{{ns}}.json",
|
||||
},
|
||||
load: "all"
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const sizeOf = require("image-size");
|
||||
|
||||
// TODO: Widget style templates need Fosscord branding
|
||||
const source = path.join(__dirname, "..", "..", "..", "..", "assets", "widget", `${style}.png`);
|
||||
const source = path.join(__dirname, "..", "..", "..", "..", "..", "assets", "widget", `${style}.png`);
|
||||
if (!fs.existsSync(source)) {
|
||||
throw new HTTPError("Widget template does not exist.", 400);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user