Lint and so on
This commit is contained in:
@@ -2,7 +2,10 @@ import JSZip from 'jszip';
|
||||
import type { Manifest, AssetStore } from './types';
|
||||
import { state } from './state.svelte';
|
||||
|
||||
export async function exportBoard(): Promise<{ success: boolean; error?: string }> {
|
||||
export async function exportBoard(): Promise<{
|
||||
success: boolean;
|
||||
error?: string;
|
||||
}> {
|
||||
try {
|
||||
const zip = new JSZip();
|
||||
const assetsFolder = zip.folder('assets');
|
||||
@@ -12,7 +15,7 @@ export async function exportBoard(): Promise<{ success: boolean; error?: string
|
||||
version: 1,
|
||||
items: state.manifest.items.map((item) => ({ ...item })),
|
||||
sharedCss: state.manifest.sharedCss,
|
||||
appCss: state.manifest.appCss
|
||||
appCss: state.manifest.appCss,
|
||||
};
|
||||
|
||||
for (const item of exportManifest.items) {
|
||||
@@ -31,7 +34,7 @@ export async function exportBoard(): Promise<{ success: boolean; error?: string
|
||||
const blob = await zip.generateAsync({
|
||||
type: 'blob',
|
||||
compression: 'DEFLATE',
|
||||
compressionOptions: { level: 9 }
|
||||
compressionOptions: { level: 9 },
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
@@ -41,28 +44,35 @@ export async function exportBoard(): Promise<{ success: boolean; error?: string
|
||||
URL.revokeObjectURL(url);
|
||||
return { success: true };
|
||||
} catch (e) {
|
||||
return { success: false, error: e instanceof Error ? e.message : 'Export failed' };
|
||||
return {
|
||||
success: false,
|
||||
error: e instanceof Error ? e.message : 'Export failed',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function importBoard(file: File): Promise<{ success: boolean; error?: string }> {
|
||||
export async function importBoard(
|
||||
file: File,
|
||||
): Promise<{ success: boolean; error?: string }> {
|
||||
try {
|
||||
const zip = await JSZip.loadAsync(file);
|
||||
|
||||
const manifestFile = zip.file('manifest.json');
|
||||
if (!manifestFile) throw new Error('Invalid .bub file: missing manifest.json');
|
||||
if (!manifestFile)
|
||||
throw new Error('Invalid .bub file: missing manifest.json');
|
||||
|
||||
const manifestJson = await manifestFile.async('string');
|
||||
const raw = JSON.parse(manifestJson);
|
||||
|
||||
if (raw.version !== 1) throw new Error(`Unsupported manifest version: ${raw.version}`);
|
||||
if (raw.version !== 1)
|
||||
throw new Error(`Unsupported manifest version: ${raw.version}`);
|
||||
|
||||
const manifest: Manifest = {
|
||||
version: 1,
|
||||
items: raw.items,
|
||||
sharedCss: raw.sharedCss ?? '',
|
||||
appCss: raw.appCss ?? '',
|
||||
flags: raw.flags ?? {}
|
||||
flags: raw.flags ?? {},
|
||||
};
|
||||
|
||||
const assets: AssetStore = {};
|
||||
@@ -70,7 +80,9 @@ export async function importBoard(file: File): Promise<{ success: boolean; error
|
||||
|
||||
for (const item of manifest.items) {
|
||||
if (item.assetId) {
|
||||
const assetFiles = zip.folder('assets')?.file(new RegExp(`^${item.assetId}\\.`));
|
||||
const assetFiles = zip
|
||||
.folder('assets')
|
||||
?.file(new RegExp(`^${item.assetId}\\.`));
|
||||
if (assetFiles && assetFiles.length > 0) {
|
||||
const assetFile = assetFiles[0];
|
||||
const blob = await assetFile.async('blob');
|
||||
@@ -92,6 +104,9 @@ export async function importBoard(file: File): Promise<{ success: boolean; error
|
||||
state.load(manifest, assets);
|
||||
return { success: true };
|
||||
} catch (e) {
|
||||
return { success: false, error: e instanceof Error ? e.message : 'Import failed' };
|
||||
return {
|
||||
success: false,
|
||||
error: e instanceof Error ? e.message : 'Import failed',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user