lots more stuff

- proper gzip download for disk system (aka WNI reinventing the Content-Encoding: gzip wheel)
- send Last-Modified for static files
- send wtv-checksum for all disk system downloads
- other fixes
This commit is contained in:
zefie
2021-08-11 00:56:21 -04:00
parent 11935a5886
commit 95442a12af
21 changed files with 185 additions and 100 deletions

View File

@@ -5,6 +5,7 @@
class WTVShared {
path = require('path');
fs = require('fs');
minisrv_config = [];
constructor(minisrv_config) {
@@ -19,6 +20,33 @@ class WTVShared {
}
}
/**
* Returns the Last-Modified date in Unix Timestamp format
* @param {string} file Path to a file
*/
getFileLastModified(file) {
var stats = this.fs.lstatSync(file);
if (stats) return new Date(stats.mtimeMs);
return false;
}
/**
* Returns the Last-Modified date in a RFC7231 compliant UTC Date String
* @param {string} file Path to a file
*/
getFileLastModifiedUTCString(file) {
return this.getFileLastModified(file).toUTCString();
}
/**
* Returns a RFC7231 compliant UTC Date String from the current time
* @param {Number} offset Offset from current time (+/-)
* @returns {string} A RFC7231 compliant UTC Date String from the current time
*/
getUTCTime(offset = 0) {
return new Date((new Date).getTime() + offset).toUTCString();
}
/**
* Returns a censored SSID
* @param {string|Array} obj SSID String or Headers Object
@@ -66,6 +94,20 @@ class WTVShared {
return path;
}
/**
* If the file ends with .gz, remove it
* @param {string} path
* @return {string} path without gz, or unmodified path if it isnt a gz
*/
stripGzipFromPath(path) {
var path_split = path.split('.');
if (path_split[path_split.length - 1].toLowerCase() == "gz") {
path_split.pop();
path = path_split.join(".");
}
return path;
}
/**
* Gets the file extension from a path
* @param {string} path