diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index 359675c6bc..bb41a0c6ce 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -47,7 +47,7 @@ run_test('upload_started', () => { upload_opts.drop(); upload_opts.uploadStarted(0, { - lastModified: 1549958107000, + trackingId: "1549958107000", name: 'some-file', }, 1); @@ -63,7 +63,7 @@ run_test('progress_updated', () => { assert.equal(width_percent, '39%'); width_update_checked = true; }; - upload_opts.progressUpdated(1, {lastModified: 1549958107000}, 39); + upload_opts.progressUpdated(1, {trackingId: "1549958107000"}, 39); assert(width_update_checked); }); @@ -88,7 +88,7 @@ run_test('upload_error', () => { function test(err, msg, server_response = null, file = {}) { setup_test(); - file.lastModified = 1549958107000; + file.trackingId = "1549958107000"; upload_opts.error(err, server_response, file); assert_side_effects(msg); } @@ -174,10 +174,10 @@ run_test('upload_finish', () => { setup(); upload_opts.uploadFinished(i, { - lastModified: 1549958107000, + trackingId: "1549958107000", name: 'some-file', }, response); - upload_opts.progressUpdated(1, {lastModified: 1549958107000}, 100); + upload_opts.progressUpdated(1, {trackingId: "1549958107000"}, 100); assert_side_effects(); } diff --git a/static/js/upload.js b/static/js/upload.js index ea3deeee8c..6713b76e9c 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -68,16 +68,21 @@ exports.options = function (config) { var uploadStarted = function (i, file) { error_msg.html($("
").text(i18n.t("Uploading…"))); - // Here file.lastModified is unique for each upload - // so it is used to track each upload individually + // file.lastModified is unique for each upload, and was previously used to track each + // upload. But, when an image is pasted into Safari, it looks like the lastModified time + // gets changed by the time the image upload is finished, and we lose track of the + // uploaded images. Instead, we set a random ID for each image, to track it. + if (!file.trackingId) { // The conditional check is present to make this easy to test + file.trackingId = Math.random().toString().substring(2); // Use digits after the `.` + } send_status.append('