UI: Change config export to include metadata about encryption

New format of {metadata: {encrypted: true}, contents: {...}} will simplify the logic of configuration import since we'll know if it's encrypted beforehand
This commit is contained in:
vakarisz 2022-06-29 14:56:08 +03:00
parent 6cef18b92f
commit 5a531bcb04
1 changed files with 11 additions and 7 deletions

View File

@ -21,19 +21,23 @@ const ConfigExportModal = (props: Props) => {
} }
function onSubmit() { function onSubmit() {
let config_json = JSON.stringify(props.configuration, null, 2); let config = props.configuration;
let config_export = null; let config_export = {'metadata': {}, 'contents': null};
if (radioValue === 'password') { if (radioValue === 'password') {
config_export = encryptText(config_json, pass); config_export.contents = encryptText(JSON.stringify(config), pass);
config_export.metadata = {'encrypted': true};
} else { } else {
config_export = config_json; config_export.contents = config;
config_export.metadata = {'encrypted': false};
} }
config_export = new Blob(
[config_export], let export_json = JSON.stringify(config_export, null, 2);
let export_blob = new Blob(
[export_json],
{type: 'text/plain;charset=utf-8'} {type: 'text/plain;charset=utf-8'}
); );
FileSaver.saveAs(config_export, 'monkey.conf'); FileSaver.saveAs(export_blob, 'monkey.conf');
props.onHide(); props.onHide();
} }