Index: trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | * @param an UploadInterface object, which contains a .form property which points to a real HTML form in the DOM |
5 | 5 | */ |
6 | 6 | |
7 | | -mw.FirefoggHandler = function( upload ) { |
| 7 | +mw.FirefoggHandler = function( upload, api ) { |
8 | 8 | return this.init( upload ); |
9 | 9 | }; |
10 | 10 | |
— | — | @@ -15,17 +15,17 @@ |
16 | 16 | */ |
17 | 17 | init: function( upload ){ |
18 | 18 | this.upload = upload; |
19 | | - this.api = upload.api; |
| 19 | + this.api = upload.api; |
20 | 20 | // update the mwe-upwiz-file-input target |
21 | | - this.upload.ui.$fileInputCtrl = this.getInputControl() |
| 21 | + this.upload.ui.$fileInputCtrl = this.getInputControl(); |
22 | 22 | this.upload.ui.fileCtrlContainer.empty().append( |
23 | 23 | this.upload.ui.$fileInputCtrl |
24 | | - ) |
| 24 | + ); |
25 | 25 | // update the "valid" extension to include firefogg transcode extensions: |
26 | 26 | mw.UploadWizard.config[ 'fileExtensions' ] = $.merge( |
27 | 27 | mw.UploadWizard.config[ 'fileExtensions' ], |
28 | 28 | mw.UploadWizard.config[ 'transcodeExtensionList' ] |
29 | | - ) |
| 29 | + ); |
30 | 30 | |
31 | 31 | }, |
32 | 32 | // Setup local pointer to firefogg instance |
— | — | @@ -38,14 +38,15 @@ |
39 | 39 | getTransport: function(){ |
40 | 40 | var _this = this; |
41 | 41 | if( !this.transport ){ |
42 | | - this.transport = new mw.FirefoggTransport( |
43 | | - this.getForm(), |
| 42 | + this.transport = new mw.FirefoggTransport( |
| 43 | + this.upload, |
| 44 | + this.api, |
44 | 45 | this.getFogg(), |
45 | 46 | function( fraction ) { |
46 | 47 | _this.upload.setTransportProgress( fraction ); |
47 | 48 | // also update preview video: |
48 | 49 | }, |
49 | | - function( result ) { |
| 50 | + function( result ) { |
50 | 51 | mw.log("FirefoggTransport::getTransport> Transport done " + JSON.stringify( result ) ); |
51 | 52 | _this.upload.setTransported( result ); |
52 | 53 | } |
— | — | @@ -85,12 +86,13 @@ |
86 | 87 | if( _this.getFogg().selectVideo() ) { |
87 | 88 | // Update the value of the input file: |
88 | 89 | $j( this ) |
89 | | - .val( _this.getFogg().sourceFilename ) |
| 90 | + .val( _this.getFogg().sourceFilename ); |
90 | 91 | //.trigger('change'); |
91 | 92 | // note the change trigger does not work because we replace the target: |
92 | 93 | var title = _this.getTransport().getFileName().replace( /:/g, '_' ); |
93 | 94 | _this.upload.title = new mw.Title( title , 'file' ); |
94 | 95 | _this.upload.ui.fileChangedOk(); |
| 96 | + _this.upload.filename = title; |
95 | 97 | } |
96 | 98 | } ); |
97 | 99 | }, |
Index: trunk/extensions/UploadWizard/resources/mw.Firefogg.js |
— | — | @@ -24,5 +24,8 @@ |
25 | 25 | osLink = this.firefoggInstallLinks['win32']; |
26 | 26 | } |
27 | 27 | return osLink; |
| 28 | + }, |
| 29 | + isInstalled: function() { |
| 30 | + return typeof( Firefogg ) != 'undefined' && Firefogg().version >= '2.8.05'; |
28 | 31 | } |
29 | | -}; |
\ No newline at end of file |
| 32 | +}; |
Index: trunk/extensions/UploadWizard/resources/mw.FirefoggTransport.js |
— | — | @@ -1,12 +1,15 @@ |
2 | 2 | /** |
3 | 3 | * Represents a "transport" for files to upload; in this case an firefogg. |
4 | 4 | * |
5 | | - * @param form jQuery selector for HTML form |
| 5 | + * @param upload UploadInterface |
| 6 | + * @param api |
| 7 | + * @param fogg Firefogg instance |
6 | 8 | * @param progressCb callback to execute as the upload progresses |
7 | 9 | * @param transportedCb callback to execute when we've finished the upload |
8 | 10 | */ |
9 | | -mw.FirefoggTransport = function( $form, fogg, progressCb, transportedCb ) { |
10 | | - this.$form = $form; |
| 11 | +mw.FirefoggTransport = function( upload, api, fogg, progressCb, transportedCb ) { |
| 12 | + this.upload = upload; |
| 13 | + this.api = api; |
11 | 14 | this.fogg = fogg; |
12 | 15 | this.progressCb = progressCb; |
13 | 16 | this.transportedCb = transportedCb; |
— | — | @@ -14,26 +17,37 @@ |
15 | 18 | |
16 | 19 | mw.FirefoggTransport.prototype = { |
17 | 20 | |
18 | | - passthrough: false, |
19 | 21 | /** |
20 | | - * Do an upload on a given fogg object: |
| 22 | + * Do an upload |
21 | 23 | */ |
22 | | - doUpload: function(){ |
23 | | - // check if the server supports chunks: |
24 | | - if( this.isChunkUpload() ){ |
25 | | - mw.log("FirefoggTransport::doUpload> Chunks"); |
26 | | - // encode and upload at the same time: |
27 | | - this.doChunkUpload(); |
28 | | - } else { |
29 | | - mw.log("FirefoggTransport::doUpload> Encode then upload"); |
30 | | - this.doEncodeThenUpload(); |
31 | | - } |
| 24 | + doUpload: function() { |
| 25 | + var _this = this; |
| 26 | + //Encode or passthrough Firefogg before upload |
| 27 | + this.fogg.encode( JSON.stringify( this.getEncodeSettings() ), |
| 28 | + function(result, file) { |
| 29 | + result = JSON.parse(result); |
| 30 | + if(result.progress == 1) { //encoding done |
| 31 | + _this.doFormDataUpload(file); |
| 32 | + } else { //encoding failed |
| 33 | + var response = { |
| 34 | + error: { |
| 35 | + code: 500, |
| 36 | + info: 'Encoding failed' |
| 37 | + } |
| 38 | + }; |
| 39 | + _this.transportedCb(response); |
| 40 | + } |
| 41 | + }, function(progress) { //progress |
| 42 | + progress = JSON.parse(progress); |
| 43 | + _this.progressCb( progress.progress ); |
| 44 | + } |
| 45 | + ); |
32 | 46 | }, |
33 | | - isChunkUpload: function(){ |
34 | | - // for now just test post |
35 | | - return false; |
36 | | - return ( mw.UploadWizard.config[ 'enableFirefoggChunkUpload' ] ); |
37 | | - }, |
| 47 | + doFormDataUpload: function(file) { |
| 48 | + this.upload.file = file; |
| 49 | + this.uploadHandler = new mw.ApiUploadFormDataHandler( this.upload, this.api ); |
| 50 | + this.uploadHandler.start(); |
| 51 | + }, |
38 | 52 | /** |
39 | 53 | * Check if the asset should be uploaded in passthrough mode ( or if it should be encoded ) |
40 | 54 | */ |
— | — | @@ -104,10 +118,10 @@ |
105 | 119 | } |
106 | 120 | }, |
107 | 121 | getEncodeExt: function(){ |
108 | | - var encodeSettings = mw.UploadWizard.config[ 'firefoggEncodeSettings']; |
109 | | - if( encodeSettings['videoCodec'] |
| 122 | + var encodeSettings = mw.UploadWizard.config[ 'firefoggEncodeSettings' ]; |
| 123 | + if( encodeSettings[ 'videoCodec' ] |
110 | 124 | && |
111 | | - encodeSettings['videoCodec'] == 'vp8' ) |
| 125 | + encodeSettings[ 'videoCodec' ] == 'vp8' ) |
112 | 126 | { |
113 | 127 | return 'webm'; |
114 | 128 | } else { |
— | — | @@ -123,124 +137,11 @@ |
124 | 138 | return { 'passthrough' : true }; |
125 | 139 | } |
126 | 140 | // Get the default encode settings: |
127 | | - var encodeSettings = mw.UploadWizard.config[ 'firefoggEncodeSettings']; |
| 141 | + var encodeSettings = mw.UploadWizard.config[ 'firefoggEncodeSettings' ]; |
128 | 142 | // Update the format: |
129 | | - this.fogg.setFormat( ( this.getEncodeExt() == 'webm' )? 'webm' : 'ogg' ); |
| 143 | + this.fogg.setFormat( ( this.getEncodeExt() == 'webm' ) ? 'webm' : 'ogg' ); |
130 | 144 | |
131 | 145 | mw.log("FirefoggTransport::getEncodeSettings> " + JSON.stringify( encodeSettings ) ); |
132 | 146 | return encodeSettings; |
133 | 147 | }, |
134 | | - |
135 | | - /** |
136 | | - * Encode then upload |
137 | | - */ |
138 | | - doEncodeThenUpload: function(){ |
139 | | - this.fogg.encode( JSON.stringify( this.getEncodeSettings() ) ); |
140 | | - this.monitorProgress(); |
141 | | - }, |
142 | | - |
143 | | - /** |
144 | | - * Do fogg post |
145 | | - */ |
146 | | - doFoggPost: function(){ |
147 | | - var _this = this; |
148 | | - // Get the upload request with a callback ( populates the request token ) |
149 | | - this.getUploadRequest( function( request ){ |
150 | | - mw.log("FirefoggTransport::doFoggPost> " + _this.getUploadUrl() + ' request:' + |
151 | | - JSON.stringify( request ) ); |
152 | | - |
153 | | - _this.fogg.post( _this.getUploadUrl(), |
154 | | - 'file', |
155 | | - JSON.stringify( request ) |
156 | | - ); |
157 | | - _this.monitorProgress(); |
158 | | - } ); |
159 | | - }, |
160 | | - |
161 | | - /** |
162 | | - * Encode and upload in chunks |
163 | | - */ |
164 | | - doChunkUpload: function(){ |
165 | | - var _this = this; |
166 | | - this.getUploadRequest( function( request ){ |
167 | | - this.fogg.upload( |
168 | | - JSON.stringify( _this.getEncodeSettings() ), |
169 | | - _this.getUploadUrl(), |
170 | | - JSON.stringify( request ) |
171 | | - ); |
172 | | - }); |
173 | | - _this.monitorProgress(); |
174 | | - }, |
175 | | - |
176 | | - /** |
177 | | - * Get the upload url |
178 | | - */ |
179 | | - getUploadUrl: function(){ |
180 | | - return mw.UploadWizard.config['apiUrl']; |
181 | | - }, |
182 | | - |
183 | | - /** |
184 | | - * Get the upload settings |
185 | | - * @param {function} callback function to send the request object |
186 | | - */ |
187 | | - getUploadRequest: function( callback ){ |
188 | | - var _this = this; |
189 | | - // ugly probably would be nice to have base reference to the upload class so we can use the |
190 | | - new mw.Api( { |
191 | | - 'url' : _this.getUploadUrl() |
192 | | - } ) |
193 | | - .getEditToken( function( token ) { |
194 | | - callback( { |
195 | | - 'action' : ( _this.isChunkUpload() )? 'firefoggupload' : 'upload', |
196 | | - 'stash' :1, |
197 | | - 'comment' : 'DUMMY TEXT', |
198 | | - 'format' : 'json', |
199 | | - 'filename' : _this.getFileName(), |
200 | | - 'token' : token |
201 | | - } ); |
202 | | - }, function( code, info ) { |
203 | | - _this.upload.setError( code, info ); |
204 | | - } ); |
205 | | - }, |
206 | | - /** |
207 | | - * Monitor progress on an upload: |
208 | | - */ |
209 | | - monitorProgress: function(){ |
210 | | - var _this = this; |
211 | | - var fogg = this.fogg; |
212 | | - var progress = fogg.progress(); |
213 | | - var state = fogg.state; |
214 | | - |
215 | | - //mw.log("FirefoggTransport::monitorProgress> " + progress + ' state: ' + state + ' status: ' + this.fogg.status() + ' rt: ' + this.getResponseText() ); |
216 | | - this.progressCb( progress ); |
217 | | - |
218 | | - if( state == 'encoding done' && ! this.isChunkUpload() ){ |
219 | | - // ( if encoding done, we are in a two step encode then upload process ) |
220 | | - this.doFoggPost(); |
221 | | - return ; |
222 | | - } |
223 | | - // If state is 'in progress' ... fire monitor progress |
224 | | - if( state == 'encoding' || state == 'uploading' || state == '' ){ |
225 | | - setTimeout( function(){ |
226 | | - _this.monitorProgress(); |
227 | | - }, mw.UploadWizard.config['uploadProgressInterval'] ); |
228 | | - } |
229 | | - // return the api result: |
230 | | - if( state == 'done' || state == 'upload done' ){ |
231 | | - this.transportedCb( JSON.parse( this.getResponseText() ) ); |
232 | | - } |
233 | | - |
234 | | - }, |
235 | | - /** |
236 | | - * Get the response text from a firefogg upload |
237 | | - */ |
238 | | - getResponseText: function(){ |
239 | | - var _this = this; |
240 | | - try { |
241 | | - var pstatus = JSON.parse( _this.fogg.uploadstatus() ); |
242 | | - return pstatus["responseText"]; |
243 | | - } catch( e ) { |
244 | | - mw.log( "Error:: Firefogg could not parse uploadstatus / could not get responseText: " + e ); |
245 | | - } |
246 | | - } |
247 | 148 | }; |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardUpload.js |
— | — | @@ -591,7 +591,7 @@ |
592 | 592 | getUploadHandler: function(){ |
593 | 593 | if( !this.uploadHandler ) { |
594 | 594 | var constructor; // must be the name of a function in 'mw' namespace |
595 | | - if( mw.UploadWizard.config[ 'enableFirefogg' ] && typeof( Firefogg ) != 'undefined' ) { |
| 595 | + if( mw.UploadWizard.config[ 'enableFirefogg' ] && mw.Firefogg.isInstalled() ) { |
596 | 596 | constructor = 'FirefoggHandler'; |
597 | 597 | } else if( mw.UploadWizard.config[ 'enableFormData' ] && mw.fileApi.isSliceAvailable()) { |
598 | 598 | constructor = 'ApiUploadFormDataHandler'; |