From 72517557d3d6f5f34daf4092749fb17ddbe5c687 Mon Sep 17 00:00:00 2001 From: Boris Sekachev <40690378+bsekachev@users.noreply.github.com> Date: Thu, 5 Dec 2019 13:44:51 +0300 Subject: [PATCH] Fixed some issues with dump (#904) * Changed method for downloading annotations * Initial commit * Initial commit * Updated download method for dataset * fixed eslint error --- cvat-core/src/server-proxy.js | 12 +++++------- cvat-ui/src/actions/tasks-actions.ts | 12 ++++++------ cvat-ui/src/components/cvat-app.tsx | 1 + cvat/apps/engine/views.py | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cvat-core/src/server-proxy.js b/cvat-core/src/server-proxy.js index a4fad54288b9..018a58bdf962 100644 --- a/cvat-core/src/server-proxy.js +++ b/cvat-core/src/server-proxy.js @@ -563,20 +563,18 @@ return new Promise((resolve, reject) => { async function request() { - try { - const response = await Axios - .get(`${url}`, { - proxy: config.proxy, - }); + Axios.get(`${url}`, { + proxy: config.proxy, + }).then((response) => { if (response.status === 202) { setTimeout(request, 3000); } else { url = `${url}&action=download`; resolve(url); } - } catch (errorData) { + }).catch((errorData) => { reject(generateError(errorData)); - } + }); } setTimeout(request); diff --git a/cvat-ui/src/actions/tasks-actions.ts b/cvat-ui/src/actions/tasks-actions.ts index ae4b53016a0c..1dfccf7f6826 100644 --- a/cvat-ui/src/actions/tasks-actions.ts +++ b/cvat-ui/src/actions/tasks-actions.ts @@ -164,9 +164,9 @@ ThunkAction, {}, {}, AnyAction> { try { dispatch(dumpAnnotation(task, dumper)); const url = await task.annotations.dump(task.name, dumper); - // false positive - // eslint-disable-next-line security/detect-non-literal-fs-filename - window.open(url); + const downloadAnchor = (window.document.getElementById('downloadAnchor') as HTMLAnchorElement); + downloadAnchor.href = url; + downloadAnchor.click(); } catch (error) { dispatch(dumpAnnotationFailed(task, dumper, error)); return; @@ -270,9 +270,9 @@ ThunkAction, {}, {}, AnyAction> { try { const url = await task.annotations.exportDataset(exporter.tag); - // false positive - // eslint-disable-next-line security/detect-non-literal-fs-filename - window.open(url, '_blank'); + const downloadAnchor = (window.document.getElementById('downloadAnchor') as HTMLAnchorElement); + downloadAnchor.href = url; + downloadAnchor.click(); } catch (error) { dispatch(exportDatasetFailed(task, exporter, error)); } diff --git a/cvat-ui/src/components/cvat-app.tsx b/cvat-ui/src/components/cvat-app.tsx index 09e3d4762300..a99e908139ca 100644 --- a/cvat-ui/src/components/cvat-app.tsx +++ b/cvat-ui/src/components/cvat-app.tsx @@ -233,6 +233,7 @@ export default class CVATApplication extends React.PureComponent { + diff --git a/cvat/apps/engine/views.py b/cvat/apps/engine/views.py index 9326918e1909..47a262c1acb5 100644 --- a/cvat/apps/engine/views.py +++ b/cvat/apps/engine/views.py @@ -364,7 +364,7 @@ def dump(self, request, pk, filename): "{}.{}.{}.{}".format(filename, username, timestamp, db_dumper.format.lower())) queue = django_rq.get_queue("default") - rq_id = "{}@/api/v1/tasks/{}/annotations/{}".format(username, pk, filename) + rq_id = "{}@/api/v1/tasks/{}/annotations/{}/{}".format(username, pk, dump_format, filename) rq_job = queue.fetch_job(rq_id) if rq_job: