Skip to content

Commit d1d5f89

Browse files
committed
Add setting to enable/disable file renaming
1 parent 2b5febb commit d1d5f89

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ $ npm start config.js
5959
* `masterKey`: Parse master key.
6060
* `serverURL`: The URL for the Parse server (default: http://api.parse.com/1).
6161
This is used to with `applicationId` and `masterKey` to get the schema and fetch all files/objects.
62+
* `renameFiles` (boolean): Whether or not to rename Parse hosted files.
63+
This removes the "tfss-" or legacy Parse filename prefix before saving with the new file adapter.
6264
* `renameInDatabase` (boolean): Whether or not to rename files in MongoDB.
6365
* `mongoURL`: MongoDB connection url.
6466
Direct access to the database is needed because Parse SDK doesn't allow direct writing to file fields.

lib/questions.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,24 @@ function questions(config) {
3434
{name: 'All files', value: 'all'}
3535
],
3636
when: (['parseOnly','parseServerOnly', 'all'].indexOf(config.filesToTransfer) == -1)
37+
}, {
38+
type: 'confirm',
39+
name: 'renameFiles',
40+
message: 'Rename Parse hosted file names?',
41+
default: false,
42+
when: function(answers) {
43+
return config.renameFiles == undefined &&
44+
(answers.filesToTransfer == 'all' || config.filesToTransfer == 'all' ||
45+
config.filesToTransfer == 'parseOnly' || answers.filesToTransfer == 'parseOnly');
46+
}
3747
}, {
3848
type: 'confirm',
3949
name: 'renameInDatabase',
4050
message: 'Rename Parse hosted files in the database after transfer?',
4151
default: false,
4252
when: function(answers) {
43-
return !config.renameInDatabase &&
53+
return config.renameInDatabase == undefined &&
54+
(answers.renameFiles || config.renameFiles) &&
4455
(answers.filesToTransfer == 'all' || config.filesToTransfer == 'all' ||
4556
config.filesToTransfer == 'parseOnly' || answers.filesToTransfer == 'parseOnly');
4657
}

lib/transfer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ function _requestErrorHandler(error, response) {
9292
* @return {String}
9393
*/
9494
function _createNewFileName(fileName) {
95+
if (!config.renameFiles) {
96+
return fileName;
97+
}
9598
if (_isParseHostedFile(fileName)) {
9699
fileName = fileName.replace('tfss-', '');
97100
var newPrefix = crypto.randomBytes(32/2).toString('hex');

0 commit comments

Comments
 (0)