Browse Source

Add repositories for downloading dataset

pull/1310/head
Hironsan 4 years ago
parent
commit
6b66e538da
2 changed files with 47 additions and 0 deletions
  1. 16
      frontend/repositories/download/apiDownloadFormatRepository.ts
  2. 31
      frontend/repositories/download/apiDownloadRepository.ts

16
frontend/repositories/download/apiDownloadFormatRepository.ts

@ -0,0 +1,16 @@
import ApiService from '@/services/api.service'
import { DownloadFormatRepository } from '@/domain/models/download/downloadFormatRepository'
import { Format } from '~/domain/models/download/format'
export class APIDownloadFormatRepository implements DownloadFormatRepository {
constructor(
private readonly request = ApiService
) {}
async list(projectId: string): Promise<Format[]> {
const url = `/projects/${projectId}/download-format`
const response = await this.request.get(url)
const responseItems: Format[] = response.data
return responseItems.map(item => Format.valueOf(item))
}
}

31
frontend/repositories/download/apiDownloadRepository.ts

@ -0,0 +1,31 @@
import ApiService from '@/services/api.service'
import { DownloadRepository } from '@/domain/models/download/downloadRepository'
export class APIDownloadRepository implements DownloadRepository {
constructor(
private readonly request = ApiService
) {}
async prepare(projectId: string, format: string): Promise<string> {
const url = `/projects/${projectId}/download`
const data = {
format,
}
const response = await this.request.post(url, data)
return response.data.task_id
}
async download(projectId: string, taskId: string): Promise<void> {
const url = `/projects/${projectId}/download?taskId=${taskId}`
const config = {
responseType: 'blob',
}
const response = await this.request.get(url, config)
const downloadUrl = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = downloadUrl
link.setAttribute('download', `${taskId}.zip`)
document.body.appendChild(link)
link.click()
}
}
Loading…
Cancel
Save