10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-04 05:03:53 +01:00

Add header option and better use of max-age

This commit is contained in:
Mickaël Véril 2020-11-01 16:54:57 +01:00
parent ed21b74fc8
commit de8648e5f1
5 changed files with 11 additions and 6 deletions

View File

@ -28,7 +28,7 @@ draft: false
var key = ["file", "fileBase64"]
if (params.has(key[0])) {
var filename = params.get(key[0]);
var text = await getTextFromFileUrlAsync(filename)
var text = await getTextFromFileUrlAsync(filename,{"Cache-Control":"max-age=0"})
$("#btn_download").click(function () {
var b = new Blob([text],{type:"text/plain;charset=utf-8"});
saveAs(b, filename.substring(filename.lastIndexOf('/')+1))

View File

@ -7,7 +7,8 @@ class Geometry {
switch (trueTypeOf(file)) {
case String.name:
file = getFullDataPath("/structures/"+file)
var str = await getTextFromFileUrlAsync(file)
const maxAge= (DebugMode.Enabled,0,600)
var str = await getTextFromFileUrlAsync(file,{"Cache-Control":`max-age=${maxAge}`})
break;
case File.name:
var str = await getTextFromUploadedFileAsync(file)

View File

@ -278,7 +278,8 @@ class dataFileBase {
switch (trueTypeOf(file)) {
case String.name:
file = getFullDataPath(file)
var str = await getTextFromFileUrlAsync(file)
const maxAge= (DebugMode.Enabled,0,600)
var str = await getTextFromFileUrlAsync(file,{"Cache-Control":`max-age=${maxAge}`})
break;
case File.name:
var str = await getTextFromUploadedFileAsync(file)

View File

@ -1,8 +1,10 @@
async function getTextFromFileUrlAsync(url) {
async function getTextFromFileUrlAsync(url,header={}) {
return new Promise(function (resolve, reject) {
var req = new XMLHttpRequest();
req.open("GET",url, true);
req.setRequestHeader("Cache-Control", "max-age=0")
for (const [key, val] of Object.entries(header)) {
req.setRequestHeader(key,val)
}
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200 || req.status==304) {//when a good response is given do this

View File

@ -1,7 +1,8 @@
class indexDB {
static async loadAsync() {
var db = new indexDB
const text = await getTextFromFileUrlAsync("/data/index.yaml")
const maxAge= (DebugMode.Enabled,0,600)
const text = await getTextFromFileUrlAsync("/data/index.yaml",{"Cache-Control":`max-age=${maxAge}`})
const myYaml = jsyaml.load(text);
db.sets = ((myYaml.sets === null) ? new Map() : new Map(Object.entries(myYaml.sets)));
db.others = ((myYaml.others === null) ? [] : Array.from(myYaml.others));