Export saved data (#400)

This commit is contained in:
1ilit
2025-04-10 22:08:31 +04:00
committed by GitHub
parent fe0cbbe2ee
commit 436ab3ec33
5 changed files with 136 additions and 2 deletions

View File

@@ -77,6 +77,7 @@ import { jsonToDocumentation } from "../../utils/exportAs/documentation";
import { IdContext } from "../Workspace";
import { socials } from "../../data/socials";
import { toDBML } from "../../utils/exportAs/dbml";
import { exportSavedData } from "../../utils/exportSavedData";
export default function ControlPanel({
diagramId,
@@ -1419,6 +1420,9 @@ export default function ControlPanel({
language: {
function: () => setModal(MODAL.LANGUAGE),
},
export_saved_data: {
function: exportSavedData,
},
flush_storage: {
warning: {
title: t("flush_storage"),

View File

@@ -249,6 +249,7 @@ const en = {
supported_types: "Supported file types:",
bulk_update: "Bulk update",
multiselect: "Multiselect",
export_saved_data: "Export saved data",
},
};

View File

@@ -0,0 +1,35 @@
import JSZip from "jszip";
import { db } from "../data/db";
import { saveAs } from "file-saver";
const zip = new JSZip();
export async function exportSavedData() {
const diagramsFolder = zip.folder("diagrams");
await db.diagrams.each((diagram) => {
diagramsFolder.file(
`${diagram.name}(${diagram.id}).json`,
JSON.stringify(diagram, null, 2),
);
return true;
});
const templatesFolder = zip.folder("templates");
await db.templates.where({ custom: 1 }).each((template) => {
templatesFolder.file(
`${template.title}(${template.id}).json`,
JSON.stringify(template, null, 2),
);
return true;
});
zip.generateAsync({ type: "blob" }).then(function (content) {
const date = new Date();
saveAs(
content,
`${date.getFullYear()}_${date.getMonth()}_${date.getDay()}_export.zip`,
);
});
}