Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #241 from COS301-SE-2023/feature/add-multiple-assets
Browse files Browse the repository at this point in the history
I hate autosave
  • Loading branch information
ArmandKrynauw authored Oct 27, 2023
2 parents ff9a840 + 3b9e7c4 commit e3992d7
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/frontend/ui/tiles/Assets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,35 @@
async function requestFileAccess() {
try {
const handle = await window.showOpenFilePicker();
const file = await handle[0].getFile();
const blob = await file.arrayBuffer();
const cacheId = await cacheStore.addCacheObject(new Blob([blob], { type: file.type }), {
name: file.name,
contentType: file.type,
});
if ($projectsStore.activeProject && cacheId) {
const res = await window.apis.projectApi.addCacheObjects($projectsStore.activeProject.id, [
cacheId,
]);
const handle = await window.showOpenFilePicker({ multiple: true });
// let file: any[];
const assets: { file: any; buffer: any }[] = await Promise.all(
handle.map(async (asset: any) => ({
file: await asset.getFile(),
buffer: await (await asset.getFile()).arrayBuffer(),
}))
);
if (!res.success) {
toastStore.trigger({ message: res.data, type: "error" });
assets.forEach(async (asset: { file: any; buffer: any }) => {
const cacheId = await cacheStore.addCacheObject(
new Blob([asset.buffer], { type: asset.file.type }),
{
name: asset.file.name,
contentType: asset.file.type,
}
);
// console.log("id: ", cacheId)
if ($projectsStore.activeProject && cacheId) {
const res = await window.apis.projectApi.addCacheObjects(
$projectsStore.activeProject.id,
[cacheId]
);
if (!res.success) {
toastStore.trigger({ message: res.data, type: "error" });
}
}
}
});
} catch (error) {
console.error(error);
}
Expand Down

0 comments on commit e3992d7

Please sign in to comment.