From 9c6e270f768a29394b07a2effe0628dee84cb06a Mon Sep 17 00:00:00 2001 From: binsky Date: Sun, 22 Aug 2021 15:12:57 +0200 Subject: [PATCH] fix importer js Signed-off-by: binsky --- .jshintrc | 3 ++- Gruntfile.js | 3 ++- js/app/controllers/generic-csv-importer.js | 20 ++++++-------------- js/app/services/fileservice.js | 7 ++++++- js/importers/importer-passmanjson.js | 15 ++++++++++----- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.jshintrc b/.jshintrc index 688f0cb7..6cf70144 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,10 +1,11 @@ { "maxerr" : 50, "jquery" : true, // jQuery + "esversion" : 8, "globals" : { "angular": true, "PassmanImporter": true, "OC": true, "window": true } // additional predefined global variables -} \ No newline at end of file +} diff --git a/Gruntfile.js b/Gruntfile.js index 4e346391..00381395 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -34,6 +34,7 @@ module.exports = function (grunt) { eqeqeq: true, eqnull: true, browser: true, + esversion: 8, globals: { "angular": true, "PassmanImporter": true, @@ -406,4 +407,4 @@ module.exports = function (grunt) { grunt.registerTask('hint', ['jshint']); grunt.registerTask('build', ['sass', 'jshint', 'html2js', 'mkdir:dist', 'copy:dist', 'copy:fonts', 'replace:dist', 'uglify', 'concat:css', 'cssmin', 'clean:css', 'replace:strict', 'copy:settingsJs']); -}; \ No newline at end of file +}; diff --git a/js/app/controllers/generic-csv-importer.js b/js/app/controllers/generic-csv-importer.js index 4117eae3..c94e8d76 100644 --- a/js/app/controllers/generic-csv-importer.js +++ b/js/app/controllers/generic-csv-importer.js @@ -116,7 +116,7 @@ if (row[k] !== undefined && (typeof row[k] === 'string' || row[k] instanceof String) && row[k].length > 1){ try { row[k] = JSON.parse(row[k]); - for(var i = 0; k < row[k].length; i++){ + for(let i = 0; k < row[k].length; i++){ _credential.custom_fields.push({ 'label': row[k][i].label, 'secret': row[k][i].secret, @@ -128,7 +128,7 @@ // console.error(e); } } else { - for(var j = 0; j < row[k].length; j++){ + for(let j = 0; j < row[k].length; j++){ if (row[k][j].field_type === 'file'){ var _file = { filename: row[k][j].value.filename, @@ -137,11 +137,7 @@ data: row[k][j].value.file_data }; - row[k][j].value = await FileService.uploadFile(_file).then(function (result) { - delete result.file_data; - result.filename = EncryptService.decryptString(result.filename); - return result; - }); + row[k][j].value = await FileService.uploadFile(_file).then(FileService.getEmptyFileWithDecryptedFilename); } _credential.custom_fields.push(row[k][j]); } @@ -150,7 +146,7 @@ if (row[k] !== undefined && (typeof row[k] === 'string' || row[k] instanceof String) && row[k].length > 1){ try { row[k] = JSON.parse(row[k]); - for(var i = 0; k < row[k].length; i++){ + for(let i = 0; k < row[k].length; i++){ _credential.files.push({ filename: row[k][i].filename, size: row[k][i].size, @@ -162,17 +158,13 @@ // console.error(e); } } else { - for(var j = 0; j < row[k].length; j++){ + for(let j = 0; j < row[k].length; j++){ _credential.files.push(await FileService.uploadFile({ filename: row[k][j].filename, size: row[k][j].size, mimetype: row[k][j].mimetype, data: row[k][j].file_data - }).then(function (result) { - delete result.file_data; - result.filename = EncryptService.decryptString(result.filename); - return result; - })); + }).then(FileService.getEmptyFileWithDecryptedFilename)); } } } else if(field === 'tags'){ diff --git a/js/app/services/fileservice.js b/js/app/services/fileservice.js index 54cad62c..39560822 100644 --- a/js/app/services/fileservice.js +++ b/js/app/services/fileservice.js @@ -114,7 +114,12 @@ /** global: URL */ return URL.createObjectURL(bb); + }, + getEmptyFileWithDecryptedFilename: function (file) { + delete file.file_data; + file.filename = EncryptService.decryptString(file.filename); + return file; } }; }]); -}()); \ No newline at end of file +}()); diff --git a/js/importers/importer-passmanjson.js b/js/importers/importer-passmanjson.js index f600d0e9..55f68cc9 100644 --- a/js/importers/importer-passmanjson.js +++ b/js/importers/importer-passmanjson.js @@ -43,7 +43,8 @@ var PassmanImporter = PassmanImporter || {}; PassmanImporter.passmanJson.readFile = function (file_data) { /** global: C_Promise */ - return new C_Promise(async function(){ + return new C_Promise( + async function(){ var parseCustomFields = async function (customFields, credential){ if (customFields.length > 0) { for (var cf = 0; cf < customFields.length; cf++) { @@ -93,10 +94,14 @@ var PassmanImporter = PassmanImporter || {}; mimetype: files[cf].mimetype, data: files[cf].file_data }; - var file_result = await FileService.uploadFile(_file); - delete file_result.file_data; - file_result.filename = EncryptService.decryptString(file_result.filename); - credential.files.push(file_result); + try { + var file_result = await FileService.uploadFile(_file); + delete file_result.file_data; + file_result.filename = EncryptService.decryptString(file_result.filename); + credential.files.push(file_result); + } catch (e) { + console.error("failed processing file: " + _file.filename); + } } } return credential;