mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 13:53:48 +01:00
Use URLSearchParams API instead of manual or parseQueryStringToDictionary use
This commit is contained in:
parent
02eb8d545a
commit
f5d2df9811
@ -5,7 +5,6 @@ draft: false
|
|||||||
---
|
---
|
||||||
<script src="/js/getFullDataPath.js" type="text/javascript"></script>
|
<script src="/js/getFullDataPath.js" type="text/javascript"></script>
|
||||||
<script src="/js/getTextFromFile.js" type="text/javascript"></script>
|
<script src="/js/getTextFromFile.js" type="text/javascript"></script>
|
||||||
<script src="/js/parseQueryStringToDictionary.js" type="text/javascript"></script>
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
window.onload=async function(){
|
window.onload=async function(){
|
||||||
@ -23,10 +22,10 @@ draft: false
|
|||||||
}
|
}
|
||||||
console.warn(mystr);
|
console.warn(mystr);
|
||||||
}
|
}
|
||||||
var queryDic=parseQueryStringToDictionary()
|
var params=new URL(window.location.href).searchParams
|
||||||
var key=["file","fileBase64"]
|
var key=["file","fileBase64"]
|
||||||
if(key[0] in queryDic){
|
if(params.has(key[0])){
|
||||||
var filename=queryDic[key[0]];
|
var filename=params.get(key[0]);
|
||||||
var textPromise=getTextFromFileUrlAsync(filename)
|
var textPromise=getTextFromFileUrlAsync(filename)
|
||||||
$("#btn_download").click(function(){
|
$("#btn_download").click(function(){
|
||||||
window.open(filename,"_self");
|
window.open(filename,"_self");
|
||||||
@ -35,8 +34,9 @@ draft: false
|
|||||||
document.getElementById('fileContent').innerText=await textPromise;
|
document.getElementById('fileContent').innerText=await textPromise;
|
||||||
document.getElementById('file').hidden=false;
|
document.getElementById('file').hidden=false;
|
||||||
document.getElementById("div_btn").hidden=false;
|
document.getElementById("div_btn").hidden=false;
|
||||||
} else if(key[1] in queryDic){
|
|
||||||
var base64=queryDic[key[1]];
|
} else if(params.has(key[1])){
|
||||||
|
var base64=params.get(key[1]);
|
||||||
$("#btn_download").click(function(){
|
$("#btn_download").click(function(){
|
||||||
window.open(String.raw`data:text/plain;base64,${base64}`,"_self")
|
window.open(String.raw`data:text/plain;base64,${base64}`,"_self")
|
||||||
})
|
})
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
function parseQueryStringToDictionary(queryString=window.location.search) {
|
|
||||||
var dictionary = {};
|
|
||||||
|
|
||||||
// remove the '?' from the beginning of the
|
|
||||||
// if it exists
|
|
||||||
if (queryString.indexOf('?') === 0) {
|
|
||||||
queryString = queryString.substr(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 1: separate out each key/value pair
|
|
||||||
var parts = queryString.split('&');
|
|
||||||
|
|
||||||
for (var i = 0; i < parts.length; i++) {
|
|
||||||
var p = parts[i];
|
|
||||||
// Step 2: Split Key/Value pair
|
|
||||||
var keyValuePair = p.split('=');
|
|
||||||
|
|
||||||
// Step 3: Add Key/Value pair to Dictionary object
|
|
||||||
var key = keyValuePair[0];
|
|
||||||
var value = keyValuePair[1];
|
|
||||||
|
|
||||||
// decode URI encoded string
|
|
||||||
value = decodeURIComponent(value);
|
|
||||||
value = value.replace(/\+/g, ' ');
|
|
||||||
|
|
||||||
dictionary[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 4: Return Dictionary Object
|
|
||||||
return dictionary;
|
|
||||||
}
|
|
@ -4,15 +4,23 @@ class websiteFile{
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getViewerURL(){
|
async getViewerURL(){
|
||||||
|
params=new URLSearchParams()
|
||||||
var urlbase="/view"
|
var urlbase="/view"
|
||||||
switch (trueTypeOf(this.file)) {
|
switch (trueTypeOf(this.file)) {
|
||||||
case "string":
|
case "string":
|
||||||
return String.raw`${urlbase}?file=${this.file}`
|
params.append("file",this.file)
|
||||||
break
|
break
|
||||||
case "File":
|
case "File":
|
||||||
var base64=btoa(await getTextFromUploadedFileAsync(this.file))
|
var base64=btoa(await getTextFromUploadedFileAsync(this.file))
|
||||||
return String.raw`${urlbase}?fileBase64=${base64}`;
|
params.append("fileBase64",base64);
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if ([...params].length>0){
|
||||||
|
return urlbase+"?"+params.tostring()
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return urlbase
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user