77 */
88
99var filed = require ( 'filed' ) ,
10- mime = require ( 'mime' ) ,
11- base = require ( '../../../core/storage' ) ,
12- through = require ( 'through2' ) ,
13- _ = require ( 'underscore' ) ,
14- urlJoin = require ( 'url-join' ) ;
10+ mime = require ( 'mime' ) ,
11+ base = require ( '../../../core/storage' ) ,
12+ through = require ( 'through2' ) ,
13+ _ = require ( 'underscore' ) ,
14+ urlJoin = require ( 'url-join' ) ;
1515
1616/**
1717 * client.removeFile
@@ -24,13 +24,13 @@ var filed = require('filed'),
2424 */
2525exports . removeFile = function ( container , file , callback ) {
2626 var containerName = container instanceof this . models . Container ? container . name : container ,
27- fileName = file instanceof this . models . File ? file . name : file ;
27+ fileName = file instanceof this . models . File ? file . name : file ;
2828
2929 this . _request ( {
3030 method : 'DELETE' ,
3131 container : containerName ,
3232 path : fileName
33- } , function ( err ) {
33+ } , function ( err ) {
3434 return err
3535 ? callback ( err )
3636 : callback ( null , true ) ;
@@ -47,12 +47,12 @@ exports.removeFile = function (container, file, callback) {
4747 * @param {array } files the files or fileNames to delete
4848 * @param callback
4949 */
50- exports . bulkDelete = function ( container , files , callback ) {
50+ exports . bulkDelete = function ( container , files , callback ) {
5151 var self = this ,
52- containerName = container instanceof this . models . Container ? container . name : container ;
52+ containerName = container instanceof this . models . Container ? container . name : container ;
5353 this . _request ( {
5454 method : 'DELETE' ,
55- body : files . map ( function ( file ) {
55+ body : files . map ( function ( file ) {
5656 return urlJoin ( containerName , ( file instanceof self . models . File ? file . name : file ) ) ;
5757 } ) . join ( '\r\n' ) ,
5858 headers : {
@@ -61,7 +61,7 @@ exports.bulkDelete = function(container, files, callback) {
6161 qs : {
6262 'bulk-delete' : true
6363 }
64- } , function ( err , results ) {
64+ } , function ( err , results ) {
6565 return err
6666 ? callback ( err )
6767 : callback ( null , results ) ;
@@ -95,15 +95,15 @@ exports.upload = function (options) {
9595 }
9696
9797 var container = options . container ,
98- writableStream ,
99- proxyStream = through ( ) ,
100- uploadOptions = {
101- method : 'PUT' ,
102- upload : true ,
103- container : container ,
104- path : options . remote ,
105- headers : options . headers || { }
106- } ;
98+ writableStream ,
99+ proxyStream = through ( ) ,
100+ uploadOptions = {
101+ method : 'PUT' ,
102+ upload : true ,
103+ container : container ,
104+ path : options . remote ,
105+ headers : options . headers || { }
106+ } ;
107107
108108 if ( options . container instanceof this . models . Container ) {
109109 uploadOptions . container = options . container . name ;
@@ -123,7 +123,7 @@ exports.upload = function (options) {
123123
124124 writableStream = this . _request ( uploadOptions ) ;
125125
126- writableStream . on ( 'complete' , function ( response ) {
126+ writableStream . on ( 'complete' , function ( response ) {
127127 var err = self . _parseError ( response ) ;
128128
129129 if ( err ) {
@@ -175,19 +175,19 @@ exports.upload = function (options) {
175175 */
176176exports . download = function ( options , callback ) {
177177 var self = this ,
178- container = options . container ,
179- inputStream ,
180- apiStream ;
178+ container = options . container ,
179+ inputStream ,
180+ apiStream ;
181181
182182 var success = ! callback ? null : function ( err , body , res ) {
183183 return err
184184 ? callback ( err )
185185 : callback ( null , new self . models . File ( self , _ . extend ( res . headers , {
186- container : options . container ,
187- name : options . remote
188- } ) ) ) ;
186+ container : options . container ,
187+ name : options . remote
188+ } ) ) ) ;
189189 } ;
190-
190+
191191 if ( container instanceof self . models . Container ) {
192192 container = container . name ;
193193 }
@@ -223,7 +223,7 @@ exports.download = function (options, callback) {
223223 */
224224exports . getFile = function ( container , file , callback ) {
225225 var containerName = container instanceof this . models . Container ? container . name : container ,
226- self = this ;
226+ self = this ;
227227
228228 this . _request ( {
229229 method : 'HEAD' ,
@@ -236,9 +236,9 @@ exports.getFile = function (container, file, callback) {
236236 return err
237237 ? callback ( err )
238238 : callback ( null , new self . models . File ( self , _ . extend ( res . headers , {
239- container : container ,
240- name : file
241- } ) ) ) ;
239+ container : container ,
240+ name : file
241+ } ) ) ) ;
242242 } ) ;
243243} ;
244244
@@ -277,7 +277,7 @@ exports.getFiles = function (container, options, callback) {
277277 var remainingLimit = options . limit ;
278278 delete options . limit ;
279279
280- var getFilesCallback = function ( err , someFiles ) {
280+ var getFilesCallback = function ( err , someFiles ) {
281281 if ( err ) {
282282 return callback ( err ) ;
283283 }
@@ -305,33 +305,33 @@ exports.getFiles = function (container, options, callback) {
305305
306306exports . _getFiles = function ( container , options , callback ) {
307307 var containerName = container instanceof this . models . Container ? container . name : container ,
308- self = this ;
308+ self = this ;
309309
310310 var getFilesOpts = {
311- path : containerName ,
312- qs : _ . extend ( {
313- format : 'json'
314- } , _ . pick ( options , [ 'limit' , 'marker' , 'prefix' , 'path' , 'delimiter' ] ) )
315- } ;
311+ path : containerName ,
312+ qs : _ . extend ( {
313+ format : 'json'
314+ } , _ . pick ( options , [ 'limit' , 'marker' , 'prefix' , 'path' , 'delimiter' ] ) )
315+ } ;
316316
317- if ( options . endMarker ) {
318- getFilesOpts . qs . end_marker = options . endMarker ;
319- }
317+ if ( options . endMarker ) {
318+ getFilesOpts . qs . end_marker = options . endMarker ;
319+ }
320320
321321 if ( options . end_marker ) {
322322 getFilesOpts . qs . end_marker = options . end_marker ;
323323 }
324324
325325 if ( options . prefix ) {
326- getFilesOpts . qs . prefix = options . prefix ;
326+ getFilesOpts . qs . prefix = options . prefix ;
327327 }
328328
329329 if ( options . path ) {
330- getFilesOpts . qs . path = options . path ;
330+ getFilesOpts . qs . path = options . path ;
331331 }
332332
333333 if ( options . delimiter ) {
334- getFilesOpts . qs . delimiter = options . delimiter ;
334+ getFilesOpts . qs . delimiter = options . delimiter ;
335335 }
336336
337337 this . _request ( getFilesOpts , function ( err , body ) {
@@ -362,7 +362,7 @@ exports._getFiles = function (container, options, callback) {
362362 */
363363exports . updateFileMetadata = function ( container , file , callback ) {
364364 var self = this ,
365- containerName = container instanceof self . models . Container ? container . name : container ;
365+ containerName = container instanceof self . models . Container ? container . name : container ;
366366
367367 if ( ! file instanceof base . File ) {
368368 throw new Error ( 'Must update an existing file instance' ) ;
@@ -396,27 +396,27 @@ exports.updateFileMetadata = function (container, file, callback) {
396396 * @param callback
397397 */
398398exports . copy = function ( options , callback ) {
399- var self = this ,
400- containerName = options . sourceContainer instanceof self . models . Container ? options . sourceContainer . name : options . sourceContainer ,
401- destContainerName = options . destinationContainer instanceof self . models . Container ? options . destinationContainer . name : options . destinationContainer ,
402- destinationFile = options . destinationFile || options . sourceFile ;
403-
404- var copyOptions = {
405- method : 'COPY' ,
406- uri : options . sourceFile instanceof self . models . File ? options . sourceFile . fullPath : this . _getUrl ( {
407- container : containerName ,
408- path : options . sourceFile
409- } ) ,
410- headers : _ . extend ( options . headers || { } , {
411- destination : urlJoin ( '/' , destContainerName ,
412- destinationFile instanceof self . models . File ? destinationFile . name : destinationFile )
413- } )
414- } ;
415-
416- this . _request ( copyOptions , function ( err ) {
417- return err
418- ? callback ( err )
419- : callback ( null , true ) ;
420- } ) ;
399+ var self = this ,
400+ containerName = options . sourceContainer instanceof self . models . Container ? options . sourceContainer . name : options . sourceContainer ,
401+ destContainerName = options . destinationContainer instanceof self . models . Container ? options . destinationContainer . name : options . destinationContainer ,
402+ destinationFile = options . destinationFile || options . sourceFile ;
403+
404+ var copyOptions = {
405+ method : 'COPY' ,
406+ uri : options . sourceFile instanceof self . models . File ? options . sourceFile . fullPath : this . _getUrl ( {
407+ container : containerName ,
408+ path : options . sourceFile
409+ } ) ,
410+ headers : _ . extend ( options . headers || { } , {
411+ destination : urlJoin ( '/' , destContainerName ,
412+ destinationFile instanceof self . models . File ? destinationFile . name : destinationFile )
413+ } )
414+ } ;
415+
416+ this . _request ( copyOptions , function ( err ) {
417+ return err
418+ ? callback ( err )
419+ : callback ( null , true ) ;
420+ } ) ;
421421} ;
422422
0 commit comments