Browse Source

fix(gui): SSL certificate selection error

read certificate file data

related #215

Signed-off-by: Pranav C Balan <pranavxc@gmail.com>
pull/240/head
Pranav C Balan 3 years ago
parent
commit
26404ee15f
  1. 23
      packages/nc-gui/components/createOrEditProject.vue
  2. 42
      packages/nc-gui/helpers/fileReader.js

23
packages/nc-gui/components/createOrEditProject.vue

@ -438,7 +438,10 @@
</v-select>
<v-row class="pa-0 ma-0">
<input type="file" ref="certFilePath" class="d-none"/>
<input type="file" ref="certFilePath" class="d-none"
@change="readFileContent(db,'ssl','cert',dbIndex)"
/>
<x-btn tooltip="Select .cert file"
small
color="primary"
@ -449,7 +452,8 @@
>{{ db.ui.ssl.cert }}
</x-btn>
<input type="file" ref="keyFilePath" class="d-none"/>
<input type="file" ref="keyFilePath" class="d-none"
@change="readFileContent(db,'ssl','key',dbIndex)"/>
<x-btn tooltip="Select .key file"
small
color="primary"
@ -460,7 +464,8 @@
>{{ db.ui.ssl.key }}
</x-btn>
<input type="file" ref="caFilePath" class="d-none"/>
<input type="file" ref="caFilePath" class="d-none"
@change="readFileContent(db,'ssl','ca',dbIndex)"/>
<x-btn tooltip="Select CA file"
small
color="primary"
@ -769,7 +774,7 @@ import MonacoJsonEditor from "@/components/monaco/MonacoJsonEditor";
import JSON5 from 'json5';
const {uniqueNamesGenerator, starWars, adjectives, animals} = require('unique-names-generator');
import readFile from "@/helpers/fileReader";
import {mapGetters, mapActions, mapState, mapMutations} from "vuex";
import Vue from 'vue';
@ -1209,9 +1214,13 @@ export default {
openJsonInSystemEditor() {
// shell.openItem(path.join(this.project.folder, 'config.xc.json'));
},
readFileContent(db, obj, key, index) {
readFile(this.$refs[`${key}FilePath`][index], (data) => {
Vue.set(db.connection[obj], key, data)
})
},
selectFile(db, obj, key, index) {
// this.$refs[key][index].click()
this.$refs[key][index].click()
// console.log(obj, key);
// const file = dialog.showOpenDialog({
@ -1428,7 +1437,7 @@ export default {
let i = 0;
const toast = this.$toast.info(this.loaderMessages[0]);
const interv = setInterval(() => {
if(this.edit) return
if (this.edit) return
if (i < this.loaderMessages.length - 1) i++;
if (toast) {
if (!this.allSchemas) {

42
packages/nc-gui/helpers/fileReader.js

@ -0,0 +1,42 @@
// Ref : https://stackoverflow.com/a/12002275
//Tested in Mozilla Firefox browser, Chrome
function ReadFileAllBrowsers(FileElement, CallBackFunction) {
try {
if (!FileElement.files || !FileElement.files.length) return CallBackFunction();
const file = FileElement.files[0];
if (file) {
const reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function (evt) {
CallBackFunction(evt.target.result);
}
reader.onerror = function (evt) {
CallBackFunction()
}
}
} catch (Exception) {
const fall_back = ieReadFile(FileElement.value);
if (fall_back != false) {
CallBackFunction(fall_back);
}
}
}
///Reading files with Internet Explorer
function ieReadFile(filename) {
try {
const fso = new ActiveXObject("Scripting.FileSystemObject");
const fh = fso.OpenTextFile(filename, 1);
const contents = fh.ReadAll();
fh.Close();
return contents;
} catch (Exception) {
return false;
}
}
export default ReadFileAllBrowsers;
Loading…
Cancel
Save