mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 21:04:59 +00:00
feat(storage): add archive storage support for assets
This commit is contained in:
@@ -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',
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user