Index: trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js |
— | — | @@ -14,13 +14,18 @@ |
15 | 15 | * Constructor |
16 | 16 | */ |
17 | 17 | init: function( upload ){ |
| 18 | + var _this = this; |
18 | 19 | this.upload = upload; |
19 | 20 | this.api = upload.api; |
20 | | - // update the mwe-upwiz-file-input target |
21 | | - this.upload.ui.$fileInputCtrl = this.getInputControl(); |
22 | | - this.upload.ui.fileCtrlContainer.empty().append( |
23 | | - this.upload.ui.$fileInputCtrl |
24 | | - ); |
| 21 | + // pass file to Firefogg after selection |
| 22 | + this.upload.ui.$fileInputCtrl.bind('change', function(event) { |
| 23 | + if(_this.upload.ui.$fileInputCtrl[0].files.length) { |
| 24 | + _this.getFogg().setInput(_this.upload.ui.$fileInputCtrl[0].files[0]); |
| 25 | + //This is required to get the right requestedTitle in UploadWizardUpload |
| 26 | + var title = _this.getTransport().getFileName().replace( /:/g, '_' ); |
| 27 | + _this.upload.title = new mw.Title( title , 'file' ); |
| 28 | + } |
| 29 | + }); |
25 | 30 | // update the "valid" extension to include firefogg transcode extensions: |
26 | 31 | mw.UploadWizard.config[ 'fileExtensions' ] = $.merge( |
27 | 32 | mw.UploadWizard.config[ 'fileExtensions' ], |
— | — | @@ -39,12 +44,12 @@ |
40 | 45 | var _this = this; |
41 | 46 | if( !this.transport ){ |
42 | 47 | this.transport = new mw.FirefoggTransport( |
43 | | - this.upload, |
44 | | - this.api, |
| 48 | + this.upload, |
| 49 | + this.api, |
45 | 50 | this.getFogg(), |
46 | | - function( fraction ) { |
47 | | - _this.upload.setTransportProgress( fraction ); |
48 | | - // also update preview video: |
| 51 | + function( data ) { |
| 52 | + _this.upload.setTransportProgress( data.progress ); |
| 53 | + // also update preview video, url is in data.preview |
49 | 54 | }, |
50 | 55 | function( result ) { |
51 | 56 | mw.log("FirefoggTransport::getTransport> Transport done " + JSON.stringify( result ) ); |
— | — | @@ -54,50 +59,8 @@ |
55 | 60 | } |
56 | 61 | return this.transport; |
57 | 62 | }, |
58 | | - isGoodExtension: function( ext ){ |
59 | | - // First check if its an oky extension for the wiki: |
60 | | - if( $j.inArray( ext.toLowerCase(), mw.UploadWizard.config[ 'fileExtensions' ] ) !== -1 ){ |
61 | | - return true; |
62 | | - } |
63 | | - // Check if its a file that can be transcoded: |
64 | | - if( this.getTransport().isSourceAudio() || this.getTransport().isSourceVideo() ){ |
65 | | - return true; |
66 | | - } |
67 | | - // file can't be transcoded |
68 | | - return false; |
69 | | - }, |
70 | 63 | |
71 | | - getForm: function(){ |
72 | | - return $j( this.upload.ui.form ); |
73 | | - }, |
74 | | - |
75 | 64 | /** |
76 | | - * Get a pointer to the "file" input control |
77 | | - */ |
78 | | - getInputControl: function(){ |
79 | | - var _this = this; |
80 | | - return $j('<input />').attr({ |
81 | | - 'size': "1", |
82 | | - 'name': "file", |
83 | | - 'type': "text" |
84 | | - }) |
85 | | - .addClass( "mwe-upwiz-file-input" ) |
86 | | - .click( function() { |
87 | | - if( _this.getFogg().selectVideo() ) { |
88 | | - // Update the value of the input file: |
89 | | - $j( this ) |
90 | | - .val( _this.getFogg().sourceFilename ); |
91 | | - //.trigger('change'); |
92 | | - // note the change trigger does not work because we replace the target: |
93 | | - var title = _this.getTransport().getFileName().replace( /:/g, '_' ); |
94 | | - _this.upload.title = new mw.Title( title , 'file' ); |
95 | | - _this.upload.ui.fileChangedOk(); |
96 | | - _this.upload.filename = title; |
97 | | - } |
98 | | - } ); |
99 | | - }, |
100 | | - |
101 | | - /** |
102 | 65 | * If chunks are disabled transcode then upload else |
103 | 66 | * upload and transcode at the same time |
104 | 67 | */ |
Index: trunk/extensions/UploadWizard/resources/mw.FirefoggTransport.js |
— | — | @@ -23,25 +23,29 @@ |
24 | 24 | doUpload: function() { |
25 | 25 | var _this = this; |
26 | 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); |
| 27 | + if (this.isUploadFormat()) { |
| 28 | + _this.doFormDataUpload(this.upload.ui.$fileInputCtrl[0].files[0]); |
| 29 | + } else { |
| 30 | + this.fogg.encode( JSON.stringify( this.getEncodeSettings() ), |
| 31 | + function(result, file) { |
| 32 | + result = JSON.parse(result); |
| 33 | + if(result.progress == 1) { //encoding done |
| 34 | + _this.doFormDataUpload(file); |
| 35 | + } else { //encoding failed |
| 36 | + var response = { |
| 37 | + error: { |
| 38 | + code: 500, |
| 39 | + info: 'Encoding failed' |
| 40 | + } |
| 41 | + }; |
| 42 | + _this.transportedCb(response); |
| 43 | + } |
| 44 | + }, function(progress) { //progress |
| 45 | + progress = JSON.parse(progress); |
| 46 | + _this.progressCb( progress ); |
40 | 47 | } |
41 | | - }, function(progress) { //progress |
42 | | - progress = JSON.parse(progress); |
43 | | - _this.progressCb( progress.progress ); |
44 | | - } |
45 | | - ); |
| 48 | + ); |
| 49 | + } |
46 | 50 | }, |
47 | 51 | doFormDataUpload: function(file) { |
48 | 52 | this.upload.file = file; |
— | — | @@ -49,9 +53,9 @@ |
50 | 54 | this.uploadHandler.start(); |
51 | 55 | }, |
52 | 56 | /** |
53 | | - * Check if the asset should be uploaded in passthrough mode ( or if it should be encoded ) |
| 57 | + * Check if the asset is in a format that can be upload without encoding. |
54 | 58 | */ |
55 | | - isPassThrough: function(){ |
| 59 | + isUploadFormat: function(){ |
56 | 60 | // Check if the server supports webm uploads: |
57 | 61 | var wembExt = ( $j.inArray( 'webm', mw.UploadWizard.config[ 'fileExtensions'] ) !== -1 ) |
58 | 62 | // Determine passthrough mode |
— | — | @@ -104,8 +108,8 @@ |
105 | 109 | |
106 | 110 | // Get the filename |
107 | 111 | getFileName: function(){ |
108 | | - // If passthrough don't change it |
109 | | - if( this.isPassThrough() ){ |
| 112 | + // If file is in a supported format don't change extension |
| 113 | + if( this.isUploadFormat() ){ |
110 | 114 | return this.fogg.sourceFilename; |
111 | 115 | } else { |
112 | 116 | if( this.isSourceAudio() ){ |
— | — | @@ -133,7 +137,7 @@ |
134 | 138 | * Get the encode settings from configuration and the current selected video type |
135 | 139 | */ |
136 | 140 | getEncodeSettings: function(){ |
137 | | - if( this.isPassThrough() ){ |
| 141 | + if( this.isUploadFormat() ){ |
138 | 142 | return { 'passthrough' : true }; |
139 | 143 | } |
140 | 144 | // Get the default encode settings: |