Better performance on local backend

This commit is contained in:
Daniel Lautzenheiser 2022-10-10 16:32:00 -04:00
parent 5c31bc9a98
commit 3f61e53a4c

View File

@ -1,12 +1,15 @@
import { import { APIError, basename, blobToFileObj, unsentRequest } from '../../lib/util';
APIError, blobToFileObj, unsentRequest
} from '../../lib/util';
import AuthenticationPage from './AuthenticationPage'; import AuthenticationPage from './AuthenticationPage';
import type { import type {
AssetProxy, Config, Entry, Implementation, AssetProxy,
ImplementationFile, PersistOptions, Config,
User Entry,
Implementation,
DisplayURL,
ImplementationFile,
PersistOptions,
User,
} from '../../lib/util'; } from '../../lib/util';
async function serializeAsset(assetProxy: AssetProxy) { async function serializeAsset(assetProxy: AssetProxy) {
@ -135,12 +138,17 @@ export default class ProxyBackend implements Implementation {
} }
async getMedia(mediaFolder = this.mediaFolder) { async getMedia(mediaFolder = this.mediaFolder) {
const files: MediaFile[] = await this.request({ const files: { path: string; url: string }[] = await this.request({
action: 'getMedia', action: 'getMedia',
params: { branch: this.branch, mediaFolder }, params: { branch: this.branch, mediaFolder },
}); });
return files.map(deserializeMediaFile); return files.map(({ url, path }) => {
const id = url;
const name = basename(path);
return { id, name, displayURL: { id, path }, path };
});
} }
async getMediaFile(path: string) { async getMediaFile(path: string) {
@ -151,6 +159,10 @@ export default class ProxyBackend implements Implementation {
return deserializeMediaFile(file); return deserializeMediaFile(file);
} }
getMediaDisplayURL(displayURL: DisplayURL) {
return Promise.resolve(typeof displayURL === 'string' ? displayURL : displayURL.id);
}
async persistMedia(assetProxy: AssetProxy, options: PersistOptions) { async persistMedia(assetProxy: AssetProxy, options: PersistOptions) {
const asset = await serializeAsset(assetProxy); const asset = await serializeAsset(assetProxy);
const file: MediaFile = await this.request({ const file: MediaFile = await this.request({