Revert "DEV: Improve uppy plugin base and large file handling (#14383)" (#14387)

Revert “DEV: Improve uppy plugin base and large file handling (#14383)” (#14387)

This reverts commit 36bd6e8c3bccbcdb79cc96934475025b46e4c9b7.

diff --git a/app/assets/javascripts/discourse/app/lib/uppy-checksum-plugin.js b/app/assets/javascripts/discourse/app/lib/uppy-checksum-plugin.js
index 977a016..ec73104 100644
--- a/app/assets/javascripts/discourse/app/lib/uppy-checksum-plugin.js
+++ b/app/assets/javascripts/discourse/app/lib/uppy-checksum-plugin.js
@@ -1,6 +1,5 @@
 import { UploadPreProcessorPlugin } from "discourse/lib/uppy-plugin-base";
 import { Promise } from "rsvp";
-import { HUGE_FILE_THRESHOLD_BYTES } from "discourse/mixins/uppy-upload";
 
 export default class UppyChecksum extends UploadPreProcessorPlugin {
   static pluginId = "uppy-checksum";
@@ -35,19 +34,13 @@ export default class UppyChecksum extends UploadPreProcessorPlugin {
 
   _generateChecksum(fileIds) {
     if (!this._canUseSubtleCrypto()) {
-      return this._skipAll(fileIds, true);
+      return Promise.resolve();
     }
 
     let promises = fileIds.map((fileId) => {
       let file = this._getFile(fileId);
-      this._emitProgress(file);
 
-      if (file.size > HUGE_FILE_THRESHOLD_BYTES) {
-        this._consoleWarn(
-          "The file provided is too large to checksum, skipping."
-        );
-        return this._skip(file);
-      }
+      this._emitProgress(file);
 
       return file.data.arrayBuffer().then((arrayBuffer) => {
         return window.crypto.subtle
diff --git a/app/assets/javascripts/discourse/app/lib/uppy-media-optimization-plugin.js b/app/assets/javascripts/discourse/app/lib/uppy-media-optimization-plugin.js
index 15ba5aa..4a00374 100644
--- a/app/assets/javascripts/discourse/app/lib/uppy-media-optimization-plugin.js
+++ b/app/assets/javascripts/discourse/app/lib/uppy-media-optimization-plugin.js
@@ -22,19 +22,17 @@ export default class UppyMediaOptimization extends UploadPreProcessorPlugin {
 
     return this.optimizeFn(file, { stopWorkerOnError: !this.runParallel })
       .then((optimizedFile) => {
-        let skipped = false;
         if (!optimizedFile) {
           this._consoleWarn(
-            "Nothing happened, possible error or other restriction, or the file format is not a valid one for compression."
+            "Nothing happened, possible error or other restriction."
           );
-          skipped = true;
         } else {
           this._setFileState(fileId, {
             data: optimizedFile,
             size: optimizedFile.size,
           });
         }
-        this._emitComplete(file, skipped);
+        this._emitComplete(file);
       })
       .catch((err) => {
         this._consoleWarn(err);
diff --git a/app/assets/javascripts/discourse/app/lib/uppy-plugin-base.js b/app/assets/javascripts/discourse/app/lib/uppy-plugin-base.js
index f4f8b55..34eddeb 100644
--- a/app/assets/javascripts/discourse/app/lib/uppy-plugin-base.js
+++ b/app/assets/javascripts/discourse/app/lib/uppy-plugin-base.js
@@ -1,6 +1,5 @@
 import { BasePlugin } from "@uppy/core";
-import { Promise } from "rsvp";
-import { debug, warn } from "@ember/debug";
+import { warn } from "@ember/debug";
 
 export class UppyPluginBase extends BasePlugin {
   constructor(uppy, opts) {
@@ -9,13 +8,7 @@ export class UppyPluginBase extends BasePlugin {
   }
 
   _consoleWarn(msg) {
-    warn(`[${this.id}] ${msg}`, { id: `discourse.${this.id}` });
-  }
-
-  _consoleDebug(msg) {
-    if (this.siteSettings?.enable_upload_debug_mode) {
-      debug(`[${this.id}] ${msg}`, { id: `discourse.${this.id}` });
-    }
+    warn(msg, { id: `discourse.${this.id}` });
   }
 
   _getFile(fileId) {
@@ -48,36 +41,10 @@ export class UploadPreProcessorPlugin extends UppyPluginBase {
   }
 
   _emitProgress(file) {
-    this.uppy.emit("preprocess-progress", file, null, this.id);
-  }
-
-  _emitComplete(file, skipped = false) {
-    this.uppy.emit("preprocess-complete", file, skipped, this.id);
-    return Promise.resolve();
-  }
-
-  _emitAllComplete(fileIds, skipped = false) {
-    fileIds.forEach((fileId) => {
-      let file = this._getFile(fileId);
-      this._emitComplete(file, skipped);
-    });
-    return Promise.resolve();
-  }
-
-  _emitError(file, errorMessage) {
-    // the error message is stored twice; once to show in a displayErrorForUpload
-    // modal, and on the .message property to show in the uppy logs
-    this.uppy.emit("upload-error", file, {
-      errors: [errorMessage],
-      message: `[${this.id}] ${errorMessage}`,
-    });
-  }
-
-  _skip(file) {
-    return this._emitComplete(file, true);
+    this.uppy.emit("preprocess-progress", this.id, file);
   }
 
-  _skipAll(file) {
-    return this._emitAllComplete(file, true);
+  _emitComplete(file) {
+    this.uppy.emit("preprocess-complete", this.id, file);
   }
 }
diff --git a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js
index efbb0c7..6bbbe65 100644
--- a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js
+++ b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js
@@ -382,8 +382,6 @@ export default Mixin.create(ExtendableUploader, {
       limit: 10,
 
       createMultipartUpload(file) {
-        self._uppyInstance.emit("create-multipart", file.id);
-
         const data = {
           file_name: file.name,
           file_size: file.size,
@@ -404,8 +402,6 @@ export default Mixin.create(ExtendableUploader, {
           data,
           // uppy is inconsistent, an error here fires the upload-error event
         }).then((responseData) => {
-          self._uppyInstance.emit("create-multipart-success", file.id);
-
           file.meta.unique_identifier = responseData.unique_identifier;
           return {
             uploadId: responseData.external_upload_identifier,
@@ -434,7 +430,6 @@ export default Mixin.create(ExtendableUploader, {
       },
 
       completeMultipartUpload(file, data) {
-        self._uppyInstance.emit("complete-multipart", file.id);
         const parts = data.parts.map((part) => {
           return { part_number: part.PartNumber, etag: part.ETag };
         });
@@ -447,7 +442,6 @@ export default Mixin.create(ExtendableUploader, {
           }),
           // uppy is inconsistent, an error here fires the upload-error event
         }).then((responseData) => {
-          self._uppyInstance.emit("complete-multipart-success", file.id);
           return responseData;
         });
       },
@@ -562,4 +556,11 @@ export default Mixin.create(ExtendableUploader, {
   showUploadSelector(toolbarEvent) {
     this.send("showUploadSelector", toolbarEvent);
   },
+
+  _debugLog(message) {
+    if (this.siteSettings.enable_upload_debug_mode) {
+      // eslint-disable-next-line no-console
+      console.log(message);
+    }
+  },
 });
diff --git a/app/assets/javascripts/discourse/app/mixins/extendable-uploader.js b/app/assets/javascripts/discourse/app/mixins/extendable-uploader.js
index 11e1e69..120abb1 100644
--- a/app/assets/javascripts/discourse/app/mixins/extendable-uploader.js
+++ b/app/assets/javascripts/discourse/app/mixins/extendable-uploader.js
@@ -1,5 +1,4 @@
 import Mixin from "@ember/object/mixin";
-import { debug } from "@ember/debug";
 
 /**
  * Use this mixin with any component that needs to upload files or images
@@ -81,10 +80,8 @@ export default Mixin.create({
   //
   // See: https://uppy.io/docs/writing-plugins/#Progress-events
   _onPreProcessProgress(callback) {
-    this._uppyInstance.on("preprocess-progress", (file, progress, pluginId) => {
-      this._consoleDebug(
-        `[${pluginId}] processing file ${file.name} (${file.id})`
-      );
+    this._uppyInstance.on("preprocess-progress", (pluginId, file) => {
+      this._debugLog(`[${pluginId}] processing file ${file.name} (${file.id})`);
 
       this._preProcessorStatus[pluginId].activeProcessing++;
 
@@ -93,18 +90,16 @@ export default Mixin.create({
   },
 
   _onPreProcessComplete(callback, allCompleteCallback) {
-    this._uppyInstance.on("preprocess-complete", (file, skipped, pluginId) => {
-      this._consoleDebug(

[... diff too long, it was truncated ...]

GitHub sha: 5fb45e712f3b8382a38f6887b0d0fd9a5a1b9d53

This commit appears in #14387 which was approved by tgxworld. It was merged by martin.