mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 19:34:38 +00:00
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:
@@ -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] },
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user