-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Array of ParseFiles #65
base: master
Are you sure you want to change the base?
Changes from all commits
7e11388
c4b8c81
6bca501
e59341b
14b325d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ function _processFiles(files, handler) { | |
var asyncLimit = config.asyncLimit || 5; | ||
return new Promise(function(resolve, reject) { | ||
async.eachOfLimit(files, asyncLimit, function(file, index, callback) { | ||
process.stdout.write('Processing '+(index+1)+'/'+files.length+'\r'); | ||
process.stdout.write('Processing '+(index+1)+'/'+files.length+'\r'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops! |
||
file.newFileName = _createNewFileName(file.fileName); | ||
if (_shouldTransferFile(file)) { | ||
_transferFile(file).then(callback, callback); | ||
|
@@ -156,18 +156,72 @@ function _changeDBFileField(file) { | |
if (file.fileName == file.newFileName || !config.renameInDatabase) { | ||
return resolve(); | ||
} | ||
|
||
if (config.transferTo === 'filesystem'){ | ||
var _path = config.filesAdapter._filesDir + "/" + file.newFileName; | ||
} else if (config.transferTo === 's3'){ | ||
var _path = "https://" + config.filesAdapter._bucket + "." + config.filesAdapter._s3Client.config.endpoint + "/" + config.filesAdapter._bucketPrefix + file.newFileName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there should be |
||
} | ||
|
||
var update = {$set:{}}; | ||
update.$set[file.fieldName] = file.newFileName; | ||
db.collection(file.className).update( | ||
{ _id : file.objectId }, | ||
update, | ||
function(error, result ) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
|
||
if ((config.extraFields[file.className] != undefined) && (config.extraFields[file.className].indexOf(file.fieldName) != -1)) { | ||
|
||
if (file.type === 'string') { | ||
update.$set[file.fieldName] = _path; | ||
db.collection(file.className).update( | ||
{ _id : file.objectId }, | ||
update, | ||
function(error, result) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
} | ||
) | ||
} else { | ||
db.collection(file.className).findOne({_id: file.objectId}).then(function(result){ | ||
var images = result[file.fieldName]; | ||
|
||
images[file.i] = { | ||
__type: 'File', | ||
name: file.newFileName, | ||
url: _path | ||
}; | ||
|
||
update.$set[file.fieldName] = images; | ||
db.collection(file.className).update( | ||
{ _id : file.objectId }, | ||
update, | ||
function(error, result) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
); | ||
|
||
} else { | ||
|
||
update.$set[file.fieldName] = { | ||
__type: 'File', | ||
name: file.newFileName, | ||
url: _path | ||
}; | ||
|
||
db.collection(file.className).update( | ||
{ _id : file.objectId }, | ||
update, | ||
function(error, result ) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
} | ||
); | ||
} | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we do this feature 'additive' instead of file or array? Like just files, or files + arrays?