Don't allow completing a partial stash upload
authorMatthias Mullie <git@mullie.eu>
Wed, 15 May 2019 07:13:15 +0000 (09:13 +0200)
committerMatthias Mullie <git@mullie.eu>
Wed, 15 May 2019 07:13:16 +0000 (09:13 +0200)
finishUploadToStash could be called on an incomplete upload.
E.g. upload 1 chunk (that gets you the filekey) and then call
finishUploadToStash's finishUpload.

This adds another check for the stash result. The result will
only be 'Success' if all chunks have been submitted (or when
the file was uploaded as a whole, not chunked)
If we're still missing some chunks, result will be 'Continue'.

Bug: T190988
Change-Id: Ia0a4df0306b3e0cc0f2453f986b73bedd88241d3

resources/src/mediawiki.api/upload.js

index 619dd7c..fe21f07 100644 (file)
                                        return finishUpload;
                                },
                                function ( errorCode, result ) {
-                                       if ( result && result.upload && result.upload.filekey ) {
-                                               // Ignore any warnings if 'filekey' was returned, that's all we care about
+                                       if ( result && result.upload && result.upload.result === 'Success' && result.upload.filekey ) {
+                                               // Catch handler is also called in case of warnings (e.g. 'duplicate')
+                                               // We don't really care about those warnings, as long as the upload got stashed...
                                                filekey = result.upload.filekey;
                                                return $.Deferred().resolve( finishUpload );
                                        }