Skip to content

Commit

Permalink
fix(file download): fix required file server to download files
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentinTh committed May 14, 2021
1 parent 7cc69ca commit 286cacc
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 60 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
API_URL=https://localhost:3000/api
API_VERSION=1
API_PROXY=https://cors-anywhere.herokuapp.com
FILE_SERVER_URL=http://localhost:8080
JOB_LOGS_FILE=https://localhost/files/jobs.log

59 changes: 17 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"handlebars": "^4.7.7",
"handlebars-utils": "^1.0.6",
"js-cookie": "^2.2.1",
"js-file-download": "^0.4.12",
"plotly.js-cartesian-dist": "^1.58.4",
"sweetalert2": "^10.16.7",
"util": "^0.12.3"
Expand Down
14 changes: 10 additions & 4 deletions src/components/admin/administration/jobs-log/JobsLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import axios from 'axios';
import APIHelper from '@APIHelper';
import ModalHelper from '@ModalHelper';
import EventSource from 'eventsource';
import fileDownload from 'js-file-download';

let logEntries;
class JobsLog extends Component {
Expand Down Expand Up @@ -164,10 +165,15 @@ class JobsLog extends Component {
event.preventDefault();
event.stopImmediatePropagation();

window.open(
new URL(window.env.FILE_SERVER_URL + '/' + window.env.JOB_LOGS_FILE),
'_blank'
);
axios
.get('/jobs/log/file', {
headers: APIHelper.setAuthHeader()
})
.then(response => {
if (response) {
fileDownload(response.data, 'jobs.log');
}
});
}

openEventSource(close = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import APIHelper from '@APIHelper';
import ModalHelper from '@ModalHelper';
import { Filters, FilterType } from '@Filters';
import Search from '@Search';
import fileDownload from 'js-file-download';

let fileModels;
let fileRaw;
Expand Down Expand Up @@ -248,16 +249,22 @@ class FileContent extends Component {
'Preparing Download...',
'Your download will begin automatically'
);

downloadFile(
`/files/${filename}/download?source=${this.dataSource}&type=${this.fileType}&from=${fileFormat}&to=${selectedFormat}`,
this.context
).then(response => {
if (response) {
loader.close();
window.open(
new URL(window.env.FILE_SERVER_URL + '/' + response.data),
'_blank'
);

let mimetype = 'text/csv';

if (typeof response === 'object') {
response = JSON.stringify(response, null, 2);
mimetype = 'application/json';
}

fileDownload(response, `${filename}.${selectedFormat}`, mimetype);
}
});
}
Expand Down
11 changes: 3 additions & 8 deletions src/components/admin/jobs/Jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ModalHelper from '@ModalHelper';
import StringHelper from '@StringHelper';
import Store from '@Store';
import EventSource from 'eventsource';
import fileDownload from 'js-file-download';

let startedJobs;
let completedJobs;
Expand Down Expand Up @@ -257,10 +258,7 @@ class Jobs extends Component {
downloadFile(`/jobs/${jobId}/download?output=matrix`, this.context).then(
response => {
if (response) {
window.open(
new URL(window.env.FILE_SERVER_URL + '/' + response.data),
'_blank'
);
fileDownload(response, 'matrix.csv');
}
}
);
Expand All @@ -283,10 +281,7 @@ class Jobs extends Component {
downloadFile(`/jobs/${jobId}/download?output=predictions`, this.context).then(
response => {
if (response) {
window.open(
new URL(window.env.FILE_SERVER_URL + '/' + response.data),
'_blank'
);
fileDownload(response, 'predictions.csv');
}
}
);
Expand Down

0 comments on commit 286cacc

Please sign in to comment.