From 3c81e53e722e4327dc9c575417e30d7c1051934a Mon Sep 17 00:00:00 2001 From: Reimar Date: Tue, 14 Oct 2025 14:11:59 +0200 Subject: [PATCH] fix loading from project file --- src/index.js | 14 ++++++++++---- src/karlkoder_codec.js | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index c7f0322..4b6f2db 100644 --- a/src/index.js +++ b/src/index.js @@ -107,9 +107,15 @@ loadButton.onclick = async () => { }); const code = items.find((x) => x.tag === "code"); delete code.tag; + assetEditor.importAssets( - assets.map(({ name, mime, content }) => ({ name, mime, bytes: content })), + assets.map(({ name, mime, content }) => { + const file = new File([content], name, { type: mime }); + + return { name, file }; + }), ); + projectName.value = code.name; const dec = new TextDecoder(); editor.setValue(dec.decode(code.content)); @@ -141,13 +147,13 @@ exportButton.onclick = async () => { downloadFile(slugify(projectName.value) || "project", html, ".html", "text/html"); }; -function saveKarlKoder() { +async function saveKarlKoder() { downloadFile( slugify(projectName.value) || "project", - KarlkoderCodec.en( + await KarlkoderCodec.en( projectName.value, editor.getValue(), - assetEditor.assets, + await assetEditor.getAssets(), ), ".karlkode", ); diff --git a/src/karlkoder_codec.js b/src/karlkoder_codec.js index 14a4b6d..da694f7 100644 --- a/src/karlkoder_codec.js +++ b/src/karlkoder_codec.js @@ -13,19 +13,19 @@ function strToBytes(str) { } export class KarlkoderCodec { - static en(name, code, assets) { + static async en(name, code, assets) { const ret = []; for (const asset of assets) { ret.push(...strToBytes("asset")); ret.push(...strToBytes(asset.name.length.toString())); ret.push(...strToBytes(";")); - ret.push(...strToBytes(asset.mime.length.toString())); + ret.push(...strToBytes(asset.file.type.length.toString())); ret.push(...strToBytes(";")); - ret.push(...strToBytes(asset.bytes.length.toString())); + ret.push(...strToBytes(asset.file.size.toString())); ret.push(...strToBytes(";")); ret.push(...strToBytes(asset.name)); - ret.push(...strToBytes(asset.mime)); - ret.push(...asset.bytes); + ret.push(...strToBytes(asset.file.type)); + ret.push(...await asset.file.bytes()); } ret.push(...strToBytes("code")); ret.push(...strToBytes(name.length.toString()));