refactor(core): move starting symlink resolution to getDownloadLinks and simplify getProjectIds

This commit is contained in:
yiling
2026-06-11 13:08:29 +08:00
parent aed0676032
commit c910f22542
4 changed files with 79 additions and 52 deletions
+8 -14
View File
@@ -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()
})
})
+4 -4
View File
@@ -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 })
})