From 73ad359c2c3017873d5436d9eb1844bde125d943 Mon Sep 17 00:00:00 2001 From: Samuel Allan Date: Mon, 28 Jul 2025 17:22:23 +0930 Subject: [PATCH] fix: ignore deleted files in submissions If a file is deleted from disk somehow after the student response has been submitted, the api will still respond with metadata about these files. However, the download url will be empty, resulting in broken files in the frontend ui: the preview pane will display an "Unknown error", and downloading the files will result in downloaded files with the correct file names but invalid content. The student view in ORA handles these deleted files by simply ignoring them and not displaying them to the user. So here we do the same: simply filter out any deleted files from the api. Private-ref: https://tasks.opencraft.com/browse/BB-9781 --- src/data/services/lms/api.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/data/services/lms/api.js b/src/data/services/lms/api.js index bc4c41ce3..656494cc2 100644 --- a/src/data/services/lms/api.js +++ b/src/data/services/lms/api.js @@ -52,7 +52,15 @@ const fetchSubmission = (submissionUUID) => get( [paramKeys.oraLocation]: locationId(), [paramKeys.submissionUUID]: submissionUUID, }), -).then(response => response.data); +).then(response => ({ + ...response.data, + response: { + ...response.data.response, + // The API includes metadata for deleted files (without a download url); + // we don't want to deal with deleted files here, so filter them out like the student view does. + files: response.data.response.files.filter((file) => file.downloadUrl), + }, +})); /** * get('/api/submission/files', { oraLocation, submissionUUID }) @@ -65,7 +73,12 @@ const fetchSubmissionFiles = (submissionUUID) => get( [paramKeys.oraLocation]: locationId(), [paramKeys.submissionUUID]: submissionUUID, }), -).then(response => response.data); +).then(response => ({ + ...response.data, + // The API includes metadata for deleted files (without a download url); + // we don't want to deal with deleted files here, so filter them out like the student view does. + files: response.data.files.filter((file) => file.downloadUrl), +})); /** * fetches the current grade, gradeStatus, and rubricResponse data for the given submission