From 3f61e53a4cdffbf92214c38ea18c8bffe078b9e8 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Mon, 10 Oct 2022 16:32:00 -0400 Subject: [PATCH] Better performance on local backend --- src/backends/proxy/implementation.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/backends/proxy/implementation.ts b/src/backends/proxy/implementation.ts index 76d1ea8a..ddf46fb5 100644 --- a/src/backends/proxy/implementation.ts +++ b/src/backends/proxy/implementation.ts @@ -1,12 +1,15 @@ -import { - APIError, blobToFileObj, unsentRequest -} from '../../lib/util'; +import { APIError, basename, blobToFileObj, unsentRequest } from '../../lib/util'; import AuthenticationPage from './AuthenticationPage'; import type { - AssetProxy, Config, Entry, Implementation, - ImplementationFile, PersistOptions, - User + AssetProxy, + Config, + Entry, + Implementation, + DisplayURL, + ImplementationFile, + PersistOptions, + User, } from '../../lib/util'; async function serializeAsset(assetProxy: AssetProxy) { @@ -135,12 +138,17 @@ export default class ProxyBackend implements Implementation { } async getMedia(mediaFolder = this.mediaFolder) { - const files: MediaFile[] = await this.request({ + const files: { path: string; url: string }[] = await this.request({ action: 'getMedia', 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) { @@ -151,6 +159,10 @@ export default class ProxyBackend implements Implementation { return deserializeMediaFile(file); } + getMediaDisplayURL(displayURL: DisplayURL) { + return Promise.resolve(typeof displayURL === 'string' ? displayURL : displayURL.id); + } + async persistMedia(assetProxy: AssetProxy, options: PersistOptions) { const asset = await serializeAsset(assetProxy); const file: MediaFile = await this.request({