diff --git a/services/love/src/main.ts b/services/love/src/main.ts index eeeb5bcb4b..8f4ad0fb73 100644 --- a/services/love/src/main.ts +++ b/services/love/src/main.ts @@ -79,8 +79,10 @@ export const main = async (): Promise => { const data = dataByUUID.get(res.filename) if (data !== undefined) { const client = await WorkspaceClient.create(data.workspace) - await storageAdapter.syncBlobFromStorage(ctx, data.workspaceId, res.filename, storageConfig?.name) - await client.saveFile(res.filename, data.name) + const prefix = rootPrefix(storageConfig, data.workspaceId) + const filename = stripPrefix(prefix, res.filename) + await storageAdapter.syncBlobFromStorage(ctx, data.workspaceId, filename, storageConfig?.name) + await client.saveFile(filename, data.name) await client.close() dataByUUID.delete(res.filename) } else { @@ -203,6 +205,17 @@ function getDocumentKey (storageConfig: any, workspace: WorkspaceId, name: strin return storageConfig.rootBucket === undefined ? name : `${getBucketFolder(workspace)}/${name}` } +function stripPrefix (prefix: string | undefined, key: string): string { + if (prefix !== undefined && key.startsWith(prefix)) { + return key.slice(prefix.length) + } + return key +} + +function rootPrefix (storageConfig: any, workspaceId: WorkspaceId): string | undefined { + return storageConfig.rootBucket !== undefined ? getBucketFolder(workspaceId) + '/' : undefined +} + const startRecord = async ( storageConfig: StorageConfig | undefined, egressClient: EgressClient,