project-nomad/admin/app/controllers/downloads_controller.ts
jarvisxyz 4db0010a0d
fix(downloads): add retry button and resource download link for failed downloads (#1059)
Previously, failed downloads showed only an alert icon and a dismiss (X)
button — the user had no way to retry or reach the resource page without
manually re-adding the download and finding the source URL elsewhere.

This commit adds:
- POST /api/downloads/jobs/:jobId/retry endpoint (controller + service)
- retryDownloadJob() API method on the frontend
- Failed-state UI in ActiveDownloads.tsx now shows:
  - Retry button (re-dispatches the original download job)
  - 'Download page' external link (when the download URL is an HTTP(S) URL)
- Loading state on the retry button while the request is in-flight
- Screenshots documenting before/after UI

Co-authored-by: eizus <hello@cdr.xyz>
2026-08-04 03:37:31 +00:00

32 lines
971 B
TypeScript

import type { HttpContext } from '@adonisjs/core/http'
import { DownloadService } from '#services/download_service'
import { downloadJobsByFiletypeSchema } from '#validators/download'
import { inject } from '@adonisjs/core'
@inject()
export default class DownloadsController {
constructor(private downloadService: DownloadService) {}
async index() {
return this.downloadService.listDownloadJobs()
}
async filetype({ request }: HttpContext) {
const payload = await request.validateUsing(downloadJobsByFiletypeSchema)
return this.downloadService.listDownloadJobs(payload.params.filetype)
}
async removeJob({ params }: HttpContext) {
await this.downloadService.removeFailedJob(params.jobId)
return { success: true }
}
async cancelJob({ params }: HttpContext) {
return this.downloadService.cancelJob(params.jobId)
}
async retryJob({ params }: HttpContext) {
return this.downloadService.retryFailedJob(params.jobId)
}
}