@@ -3,6 +3,7 @@ import url from 'url';
3
3
import mime from 'mime' ;
4
4
import download from 'download-file' ;
5
5
import Future from 'fibers/future' ;
6
+ import celery from 'node-celery' ;
6
7
7
8
Meteor . methods ( {
8
9
uploadFromUrl : function ( link ) {
@@ -83,18 +84,52 @@ Meteor.methods({
83
84
}
84
85
} ) ;
85
86
86
- // TODO: call celery
87
+ const client = celery . createClient ( {
88
+ CELERY_BROKER_URL : Meteor . settings . broker ,
89
+ CELERY_RESULT_BACKEND : 'amqp'
90
+ } ) ;
91
+
92
+ client . on ( 'error' , err => {
93
+ console . log ( err ) ;
94
+ } ) ;
95
+
96
+ client . on ( 'connect' , Meteor . bindEnvironment ( ( ) => {
97
+ const inputPath = `/data${ file . path } ` ;
98
+
99
+ client . call ( 'core.process_file' , [ file . isVideo , inputPath , outputFormat ] , Meteor . bindEnvironment ( outputPath => {
100
+ client . end ( ) ;
101
+
102
+ if ( fs . existsSync ( inputPath ) ) {
103
+ fs . unlinkSync ( inputPath ) ;
104
+ }
105
+
106
+ if ( fs . existsSync ( outputPath ) ) {
107
+ const newPath = outputPath . replace ( '/tmp' , '' ) ;
108
+ fs . renameSync ( outputPath , newPath ) ;
109
+ }
110
+
111
+ console . log ( 'outputPath:' , outputPath ) ;
112
+
113
+ Collection . Files . update ( fileId , {
114
+ $set : {
115
+ status : 'converted'
116
+ }
117
+ } ) ;
118
+
119
+ Meteor . users . update ( Meteor . userId ( ) , {
120
+ $inc : {
121
+ 'profile.diskUsage' : - size
122
+ }
123
+ } ) ;
124
+ } ) ) ;
125
+ } ) ) ;
87
126
} ,
88
127
deleteFile : ( fileId ) => {
89
128
const file = getFile ( fileId ) ;
90
129
const filePath = Meteor . settings . data + file . path ;
91
130
92
131
if ( fs . existsSync ( filePath ) ) {
93
- fs . unlink ( filePath , error => {
94
- if ( error ) {
95
- throw new Meteor . Error ( error . toString ( ) ) ;
96
- }
97
- } ) ;
132
+ fs . unlinkSync ( filePath ) ;
98
133
}
99
134
100
135
const size = file . size ;
0 commit comments