Fix love records (#6889)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-10-11 23:55:15 +05:00 committed by GitHub
parent 211f4ed3c5
commit 00d8cf2935
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -79,8 +79,10 @@ export const main = async (): Promise<void> => {
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,