You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.0 KiB

  1. import ApiService from '@/services/api.service'
  2. import { DownloadRepository } from '@/domain/models/download/downloadRepository'
  3. export class APIDownloadRepository implements DownloadRepository {
  4. constructor(
  5. private readonly request = ApiService
  6. ) {}
  7. async prepare(projectId: string, format: string, exportApproved: boolean): Promise<string> {
  8. const url = `/projects/${projectId}/download`
  9. const data = {
  10. format,
  11. exportApproved,
  12. }
  13. const response = await this.request.post(url, data)
  14. return response.data.task_id
  15. }
  16. async download(projectId: string, taskId: string): Promise<void> {
  17. const url = `/projects/${projectId}/download?taskId=${taskId}`
  18. const config = {
  19. responseType: 'blob',
  20. }
  21. const response = await this.request.get(url, config)
  22. const downloadUrl = window.URL.createObjectURL(new Blob([response.data]))
  23. const link = document.createElement('a')
  24. link.href = downloadUrl
  25. link.setAttribute('download', `${taskId}.zip`)
  26. document.body.appendChild(link)
  27. link.click()
  28. }
  29. }