mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 10:08:08 +00:00
upload manifest to r2 before starting container (#3767)
## Description: It first sends the manifest to the worker to get a list of missing files, then for each missing file it uploads them to r2 via cf worker. This PR also has us write out the manifest in plan json instead of an mjs file. This makes it easier for the shell script to parse ## Please complete the following: - [x] I have added screenshots for all UI updates - [ ] I process any text displayed to the user through translateText() and I've added it to the en.json file - [ ] I have added relevant tests to the test directory - [ ] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
This commit is contained in:
@@ -371,15 +371,11 @@ export function copyRootPublicFiles(
|
||||
}
|
||||
}
|
||||
|
||||
export function writePublicAssetManifestModule(
|
||||
export function writePublicAssetManifest(
|
||||
outDir: string,
|
||||
assetManifest: AssetManifest,
|
||||
): void {
|
||||
const manifestPath = path.join(outDir, "_assets", "asset-manifest.mjs");
|
||||
const manifestPath = path.join(outDir, "_assets", "asset-manifest.json");
|
||||
fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
||||
const serializedManifest = JSON.stringify(assetManifest, null, 2);
|
||||
fs.writeFileSync(
|
||||
manifestPath,
|
||||
`const assetManifest = ${serializedManifest};\nexport { assetManifest };\nexport default assetManifest;\n`,
|
||||
);
|
||||
fs.writeFileSync(manifestPath, `${JSON.stringify(assetManifest, null, 2)}\n`);
|
||||
}
|
||||
|
||||
@@ -1,40 +1,34 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath, pathToFileURL } from "url";
|
||||
import { fileURLToPath } from "url";
|
||||
import type { AssetManifest } from "../core/AssetUrls";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const staticDir = path.join(__dirname, "../../static");
|
||||
const manifestPath = path.join(staticDir, "_assets", "asset-manifest.mjs");
|
||||
const manifestPath = path.join(staticDir, "_assets", "asset-manifest.json");
|
||||
|
||||
let manifestPromise: Promise<AssetManifest> | null = null;
|
||||
let manifestVersion = 0;
|
||||
|
||||
async function importRuntimeAssetManifest(
|
||||
version: number,
|
||||
): Promise<AssetManifest> {
|
||||
const manifestModule = (await import(
|
||||
`${pathToFileURL(manifestPath).href}?v=${version}`
|
||||
)) as {
|
||||
assetManifest?: AssetManifest;
|
||||
default?: AssetManifest;
|
||||
};
|
||||
return manifestModule.assetManifest ?? manifestModule.default ?? {};
|
||||
}
|
||||
let cachedManifest: AssetManifest | null = null;
|
||||
|
||||
export async function getRuntimeAssetManifest(): Promise<AssetManifest> {
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
return {};
|
||||
if (cachedManifest !== null) {
|
||||
return cachedManifest;
|
||||
}
|
||||
|
||||
manifestPromise ??= importRuntimeAssetManifest(manifestVersion).catch(
|
||||
() => ({}),
|
||||
);
|
||||
return manifestPromise;
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
cachedManifest = {};
|
||||
return cachedManifest;
|
||||
}
|
||||
try {
|
||||
cachedManifest = JSON.parse(
|
||||
fs.readFileSync(manifestPath, "utf8"),
|
||||
) as AssetManifest;
|
||||
} catch (err) {
|
||||
console.error(`Failed to parse asset manifest at ${manifestPath}:`, err);
|
||||
cachedManifest = {};
|
||||
}
|
||||
return cachedManifest;
|
||||
}
|
||||
|
||||
export function clearRuntimeAssetManifestCache(): void {
|
||||
manifestVersion++;
|
||||
manifestPromise = null;
|
||||
cachedManifest = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user