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.

30 lines
1.0 KiB

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