Skip to content

Commit 0f8e1ea

Browse files
authored
Remove filetype restrictions & send file as text
1 parent 1468a44 commit 0f8e1ea

File tree

1 file changed

+54
-66
lines changed

1 file changed

+54
-66
lines changed

src/widget.js

+54-66
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,63 @@
1-
const dropArea = document.querySelector(".blst-drag-area"),
2-
dragText = dropArea.querySelector(".blst-title"),
3-
button = dropArea.querySelector(".blst-button"),
4-
input = dropArea.querySelector(".blst-input");
5-
let blstFile; //this is a global variable and we'll use it inside multiple functions
1+
const dropArea = document.querySelector(".blst-drag-area"),
2+
dragText = dropArea.querySelector(".blst-title"),
3+
button = dropArea.querySelector(".blst-button"),
4+
input = dropArea.querySelector(".blst-input");
5+
let blstFile; //this is a global variable and we'll use it inside multiple functions
66

7-
input.addEventListener("change", (event) => {
8-
//getting user select file and [0] this means if user select multiple files then we'll select only the first one
9-
blstFile = event.target.files[0];
10-
dropArea.classList.add("active");
11-
showFile();
12-
});
13-
//If user Drag File Over DropArea
14-
dropArea.addEventListener("dragover", (event) => {
15-
event.preventDefault();
16-
dropArea.classList.add("active");
17-
dragText.textContent = "Release to Upload File";
18-
});
19-
//If user leave dragged File from DropArea
20-
dropArea.addEventListener("dragleave", () => {
21-
dropArea.classList.remove("active");
22-
dragText.textContent = "+ Drag & Drop";
23-
});
24-
//If user drop File on DropArea
25-
dropArea.addEventListener("drop", (event) => {
26-
event.preventDefault();
27-
//getting user select file and [0] this means if user select multiple files then we'll select only the first one
28-
blstFile = event.dataTransfer.files[0];
29-
showFile();
30-
});
7+
input.addEventListener("change", (event) => {
8+
//getting user select file and [0] this means if user select multiple files then we'll select only the first one
9+
blstFile = event.target.files[0];
10+
dropArea.classList.add("active");
11+
showFile();
12+
});
13+
//If user Drag File Over DropArea
14+
dropArea.addEventListener("dragover", (event) => {
15+
event.preventDefault();
16+
dropArea.classList.add("active");
17+
dragText.textContent = "Release to Upload File";
18+
});
19+
//If user leave dragged File from DropArea
20+
dropArea.addEventListener("dragleave", () => {
21+
dropArea.classList.remove("active");
22+
dragText.textContent = "+ Drag & Drop";
23+
});
24+
//If user drop File on DropArea
25+
dropArea.addEventListener("drop", (event) => {
26+
event.preventDefault();
27+
//getting user select file and [0] this means if user select multiple files then we'll select only the first one
28+
blstFile = event.dataTransfer.files[0];
29+
showFile();
30+
});
3131

3232
function showFile() {
33-
let fileType = blstFile.type;
34-
let validExtensions = ["application/json"];
35-
if (validExtensions.includes(fileType)) {
36-
if (blstFile.size > 4194304) { // 4mb
37-
alert("File size too big");
38-
dropArea.classList.remove("active");
39-
dragText.textContent = "+ Drag & Drop";
40-
} else {
41-
let reader = new FileReader();
42-
reader.onload = (event) => {
43-
let oas = JSON.parse(event.target.result);
44-
fetch("https://idk.blstsecurity.com/create_scan", {
33+
if (blstFile.size > 4194304) { // 4mb
34+
alert("File size too big");
35+
dropArea.classList.remove("active");
36+
dragText.textContent = "+ Drag & Drop";
37+
} else {
38+
let reader = new FileReader();
39+
reader.onload = (event) => {
40+
let oas = JSON.parse(event.target.result);
41+
fetch("https://idk.blstsecurity.com/create_scan", {
4542
method: "POST",
46-
body: JSON.stringify({
47-
oas
48-
}),
49-
}).then((response) => response.json()).then((data) => {
50-
let tmp = dropArea.innerHTML;
51-
const a = document.createElement("a");
52-
a.href = `https://www.blstsecurity.com/ScanSwagger/${data.scan_id}?tab=Overview&promo=apibrief#${document.location.origin}`;
53-
a.target = "_blank";
54-
a.rel = "noopener noreferrer";
55-
document.body.appendChild(a);
56-
a.click();
57-
a.remove();
58-
// window.location=window.location;
59-
});
60-
let successHtml = `
43+
body: JSON.stringify({ oas }),
44+
}).then((response) => response.json()).then((data) => {
45+
const a = document.createElement("a");
46+
a.href = `https://www.blstsecurity.com/ScanSwagger/${data.scan_id}?tab=Overview&promo=apibrief#${document.location.origin}`;
47+
a.target = "_blank";
48+
a.rel = "noopener noreferrer";
49+
document.body.appendChild(a);
50+
a.click();
51+
a.remove();
52+
});
53+
let successHtml = `
6154
<div style="display:Flex;justify-content:center;">
6255
<div class="" style="width:20px;margin-right:6px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
6356
<path stroke-linecap="round" stroke-linejoin="round" d="M5.636 18.364a9 9 0 010-12.728m12.728 0a9 9 0 010 12.728m-9.9-2.829a5 5 0 010-7.07m7.072 0a5 5 0 010 7.07M13 12a1 1 0 11-2 0 1 1 0 012 0z" stroke="green" class="animated rotation" />
6457
</svg></div>
6558
<span>${blstFile.name}</span></div>`;
66-
dropArea.innerHTML = successHtml;
67-
};
68-
reader.readAsText(blstFile);
69-
}
70-
} else {
71-
alert("Not an acceptable file!");
72-
dropArea.classList.remove("active");
73-
dragText.textContent = "+ Drag & Drop";
74-
}
75-
}
59+
dropArea.innerHTML = successHtml;
60+
};
61+
reader.readAsText(blstFile);
62+
}
63+
}

0 commit comments

Comments
 (0)