forked from Kieran/void.cat
bug fixes
- Fix inaccurate trasfer stats - Fix Edge bugs
This commit is contained in:
parent
24c7fc022b
commit
e1b8cd6315
@ -85,6 +85,12 @@
|
||||
<div class="header" onclick="window.location.href = '/'">
|
||||
void.cat
|
||||
</div>
|
||||
<div id="page-notice">
|
||||
<b>Please take note that:</b><br>
|
||||
<ul>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div id="page-upload">
|
||||
<div class="page-left" style="width: 100%">
|
||||
<div id="dropzone">Click me!</div>
|
||||
|
@ -162,6 +162,15 @@ a:hover { text-decoration: underline; }
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#page-notice {
|
||||
display: none;
|
||||
margin: 10px;
|
||||
padding: 10px;
|
||||
border: 3px solid black;
|
||||
background-color: #a90000;
|
||||
color: #ffe;
|
||||
}
|
||||
|
||||
#page-stats {
|
||||
display: none;
|
||||
}
|
||||
|
@ -14,6 +14,18 @@ const App = {
|
||||
get Upload() { return $("template[id='tmpl-upload']") }
|
||||
},
|
||||
|
||||
get IsEdge() {
|
||||
return /Edge/.test(navigator.userAgent);
|
||||
},
|
||||
|
||||
get IsChrome() {
|
||||
return !App.IsEdge && /Chrome/.test(navigator.userAgent);
|
||||
},
|
||||
|
||||
get IsFirefox() {
|
||||
return !App.IsEdge && /Mozilla/.test(navigator.userAgent);
|
||||
},
|
||||
|
||||
/**
|
||||
* Uploads the files as selected by the input form
|
||||
* @param {Element} ctx
|
||||
@ -35,6 +47,9 @@ const App = {
|
||||
* Sets up the page
|
||||
*/
|
||||
Init: async function () {
|
||||
App.CheckBrowserSupport();
|
||||
App.MakePolyfills();
|
||||
|
||||
window.site_info = await Api.GetSiteInfo();
|
||||
|
||||
App.Elements.PageView.style.display = "none";
|
||||
@ -45,7 +60,7 @@ const App = {
|
||||
if (location.hash == "#faq") {
|
||||
let faq_headers = document.querySelectorAll('#page-faq .faq-header');
|
||||
for (let x = 0; x < faq_headers.length; x++) {
|
||||
faq_headers[x].addEventListener('click', function() {
|
||||
faq_headers[x].addEventListener('click', function () {
|
||||
this.nextElementSibling.classList.toggle("show");
|
||||
}.bind(faq_headers[x]));
|
||||
}
|
||||
@ -60,12 +75,63 @@ const App = {
|
||||
new DropzoneManager(App.Elements.Dropzone);
|
||||
}
|
||||
|
||||
if(window.site_info.ok){
|
||||
if (window.site_info.ok) {
|
||||
let elms = document.querySelectorAll("#footer-stats div span");
|
||||
elms[0].textContent = window.site_info.data.basic_stats.Files;
|
||||
elms[1].textContent = Utils.FormatBytes(window.site_info.data.basic_stats.Size, 2);
|
||||
elms[2].textContent = Utils.FormatBytes(window.site_info.data.basic_stats.Transfer_24h, 2);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds in polyfills for this browser
|
||||
*/
|
||||
MakePolyfills: function () {
|
||||
if (typeof TextEncoder === "undefined" || typeof TextDecoder === "undefined") {
|
||||
App.InsertScript("//unpkg.com/text-encoding@0.6.4/lib/encoding-indexes.js");
|
||||
App.InsertScript("//unpkg.com/text-encoding@0.6.4/lib/encoding.js");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a script tag at the top of the header
|
||||
* @param {string} src - The script src url
|
||||
*/
|
||||
InsertScript: function (src) {
|
||||
var before = document.head.getElementsByTagName('script')[0];
|
||||
var newlink = document.createElement('script');
|
||||
newlink.src = src;
|
||||
document.head.insertBefore(newlink, before);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks browser version
|
||||
*/
|
||||
CheckBrowserSupport: function () {
|
||||
if (!App.IsFirefox) {
|
||||
if (App.IsChrome) {
|
||||
App.AddNoticeItem("Uploads bigger then 100MiB usually crash Chrome when uploading. Please upload with Firefox. Or check <a target=\"_blank\" href=\"https://github.com/v0l/void.cat/tree/v3-b2b/tools\">GitHub</a> for tools.");
|
||||
}
|
||||
if (App.IsEdge) {
|
||||
let edge_version = /Edge\/([0-9]{1,3}\.[0-9]{1,5})/.exec(navigator.userAgent)[1];
|
||||
Log.I(`Edge version is: ${edge_version}`);
|
||||
if (parseFloat(edge_version) < 18.18218) {
|
||||
App.AddNoticeItem("Upload progress isn't reported in the version of Edge you are using, see <a target=\"_blank\" href=\"https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12224510/\">here for more info</a>.");
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector('#page-notice').style.display = "block";
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a notice to the UI notice box
|
||||
* @param {string} txt - Message to add to notice list
|
||||
*/
|
||||
AddNoticeItem: function (txt) {
|
||||
let ne = document.createElement('li');
|
||||
ne.innerHTML = txt;
|
||||
document.querySelector('#page-notice ul').appendChild(ne);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -92,7 +92,7 @@ const FileDownloader = function (fileinfo, key, iv) {
|
||||
|
||||
/**
|
||||
* Decrypts the raw VBF file
|
||||
* @returns {Promise<File>} The decrypted file
|
||||
* @returns {Promise<*>} The decrypted file
|
||||
*/
|
||||
this.DecryptFile = async function (blob) {
|
||||
let header = VBF.Parse(blob);
|
||||
@ -116,14 +116,12 @@ const FileDownloader = function (fileinfo, key, iv) {
|
||||
|
||||
//hash the file to verify
|
||||
let file_data = decrypted_file.slice(2 + json_header_length);
|
||||
let hmac_verify = await crypto.subtle.verify("HMAC", keyhmac, header.hmac, file_data);
|
||||
let hmac_verify = await crypto.subtle.verify(HMACKeyDetails, keyhmac, header.hmac, file_data);
|
||||
if (hmac_verify) {
|
||||
Log.I(`${this.fileinfo.FileId} HMAC verified!`);
|
||||
|
||||
let header_obj = JSON.parse(json_header_text);
|
||||
return new File([file_data], header_obj.name, {
|
||||
type: header_obj.mime
|
||||
});
|
||||
return { blob: new Blob([file_data], { type: header_obj.mime }), name: header_obj.name };
|
||||
} else {
|
||||
throw "HMAC verify failed";
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ const FileUpload = function (file, host) {
|
||||
|
||||
fr.onload = function (ev) {
|
||||
this.HandleProgress('state-hash-start');
|
||||
crypto.subtle.sign("HMAC", this.hmackey, ev.target.result).then(function (hash) {
|
||||
crypto.subtle.sign(HMACKeyDetails, this.hmackey, ev.target.result).then(function (hash) {
|
||||
this.HandleProgress('state-hash-end');
|
||||
resolve({
|
||||
hash: hash,
|
||||
|
@ -68,7 +68,7 @@ const ViewManager = function () {
|
||||
});
|
||||
fd.DownloadFile().then(function (file) {
|
||||
if (file !== null) {
|
||||
var objurl = URL.createObjectURL(file);
|
||||
var objurl = URL.createObjectURL(file.blob);
|
||||
var dl_link = document.createElement('a');
|
||||
dl_link.href = objurl;
|
||||
dl_link.download = file.name;
|
||||
|
@ -4,14 +4,14 @@
|
||||
public $Size;
|
||||
public $Transfer_24h;
|
||||
|
||||
private static $TransferStatsKey = REDIS_PREFIX . "stats-transfer-all";
|
||||
private static $AllTransferStatsKey = REDIS_PREFIX . "stats-transfer-all";
|
||||
private static $GeneralStatsKey = REDIS_PREFIX . "stats-general";
|
||||
|
||||
public static function Get() : Stats {
|
||||
$redis = StaticRedis::$Instance;
|
||||
|
||||
//calculate 24hr transfer stats
|
||||
$tx_24h_array = $redis->zRange(self::$TransferStatsKey, 0, 24, true); //stats are 1hr interval
|
||||
$tx_24h_array = $redis->zRange(self::$AllTransferStatsKey, 0, 24, true); //stats are 1hr interval
|
||||
$tx_24h = 0;
|
||||
foreach($tx_24h_array as $tx_key => $tx_bytes) {
|
||||
$tx_24h += $tx_bytes;
|
||||
@ -29,10 +29,14 @@
|
||||
}
|
||||
|
||||
public static function TrackTransfer($id, $size) : void {
|
||||
//$redis = StaticRedis::$Instance;
|
||||
self::AddAllTransfer($size);
|
||||
}
|
||||
|
||||
public static function AddAllTransfer($size) : void {
|
||||
$redis = StaticRedis::$Instance;
|
||||
|
||||
$stat_member = date("YmdH");
|
||||
$redis->zIncrBy(self::$TransferStatsKey, $size, $stat_member);
|
||||
$redis->zIncrBy(self::$AllTransferStatsKey, $size, $stat_member);
|
||||
}
|
||||
|
||||
public static function Collect($fs) : void {
|
||||
@ -48,6 +52,11 @@
|
||||
"files" => count($files),
|
||||
"size" => $total_size
|
||||
));
|
||||
|
||||
//tick from cron job to create keys for every hour
|
||||
//if no downloads are happening we will be missing keys
|
||||
//this will prevent inaccurate reporting
|
||||
self::AddAllTransfer(0);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user