mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-25 03:33:33 +01:00
npm run generate:client
downloads more assets now (Thanks Rory!). Also ONLY_CACHE_JS
env var (#948)
This commit is contained in:
parent
1a0cbcb1d4
commit
683cd108e8
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,6 +8,7 @@ files/
|
|||||||
assets/cache
|
assets/cache
|
||||||
.env
|
.env
|
||||||
config.json
|
config.json
|
||||||
|
assets/cacheMisses
|
||||||
|
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
TODO: Make this configurable easily.
|
TODO: Make this configurable easily.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require("dotenv/config");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
@ -51,6 +52,7 @@ const CACHE_PATH = path.join(__dirname, "..", "assets", "cache");
|
|||||||
const BASE_URL = "https://discord.com";
|
const BASE_URL = "https://discord.com";
|
||||||
|
|
||||||
const INSTANCE_NAME = "Fosscord";
|
const INSTANCE_NAME = "Fosscord";
|
||||||
|
const ONLY_CACHE_JS = process.env.ONLY_CACHE_JS ? true : false;
|
||||||
|
|
||||||
// Manual for now
|
// Manual for now
|
||||||
const INDEX_SCRIPTS = [
|
const INDEX_SCRIPTS = [
|
||||||
@ -58,6 +60,15 @@ const INDEX_SCRIPTS = [
|
|||||||
"cfb9efe961b2bf3647bc", // 1
|
"cfb9efe961b2bf3647bc", // 1
|
||||||
"f98a039261c37f892cbf", // 0?
|
"f98a039261c37f892cbf", // 0?
|
||||||
"4470c87bb13810847db0", // ~4500.
|
"4470c87bb13810847db0", // ~4500.
|
||||||
|
|
||||||
|
// also fetch other assets from index, as they aren't cached
|
||||||
|
"40532.f4ff6c4a39fa78f07880.css",
|
||||||
|
"b21a783b953e52485dcb.worker.js",
|
||||||
|
"2bbea887c6d07e427a1d.worker.js",
|
||||||
|
"0ec5df6d78ff7a5cc7c8.worker.js",
|
||||||
|
"05422eb499ddf5616e44a52c4f1063ae.woff2",
|
||||||
|
"77f603cc7860fcb784e6ef9320a4a9c2.woff2",
|
||||||
|
"e689380400b1f2d2c6320a823a1ab079.svg",
|
||||||
];
|
];
|
||||||
|
|
||||||
const doPatch = (content) => {
|
const doPatch = (content) => {
|
||||||
@ -181,12 +192,9 @@ const doPatch = (content) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const processFile = async (name) => {
|
const processFile = async (name) => {
|
||||||
const res = await fetch(
|
const url = `${BASE_URL}/assets/${name}${name.includes(".") ? "" : ".js"}`;
|
||||||
`${BASE_URL}/assets/${name}${name.includes(".") ? "" : ".js"}`,
|
if (ONLY_CACHE_JS && !url.endsWith(".js")) return [];
|
||||||
{
|
const res = await fetch(url, { agent });
|
||||||
agent,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -205,15 +213,20 @@ const processFile = async (name) => {
|
|||||||
text,
|
text,
|
||||||
);
|
);
|
||||||
|
|
||||||
return [...new Set(text.match(/\"[A-Fa-f0-9]{20}\"/g))].map((x) =>
|
var additional = [];
|
||||||
x.replaceAll('"', ""),
|
additional.push(...new Set(text.match(/\"[A-Fa-f0-9]{20}\"/g)));
|
||||||
|
additional.push(
|
||||||
|
...[
|
||||||
|
...new Set(text.matchAll(/\.exports=.\..\+\"(.*?\..{0,5})\"/g)),
|
||||||
|
].map((x) => x[1]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return additional.map((x) => x.replaceAll('"', ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
const print = (x) => {
|
const print = (x) => {
|
||||||
process.stdout.write(
|
var repeat = process.stdout.columns - x.length;
|
||||||
`${x}${" ".repeat(process.stdout.columns - x.length)}\r`,
|
process.stdout.write(`${x}${" ".repeat(Math.max(0, repeat))}\r`);
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
@ -270,11 +283,17 @@ const print = (x) => {
|
|||||||
if (file.includes(".js") || file.includes(".css")) {
|
if (file.includes(".js") || file.includes(".css")) {
|
||||||
text = doPatch(text.toString());
|
text = doPatch(text.toString());
|
||||||
await fs.writeFile(path.join(CACHE_PATH, file), text.toString());
|
await fs.writeFile(path.join(CACHE_PATH, file), text.toString());
|
||||||
assets.push(
|
|
||||||
...[...new Set(text.match(/\"[A-Fa-f0-9]{20}\"/g))].map((x) =>
|
var additional = [];
|
||||||
x.replaceAll('"', ""),
|
additional.push(...new Set(text.match(/\"[A-Fa-f0-9]{20}\"/g)));
|
||||||
),
|
additional.push(
|
||||||
|
...[
|
||||||
|
...new Set(
|
||||||
|
text.matchAll(/\.exports=.\..\+\"(.*?\..{0,5})\"/g),
|
||||||
|
),
|
||||||
|
].map((x) => x[1]),
|
||||||
);
|
);
|
||||||
|
assets.push(additional.map((x) => x.replaceAll('"', "")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user