feat(storage): add archive storage support for assets

This commit is contained in:
yiling
2026-11-02 13:19:10 +08:00
parent 49a2d7c380
commit 9097ec12bb
100 changed files with 6180 additions and 170 deletions
@@ -3,7 +3,7 @@ import * as path from 'path'
import { z } from 'zod'
import type { AgentToolResult } from '@earendil-works/pi-agent-core'
import { downloadAsset, MAX_DOWNLOAD_ASSETS, type DownloadAssetOutput } from '@shumai/operations'
import type { User } from '@shumai/db'
import { prisma, type User } from '@shumai/db'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { storageBucket } from '@shumai/core/src/asset-read'
import { s3Service } from '@shumai/core/src/s3/s3'
@@ -54,6 +54,26 @@ async function downloadKey(key: string, userId: string): Promise<AgentToolResult
type: ResourceType.Asset,
id: owningAssetId,
})
const sk = await prisma.storageKey.findUnique({
where: { key },
include: {
assets: {
where: { isDeleted: false },
select: { status: true },
},
},
})
if (
sk &&
(sk.isArchived ||
sk.assets.some(
(a) => a.status === 'archiving' || a.status === 'archived' || a.status === 'restoring',
))
) {
throw new Error(
`Original file for storage key "${key}" is archived. Restore the asset first or download its proxy using assetIds with proxy: true.`,
)
}
const filename = sanitizeFilename(path.basename(key)) || 'downloaded_file'
const saved = await saveToSandbox(key, filename)
return {
@@ -67,6 +67,7 @@ describe('operation-backed agent tools', () => {
.map((t) => t.name)
.sort(),
).toEqual([
'archive_assets',
'copy_assets',
'create_comment',
'create_file',
@@ -87,6 +88,7 @@ describe('operation-backed agent tools', () => {
'remove_version',
'rename_asset',
'resolve_comment',
'restore_archived_assets',
'search_assets',
'update_asset_metadata',
])