mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 02:19:28 +00:00
refactor(core): move starting symlink resolution to getDownloadLinks and simplify getProjectIds
This commit is contained in:
@@ -455,12 +455,9 @@ describe('file api', () => {
|
||||
})
|
||||
|
||||
it('POST /files/download-links generates links if assets belong to the same project', async () => {
|
||||
const mockGetProjectIdsAndStartingIds = vi
|
||||
.spyOn(assetService, 'getProjectIdsAndStartingIds')
|
||||
.mockResolvedValue({
|
||||
projectIds: ['project-id-1'],
|
||||
startingIds: ['asset1', 'asset2'],
|
||||
})
|
||||
const mockGetProjectIds = vi
|
||||
.spyOn(assetService, 'getProjectIds')
|
||||
.mockResolvedValue(['project-id-1'])
|
||||
|
||||
const mockGetDownloadLinks = vi.spyOn(assetService, 'getDownloadLinks').mockResolvedValue([
|
||||
{ id: 'file1', name: 'file1.txt', url: 'http://link1' },
|
||||
@@ -488,17 +485,14 @@ describe('file api', () => {
|
||||
|
||||
expect(assetService.getDownloadLinks).toHaveBeenCalledWith(['asset1', 'asset2'])
|
||||
|
||||
mockGetProjectIdsAndStartingIds.mockRestore()
|
||||
mockGetProjectIds.mockRestore()
|
||||
mockGetDownloadLinks.mockRestore()
|
||||
})
|
||||
|
||||
it('POST /files/download-links rejects if assets belong to different projects', async () => {
|
||||
const mockGetProjectIdsAndStartingIds = vi
|
||||
.spyOn(assetService, 'getProjectIdsAndStartingIds')
|
||||
.mockResolvedValue({
|
||||
projectIds: ['project-id-1', 'project-id-2'],
|
||||
startingIds: ['asset1', 'asset2'],
|
||||
})
|
||||
const mockGetProjectIds = vi
|
||||
.spyOn(assetService, 'getProjectIds')
|
||||
.mockResolvedValue(['project-id-1', 'project-id-2'])
|
||||
|
||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||
const res = await app.request('/files/download-links', {
|
||||
@@ -511,6 +505,6 @@ describe('file api', () => {
|
||||
const json = await res.json()
|
||||
expect(json.error).toBe('All selected items must belong to the same project')
|
||||
|
||||
mockGetProjectIdsAndStartingIds.mockRestore()
|
||||
mockGetProjectIds.mockRestore()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -273,10 +273,10 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
return c.json({ files: [] })
|
||||
}
|
||||
|
||||
// 1. Fetch project IDs and starting IDs from the service layer
|
||||
const { projectIds, startingIds } = await assetService.getProjectIdsAndStartingIds(req.ids)
|
||||
// 1. Fetch project IDs from the service layer
|
||||
const projectIds = await assetService.getProjectIds(req.ids)
|
||||
|
||||
if (startingIds.length === 0) {
|
||||
if (projectIds.length === 0) {
|
||||
return c.json({ files: [] })
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
})
|
||||
|
||||
// 4. Generate download links
|
||||
const files = await assetService.getDownloadLinks(startingIds)
|
||||
const files = await assetService.getDownloadLinks(req.ids)
|
||||
return c.json({ files })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user