Skip to content

Commit

Permalink
Fixing mismatch with asset exporting to NPX files (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickGeek committed Feb 20, 2022
1 parent 0d7f012 commit 8531d75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
37 changes: 14 additions & 23 deletions app/src/app/epics/NotepadEpics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,27 +599,18 @@ async function getNotepadMarkdownWithAssets(notepad: Notepad): Promise<IExported
return { title: notepad.title, content: await notepad.toMarkdown(assets) };
}

export function getAssets(notepadAssets: string[]): Promise<Asset[]> {
return new Promise<Asset[]>(resolve => {
const assets: Asset[] = [];

if (!notepadAssets || notepadAssets.length === 0) {
resolve(assets);
return;
}

const resolvedAssets: Promise<Blob | null>[] = [];
for (let uuid of notepadAssets) {
resolvedAssets.push(ASSET_STORAGE.getItem(uuid));
}

Promise.all(resolvedAssets)
.then((blobs: Array<Blob | null>) => {
blobs
.filter((blob): blob is Blob => !!blob)
.forEach((blob: Blob, i: number) => assets.push(new Asset(blob, notepadAssets[i])));

resolve(assets);
});
});
export async function getAssets(notepadAssets: string[]): Promise<Asset[]> {
const resolvedAssets: Array<Asset | null> = await Promise.all(notepadAssets.map(uuid =>
ASSET_STORAGE.getItem<Blob>(uuid)
.then(blob => {
if (!blob) return null;
return new Asset(blob, uuid);
})
.catch(e => {
console.warn('skipping asset in export because: ', e);
return null;
})
));

return resolvedAssets.filter((asset): asset is Asset => !!asset);
}
2 changes: 1 addition & 1 deletion app/src/app/services/DifferenceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function uploadAsset(url: string, asset: Blob): Observable<void> {
body: asset,
crossDomain: true,
headers: {
'Content-Type': 'application/octet-stream'
'Content-Type': asset.type
}
}).pipe(
map(() => undefined),
Expand Down

0 comments on commit 8531d75

Please sign in to comment.