fix: load missing assets when retrieving backup (#3192)

This commit is contained in:
Erez Rokah 2020-02-04 11:12:59 +02:00 committed by GitHub
parent a4a721591f
commit 7d792f3005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -290,8 +290,17 @@ export function retrieveLocalBackup(collection: Collection, slug: string) {
if (entry) {
// load assets from backup
const mediaFiles = entry.mediaFiles || [];
const assetProxies: AssetProxy[] = mediaFiles.map(file =>
createAssetProxy({ path: file.path, file: file.file, url: file.url }),
const assetProxies: AssetProxy[] = await Promise.all(
mediaFiles.map(file => {
if (file.file || file.url) {
return createAssetProxy({ path: file.path, file: file.file, url: file.url });
} else {
return getAsset({ collection, entry: fromJS(entry), path: file.path })(
dispatch,
getState,
);
}
}),
);
dispatch(addAssets(assetProxies));

View File

@ -450,7 +450,8 @@ export class Backend {
// make sure to serialize the file
if (file.url?.startsWith('blob:')) {
const blob = await fetch(file.url as string).then(res => res.blob());
return { ...file, file: new File([blob], file.name) };
const options = file.name.match(/.svg$/) ? { type: 'image/svg+xml' } : {};
return { ...file, file: new File([blob], file.name, options) };
}
return file;
}),