]> git.p6c8.net - jirafeau_project.git/commitdiff
[BUGFIX] Catch errors in upload form
authorDan Untenzu <untenzu@webit.de>
Fri, 27 Jan 2017 09:23:50 +0000 (10:23 +0100)
committerJerome Jutteau <jerome.jutteau@outscale.com>
Thu, 23 Feb 2017 17:34:20 +0000 (18:34 +0100)
The upload forms failed to catch errors due to a
never matching condition. Failing uploads (eg. because of
filesize limit etc.) still tried to render non-existing
download links instead of showing the error.

Fix the condition by testing if the return string
starts with "Error" instead of equals "Error".

Refs #96

lib/functions.js.php

index dab491c0377eb7dc3c2f780f167f81493db27ee2..989b7884afad87f33641fc63baf20ec48886ccc4 100644 (file)
@@ -259,11 +259,14 @@ function classic_upload (url, file, time, password, one_time, upload_password)
         if (req.readyState == 4 && req.status == 200)
         {
             var res = req.responseText;
-            if (res == "Error")
+
+            // if response starts with "Error" then show a failure
+            if (/^Error/.test(res))
             {
-                pop_failure ();
+                pop_failure (res);
                 return;
             }
+
             res = res.split ("\n");
             if (time != 'none')
             {
@@ -321,11 +324,13 @@ function async_upload_start (url, max_size, file, time, password, one_time, uplo
         if (req.readyState == 4 && req.status == 200)
         {
             var res = req.responseText;
-            if (res == "Error")
+
+            if (/^Error/.test(res))
             {
-                pop_failure ();
+                pop_failure (res);
                 return;
             }
+
             res = res.split ("\n");
             async_global_ref = res[0];
             var code = res[1];
@@ -390,11 +395,13 @@ function async_upload_push (code)
         if (req.readyState == 4 && req.status == 200)
         {
             var res = req.responseText;
-            if (res == "Error")
+
+            if (/^Error/.test(res))
             {
-                pop_failure ();
+                pop_failure (res);
                 return;
             }
+
             res = res.split ("\n");
             var code = res[0]
             async_global_transfered = async_global_transfering;
@@ -428,11 +435,13 @@ function async_upload_end (code)
         if (req.readyState == 4 && req.status == 200)
         {
             var res = req.responseText;
-            if (res == "Error")
+
+            if (/^Error/.test(res))
             {
-                pop_failure ();
+                pop_failure (res);
                 return;
             }
+
             res = res.split ("\n");
             if (async_global_time != 'none')
             {

patrick-canterino.de