Add map import and export with durable refresh progress

This commit is contained in:
2026-10-07 19:44:49 +05:00
parent dac8650ac1
commit 1307436e65
37 changed files with 2207 additions and 85 deletions

View File

@@ -5,6 +5,7 @@ import { mkdir, writeFile, readFile, readdir, rm } from "node:fs/promises";
import { gunzipSync } from "node:zlib";
import sharp from "sharp";
import { datasetSchema, faces, type TerrainSnapshot } from "../shared/protocol";
import { processFabricImages } from "../lib/fabric-images";
import { renderSnapshot } from "../renderer/render.mjs";
import type { Database } from "../shared/database";
if (existsSync(".env.local")) process.loadEnvFile(".env.local");
@@ -109,7 +110,11 @@ async function processJob(job: {
(a) =>
!mapOnly ||
a.path ===
(manifest.source === "plugin" ? "terrain.json.gz" : "map.png"),
(manifest.mediaFormat
? "map.webp"
: manifest.source === "plugin"
? "terrain.json.gz"
: "map.png"),
);
await progress(0, `Downloading ${assets.length} export files`);
let downloaded = 0;
@@ -136,7 +141,22 @@ async function processJob(job: {
}
const output = `${directory}/media`;
await mkdir(output, { recursive: true });
if (manifest.source === "plugin") {
if (manifest.mediaFormat) {
await processFabricImages(manifest, {
mapOnly,
signal: abort.signal,
download: (path) => readFile(`${directory}/raw/${path}`),
async save(path, bytes) {
await mkdir(
`${output}/${path}`.slice(0, `${output}/${path}`.lastIndexOf("/")),
{ recursive: true },
);
await writeFile(`${output}/${path}`, bytes);
},
progress: (percent) =>
progress(20 + percent * 0.7, "Validating imported map images"),
});
} else if (manifest.source === "plugin") {
await progress(20, "Reading the terrain snapshot");
const compressed = await readFile(`${directory}/raw/terrain.json.gz`);
const terrain = JSON.parse(