};
/**
- * @private
* Get nonce for iframe IDs on the page.
*
+ * @private
* @return {number}
*/
function getNonce() {
}
/**
- * @private
* Given a non-empty object, return one of its keys.
*
+ * @private
* @param {Object} obj
* @return {string}
*/
}
/**
- * @private
* Get new iframe object for an upload.
*
+ * @private
* @return {HTMLIframeElement}
*/
function getNewIframe( id ) {
}
/**
- * @private
* Shortcut for getting hidden inputs
*
+ * @private
* @return {jQuery}
*/
function getHiddenInput( name, val ) {
deferred.reject( 'ok-but-empty', 'No response from API on upload attempt.' );
} else if ( result.error ) {
if ( result.error.code === 'badtoken' ) {
- api.badToken( 'edit' );
+ api.badToken( 'csrf' );
}
deferred.reject( result.error.code, result );
}
function finishUpload( moreData ) {
- data = $.extend( data, moreData );
- data.filekey = filekey;
- data.action = 'upload';
- data.format = 'json';
-
- if ( !data.filename ) {
- throw new Error( 'Filename not included in file data.' );
- }
-
- return api.postWithEditToken( data ).then( function ( result ) {
- if ( result.upload && result.upload.warnings ) {
- return $.Deferred().reject( getFirstKey( result.upload.warnings ), result ).promise();
- }
- return result;
- } );
+ return api.uploadFromStash( filekey, $.extend( data, moreData ) );
}
return this.upload( file, { stash: true, filename: data.filename } ).then(
);
},
+ /**
+ * Finish an upload in the stash.
+ *
+ * @param {string} filekey
+ * @param {Object} data
+ */
+ uploadFromStash: function ( filekey, data ) {
+ data.filekey = filekey;
+ data.action = 'upload';
+ data.format = 'json';
+
+ if ( !data.filename ) {
+ throw new Error( 'Filename not included in file data.' );
+ }
+
+ return this.postWithEditToken( data ).then( function ( result ) {
+ if ( result.upload && result.upload.warnings ) {
+ return $.Deferred().reject( getFirstKey( result.upload.warnings ), result ).promise();
+ }
+ return result;
+ } );
+ },
+
needToken: function () {
return true;
}