mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
feat(upload): allow canceling in-progress upload tasks from sidebar (#511)
* feat(upload): allow canceling in-progress upload tasks from sidebar * fix(upload): resolve concurrent confirmation race and store counter issues on cancellation * fix(webui): immediately remove cancelled upload files from file list view
This commit is contained in:
@@ -220,4 +220,27 @@ describe('Upload API', () => {
|
||||
key: 'files/test.mp4',
|
||||
})
|
||||
})
|
||||
|
||||
it('POST /teams/:teamId/upload/tasks/:taskId/cancel', async () => {
|
||||
vi.spyOn(uploadService, 'cancelUploadTask').mockResolvedValue({
|
||||
success: true,
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/team1/upload/tasks/task1/cancel', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: 'Bearer test' },
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json).toEqual({ success: true })
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: ResourceType.Team,
|
||||
id: 'team1',
|
||||
permission: Permission.Edit,
|
||||
}),
|
||||
)
|
||||
expect(uploadService.cancelUploadTask).toHaveBeenCalledWith('team1', 'user1', 'task1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -163,5 +163,20 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
return c.json(resp)
|
||||
},
|
||||
)
|
||||
.post('/teams/:teamId/upload/tasks/:taskId/cancel', async (c) => {
|
||||
const teamId = c.req.param('teamId')
|
||||
const taskId = c.req.param('taskId')
|
||||
const user = c.get('user')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const resp = await uploadService.cancelUploadTask(teamId, user.id, taskId)
|
||||
return c.json(resp)
|
||||
})
|
||||
|
||||
export default route
|
||||
|
||||
Reference in New Issue
Block a user