Skip to content

Commit db6aad5

Browse files
make hash into function
1 parent 97c737f commit db6aad5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/models/mongo/infra-code-version.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ InfraCodeVersionSchema.methods.createFs = function (data, cb) {
222222
if (last(fileData.Key) === '/') {
223223
fileKey = fileData.Key.slice(0, -1);
224224
dirKey = fileData.Key;
225-
attrs.hash = crypto.createHash('md5').update(data.body.toString().trim()).digest('hex');
225+
attrs.hash = hashString(data.body.toString());
226226
}
227227
else {
228228
fileKey = fileData.Key;
@@ -290,7 +290,7 @@ InfraCodeVersionSchema.methods.updateFile = function (fullpath, body, cb) {
290290
}, {
291291
$set: {
292292
'files.$': file.toJSON(),
293-
'hash': crypto.createHash('md5').update(body.toString().trim()).digest('hex'),
293+
'hash': hashString(body.toString()),
294294
edited: true
295295
}
296296
}, function (err) {
@@ -550,4 +550,7 @@ InfraCodeVersionSchema.methods.copyFilesFromSource = function (sourceInfraCodeVe
550550
}
551551
};
552552

553+
function hashString(data) {
554+
return crypto.createHash('md5').update(data.toString().trim()).digest('hex');
555+
}
553556
var InfraCodeVersion = module.exports = mongoose.model('InfraCodeVersion', InfraCodeVersionSchema);

0 commit comments

Comments
 (0)