-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
47 lines (36 loc) · 1.14 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const api = window.electronAPI;
function uploadFile(input, isPDF) {
const filepath = input.files[0].path;
if (filepath == null || filepath == "" || filepath == "undefined" || filepath == "null" || filepath == "NaN" || filepath == undefined) {
return;
}
if (isPDF) {
api.postPDF(filepath);
} else {
api.postCSV(filepath);
}
const filename = sanitzeFilename(filepath);
const id = isPDF ? "pdf" : "csv";
removeElementById(id);
addStringToList(filename, id);
}
async function processPDF() {
const pdfProcessResult = await api.processPDF();
alert(pdfProcessResult);
}
function sanitzeFilename(filename) {
return filename.replace(/^.*[\\\/]/, '');
}
function removeElementById(id) {
const element = document.getElementById(id);
if (typeof(element) != 'undefined' && element != null) {
element.remove();
}
}
function addStringToList(string, id) {
const list = document.getElementById("file-list");
const entry = document.createElement('li');
entry.appendChild(document.createTextNode(string));
entry.setAttribute("id", id);
list.appendChild(entry);
}