diff --git a/App/common.js b/App/common.js
index dbfee4d..4700455 100644
--- a/App/common.js
+++ b/App/common.js
@@ -304,7 +304,7 @@ function getRequestHeaders(id) {
return requestHeaders;
}
-function prepareDownload(d) {
+async function prepareDownload(d) {
var details = {};
details.url = d.url;
@@ -326,12 +326,19 @@ function prepareDownload(d) {
// decode URI Component
details.url = decodeURIComponent(details.url);
details.fileName = decodeURIComponent(details.fileName);
-
+
// file name cannot have ""
details.fileName = details.fileName.replace('\";', '');
details.fileName = details.fileName.replace('\"', '');
details.fileName = details.fileName.replace('\"', '');
+ // correct File Name
+ var getting = correctFileName(details.fileName);
+ await getting.then ((name) => {
+ details.fileName = name;
+ }
+ );
+
// get file size
details.fileSize = getFileSize(d);
diff --git a/App/data/DownloadPanel/index.html b/App/data/DownloadPanel/index.html
index c1c662f..b0087f6 100644
--- a/App/data/DownloadPanel/index.html
+++ b/App/data/DownloadPanel/index.html
@@ -502,7 +502,8 @@
-
+
+
diff --git a/App/data/DownloadPanel/index.js b/App/data/DownloadPanel/index.js
index c153e85..179476a 100644
--- a/App/data/DownloadPanel/index.js
+++ b/App/data/DownloadPanel/index.js
@@ -71,54 +71,90 @@ function download() {
const url = document.getElementById('url').value;
const fn = document.getElementById('fn').value;
const fp = document.getElementById('fp').value;
- var sending = browser.runtime.sendMessage({
- get: "download",
- url: url,
- fileName: fn,
- filePath: fp,
- header: headers,
+ verifyFileName(fn).then((e) => {
+ if (e.length != 0) {
+ document.getElementById('fn').style = "border: 1px solid red;box-shadow: red 0px 0px 4px;";
+ document.getElementById('fn').onchange = function() {
+ console.log("123");
+ document.getElementById('fn').style = "";
+ document.getElementById('fn').onchange = null;
+ };
+ }
+ else {
+ var sending = browser.runtime.sendMessage({
+ get: "download",
+ url: url,
+ fileName: fn,
+ filePath: fp,
+ header: headers,
+ });
+ sending.then(handleResponse, handleError);
+ saveWinLoc();
+ }
});
- sending.then(handleResponse, handleError);
- saveWinLoc();
}
function save() {
const url = document.getElementById('url').value;
const fn = document.getElementById('fn').value;
const fp = document.getElementById('fp').value;
- var getting = browser.windows.getCurrent();
- getting.then((windowInfo) => {
- var sending = browser.runtime.sendMessage({
- get: "save",
- url: url,
- fileName: fn,
- filePath: fp,
- header: headers,
- incognito: windowInfo.incognito,
- });
- sending.then(handleResponse, handleError);
- }, (e) => console.log(e));
- saveWinLoc();
+ verifyFileName(fn).then((e) => {
+ if (e.length != 0) {
+ document.getElementById('fn').style = "border: 1px solid red;box-shadow: red 0px 0px 4px;";
+ document.getElementById('fn').onchange = function() {
+ console.log("123");
+ document.getElementById('fn').style = "";
+ document.getElementById('fn').onchange = null;
+ };
+ }
+ else {
+ var getting = browser.windows.getCurrent();
+ getting.then((windowInfo) => {
+ var sending = browser.runtime.sendMessage({
+ get: "save",
+ url: url,
+ fileName: fn,
+ filePath: fp,
+ header: headers,
+ incognito: windowInfo.incognito,
+ });
+ sending.then(handleResponse, handleError);
+ }, (e) => console.log(e));
+ saveWinLoc();
+ }
+ });
}
function saveas() {
const url = document.getElementById('url').value;
const fn = document.getElementById('fn').value;
const fp = document.getElementById('fp').value;
- var getting = browser.windows.getCurrent();
- getting.then((windowInfo) => {
- var sending = browser.runtime.sendMessage({
- get: "saveas",
- url: url,
- fileName: fn,
- filePath: fp,
- header: headers,
- wid: windowInfo.id,
- incognito: windowInfo.incognito,
- });
- sending.then(handleResponse, handleError);
- }, (e) => console.log(e));
- saveWinLoc();
+ verifyFileName(fn).then((e) => {
+ if (e.length != 0) {
+ document.getElementById('fn').style = "border: 1px solid red;box-shadow: red 0px 0px 4px;";
+ document.getElementById('fn').onchange = function() {
+ console.log("123");
+ document.getElementById('fn').style = "";
+ document.getElementById('fn').onchange = null;
+ };
+ }
+ else {
+ var getting = browser.windows.getCurrent();
+ getting.then((windowInfo) => {
+ var sending = browser.runtime.sendMessage({
+ get: "saveas",
+ url: url,
+ fileName: fn,
+ filePath: fp,
+ header: headers,
+ wid: windowInfo.id,
+ incognito: windowInfo.incognito,
+ });
+ sending.then(handleResponse, handleError);
+ }, (e) => console.log(e));
+ saveWinLoc();
+ }
+ });
}
function tmpopen() {
diff --git a/App/lib/tools.js b/App/lib/tools.js
index a08d4ba..c9ffd98 100644
--- a/App/lib/tools.js
+++ b/App/lib/tools.js
@@ -1,5 +1,37 @@
'use strict';
+async function verifyFileName(name) {
+ var tmp = [];
+ await browser.runtime.getPlatformInfo().then( (e) => {
+ if (name.match(/[<>:"\/\\|?*\x00-\x1F]/g) != null) {
+ tmp = name.match(/[<>:"\/\\|?*\x00-\x1F]/g);
+ }
+ if (e.os == "win") {
+ if (name.search(/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i) != -1)
+ tmp = tmp.concat(name);
+ if (name[name.length - 1] == ' ' || name[name.length - 1] == '.')
+ tmp = tmp.concat("Filenames cannot end in a space or dot.");
+ }
+ });
+ console.log(tmp);
+ return tmp;
+}
+
+async function correctFileName(name) {
+ var tmp = name;
+ await browser.runtime.getPlatformInfo().then( (e) => {
+ tmp = tmp.replace(/[<>:"\/\\|?*\x00-\x1F]/g, '_');
+ if (e.os == "win") {
+ if (tmp.search(/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i) != -1)
+ tmp = '_' + tmp;
+ if (tmp[tmp.length - 1] == ' ' || tmp[tmp.length - 1] == '.')
+ tmp = tmp.slice(0, tmp.length - 1);
+ }
+ });
+ console.log(tmp);
+ return tmp;
+}
+
function monitor(options) {
if (mon == undefined) {
mon = new Worker("/lib/worker.js");