From c2a585c4cf3305c4203ab84ab8f6d9b0397d56a1 Mon Sep 17 00:00:00 2001 From: Martin Krulis Date: Thu, 19 Oct 2023 18:30:05 +0200 Subject: [PATCH] Fixing ALC hints for plagiarism source download. --- .../Solutions/PlagiarismCodeBox/PlagiarismCodeBox.js | 1 + src/pages/SolutionPlagiarisms/SolutionPlagiarisms.js | 2 +- src/redux/modules/files.js | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/Solutions/PlagiarismCodeBox/PlagiarismCodeBox.js b/src/components/Solutions/PlagiarismCodeBox/PlagiarismCodeBox.js index a2750174a..ed3a535a3 100644 --- a/src/components/Solutions/PlagiarismCodeBox/PlagiarismCodeBox.js +++ b/src/components/Solutions/PlagiarismCodeBox/PlagiarismCodeBox.js @@ -276,6 +276,7 @@ class PlagiarismCodeBox extends Component { download( selectedPlagiarismFile.solutionFile.id, selectedPlagiarismFile.fileEntry || null, + selectedPlagiarismFile.solutionFile.name, solutionId ); }} diff --git a/src/pages/SolutionPlagiarisms/SolutionPlagiarisms.js b/src/pages/SolutionPlagiarisms/SolutionPlagiarisms.js index 607c2edc1..15376e758 100644 --- a/src/pages/SolutionPlagiarisms/SolutionPlagiarisms.js +++ b/src/pages/SolutionPlagiarisms/SolutionPlagiarisms.js @@ -343,7 +343,7 @@ export default withRouter( }, (dispatch, { params }) => ({ loadAsync: () => SolutionPlagiarisms.loadAsync(params, dispatch), - download: (id, entry = null, solutionId = null) => dispatch(download(id, entry, solutionId)), + download: (...args) => dispatch(download(...args)), addComment: comment => dispatch(addComment(params.solutionId, comment)), updateComment: comment => dispatch(updateComment(params.solutionId, comment)), removeComment: id => dispatch(removeComment(params.solutionId, id)), diff --git a/src/redux/modules/files.js b/src/redux/modules/files.js index 46af873c5..9d3a49859 100644 --- a/src/redux/modules/files.js +++ b/src/redux/modules/files.js @@ -31,13 +31,16 @@ export const fetchFileIfNeeded = actions.fetchOneIfNeeded; * * @param {string} fileId * @param {string|null} entry ZIP archive path (works only for zip uploaded files) + * @param {string|null} saveAs if present, the file will be saved under given name (no need to fetch metadata) + * @param {string|null} similarSolutionId ACL hint if plagiarism source is to be downloaded + * (ID of a solution which is similar with downloaded file) */ -export const download = (fileId, entry = null, similarSolutionId = null) => +export const download = (fileId, entry = null, saveAs = null, similarSolutionId = null) => downloadHelper({ endpoint: `/uploaded-files/${fileId}/download?` + urlQueryString({ entry, similarSolutionId }), - fetch: entry ? null : fetchFileIfNeeded, + fetch: entry || saveAs ? null : fetchFileIfNeeded, actionType: actionTypes.DOWNLOAD, - fileNameSelector: entry ? null : (id, state) => getJsData(getFile(id)(state)).name, + fileNameSelector: saveAs ? () => saveAs : entry ? null : (id, state) => getJsData(getFile(id)(state)).name, contentType: 'application/octet-stream', })(fileId, entry && entry.split('/').pop());