Skip to content

Commit

Permalink
fix importer js
Browse files Browse the repository at this point in the history
Signed-off-by: binsky <[email protected]>
  • Loading branch information
binsky08 committed Aug 22, 2021
1 parent 88fef60 commit 9c6e270
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"maxerr" : 50,
"jquery" : true, // jQuery
"esversion" : 8,
"globals" : {
"angular": true,
"PassmanImporter": true,
"OC": true,
"window": true
} // additional predefined global variables
}
}
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function (grunt) {
eqeqeq: true,
eqnull: true,
browser: true,
esversion: 8,
globals: {
"angular": true,
"PassmanImporter": true,
Expand Down Expand Up @@ -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']);

};
};
20 changes: 6 additions & 14 deletions js/app/controllers/generic-csv-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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]);
}
Expand All @@ -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,
Expand All @@ -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'){
Expand Down
7 changes: 6 additions & 1 deletion js/app/services/fileservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
}]);
}());
}());
15 changes: 10 additions & 5 deletions js/importers/importer-passmanjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9c6e270

Please sign in to comment.