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.

29 lines
950 B

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