feat(storage): add archive storage support for assets (#514)

* feat(storage): add archive storage support for assets

* fix(webui): show archive icon in front of file name in breadcrumb bar

* fix(webui): display archive icon in breadcrumbs when restoring

* refactor(transcode): simplify restore asset workflow to single while loop

* docs(configuration): add archive storage documentation and readme entries

* fix(webui): show archive icon in front of version names and prevent version card overflow

* fix(webui): fix overflow in manage versions dialog scroll area

* fix(webui): prevent manage versions dialog overflow on long file names

* docs(configuration): fix archive storage environment variables and defaults

* fix(storage): address code review findings for archive storage
This commit is contained in:
Yiling-J
2026-11-03 20:31:56 +08:00
committed by GitHub
parent 49a2d7c380
commit ba3c6dbfee
110 changed files with 7013 additions and 199 deletions
+69 -4
View File
@@ -11,8 +11,10 @@ import { authMiddleware } from './middleware/auth'
import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
import type { AssetInfo } from '@shumai/dtos'
import {
archiveAssetsOp,
renameAssetOp,
resolveCommentOp,
restoreArchivedAssetsOp,
runOperation,
updateAssetMetadataOp,
} from '@shumai/core/src/operations'
@@ -817,10 +819,13 @@ describe('file api', () => {
.spyOn(assetService, 'getProjectIds')
.mockResolvedValue(['project-id-1'])
const mockGetDownloadLinks = vi.spyOn(assetService, 'getDownloadLinks').mockResolvedValue([
{ id: 'file1', name: 'file1.txt', url: 'http://link1' },
{ id: 'file2', name: 'file2.txt', url: 'http://link2' },
])
const mockGetDownloadLinks = vi.spyOn(assetService, 'getDownloadLinks').mockResolvedValue({
files: [
{ id: 'file1', name: 'file1.txt', url: 'http://link1' },
{ id: 'file2', name: 'file2.txt', url: 'http://link2' },
],
skippedArchivedCount: 0,
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/download-links', {
@@ -908,4 +913,64 @@ describe('file api', () => {
mockVariant.mockRestore()
})
})
describe('POST /files/archive and POST /files/restore-archive routes', () => {
const validUlid = '01ARZ3NDEKTSV4RRFFQ69G5FAV'
it('archives assets via archiveAssetsOp', async () => {
vi.mocked(runOperation).mockResolvedValueOnce({
archivedAssetIds: [validUlid],
taskIds: ['task-arch-1'],
skippedCount: 0,
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/archive', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ids: [validUlid] }),
})
expect(res.status).toBe(200)
const json = await res.json()
expect(json).toEqual({
archivedAssetIds: [validUlid],
taskIds: ['task-arch-1'],
skippedCount: 0,
})
expect(runOperation).toHaveBeenCalledWith(
archiveAssetsOp,
{ userId: 'user1', via: 'api' },
{ assetIds: [validUlid] },
)
})
it('restores archived assets via restoreArchivedAssetsOp', async () => {
vi.mocked(runOperation).mockResolvedValueOnce({
restoredAssetIds: [validUlid],
taskIds: ['task-rest-1'],
skippedCount: 0,
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/restore-archive', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ids: [validUlid] }),
})
expect(res.status).toBe(200)
const json = await res.json()
expect(json).toEqual({
restoredAssetIds: [validUlid],
taskIds: ['task-rest-1'],
skippedCount: 0,
})
expect(runOperation).toHaveBeenCalledWith(
restoreArchivedAssetsOp,
{ userId: 'user1', via: 'api' },
{ assetIds: [validUlid] },
)
})
})
})