Skip to content

Commit

Permalink
update the status while generating zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Eselvire committed Dec 26, 2023
1 parent 82d233b commit 467771e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ import { ZodInfer } from "./types";

// #region zip_profile
{
status.textContent = "Creating zip... (adding account data)";
zip.file(`profile_own-id.json`, JSON.stringify(ourId, null, 2));
if (initData.stn) {
zip.file(`profile_settings.json`, JSON.stringify(initData.stn, null, 2));
Expand All @@ -996,6 +997,7 @@ import { ZodInfer } from "./types";

for (const shortCode of allSnaps) {
log("adding snap", shortCode)
status.textContent = `Creating zip... (adding snap ${shortCode})`;
const data = await getSnapData(shortCode);
const imageBlob = await getSnapImage(shortCode);

Expand All @@ -1009,6 +1011,7 @@ import { ZodInfer } from "./types";
}

zip.file(`snapshots/filename_mapping.json`, JSON.stringify(snapFilenames, null, 2));
status.textContent = `Creating zip... (adding snapshots.csv)`;
zip.file(`snapshots.csv`, csv_stringify_sync.stringify(snapCsvDataset));
// #endregion zip_snaps

Expand All @@ -1020,6 +1023,7 @@ import { ZodInfer } from "./types";
const csvDataset_mifts = [[ "date", "from", "text", "isPrivate", "fromId", "toId", "_id" ]]
const allPublicMifts = await store_getAllMifts(false);
for (const mift of allPublicMifts) {
status.textContent = `Creating zip... (adding mift ${mift._id})`;
const filename = makeNameSafeForFile(`${makeDateSafeForFile(mift.ts)} - from ${mift.fromName} - ${mift.text.slice(0, 60)}`);

zip.file(`mifts/public/${filename}.json`, JSON.stringify(mift, null, 2));
Expand All @@ -1029,13 +1033,15 @@ import { ZodInfer } from "./types";
log("adding private mifts")
const allPrivateMifts = await store_getAllMifts(true);
for (const mift of allPrivateMifts) {
status.textContent = `Creating zip... (adding mift ${mift._id})`;
const filename = makeNameSafeForFile(`${makeDateSafeForFile(mift.ts)} - from ${mift.fromName} - ${mift.text.slice(0, 60)}`);

zip.file(`mifts/private/${filename}.json`, JSON.stringify(mift, null, 2));
zip.file(`mifts/private/${filename}.png`, store_getCreationImage(mift.itemId));
csvDataset_mifts.push([ mift.ts, mift.fromName, mift.text, "true", mift.fromId, mift.toId, mift._id ]);
}

status.textContent = `Creating zip... (adding mifts.csv)`;
zip.file(`mifts.csv`, csv_stringify_sync.stringify(csvDataset_mifts));
// #endregion zip_mifts

Expand All @@ -1047,7 +1053,9 @@ import { ZodInfer } from "./types";
// NOTE: If a creation somehow had it's image and stats downloaded, but no def, it won't appear.
// This shouldn't happen, though, and I'm not sure how we'd recover from that anyway.
const allKeys = await db.getAllKeys('creations-data-def') as string[];
for await (const id of allKeys) {
for (let i = 0; i < allKeys.length; i++) {
const id = allKeys[i];
status.textContent = `Creating zip... (adding creation ${i}/${allKeys.length})`;
const def = await store_getCreationDef(id);
const img = await store_getCreationImage(id);

Expand Down Expand Up @@ -1088,17 +1096,20 @@ import { ZodInfer } from "./types";
}

// NOTE: we only store CSV data for our own creations
status.textContent = `Creating zip... (adding my-creations.csv)`;
zip.file(`my-creations.csv`, csv_stringify_sync.stringify(csvDataset));
}
// #endregion zip_creations

status.textContent = `Creating zip... (adding inventory data)`;
zip.file(`inventory-collected.json`, JSON.stringify(await db.getAllKeys(`inventory-collections`), null, 2));
zip.file(`inventory-created.json`, JSON.stringify(await db.getAllKeys(`inventory-creations`), null, 2));


// #region zip_arealist
{
log("storing area list...");
status.textContent = `Creating zip... (adding area list)`;

const areaList = await api_getMyAreaList();
const csvDataset = [[ "groupId", "id", "areaName", "name", "isSubarea", "isCreator", "isEditor", "totalVisitors", "lastVisit" ]]
Expand Down Expand Up @@ -1127,6 +1138,7 @@ import { ZodInfer } from "./types";


log("generating file...")
status.textContent = `Creating zip... (generating file, this can take a while!)`;
const zipBlob = await zip.generateAsync({type: "blob"})
log("downloading file...")
saveAs(zipBlob, "manyland-account-archive.zip");
Expand Down

0 comments on commit 467771e

Please sign in to comment.