upload direct + bug fixes

This commit is contained in:
Kieran
2018-11-22 23:05:39 +08:00
parent 6b4012b7a3
commit 9a16f28d52
6 changed files with 43 additions and 19 deletions

View File

@ -1,9 +1,7 @@
$page-width: 1024px; $page-width: 1024px;
$page-height: 512px;
$page-padding: 10px; $page-padding: 10px;
$page-margin-top: 20px; $page-margin-top: 20px;
$dropzone-border-width: 2px; $dropzone-border-width: 2px;
$dropzone-height: ($page-height - ($dropzone-border-width * 2)) / 2;
$upload-progress-padding: 2px; $upload-progress-padding: 2px;
$upload-progress-height: 20px; $upload-progress-height: 20px;
@ -51,11 +49,15 @@ a:hover { text-decoration: underline; }
#dropzone { #dropzone {
border: $dropzone-border-width dashed #333; border: $dropzone-border-width dashed #333;
line-height: $dropzone-height; line-height: 100px;
text-align: center; text-align: center;
font-size: 50px; font-size: 50px;
} }
#dropzone small {
font-size: 20px;
}
#page-upload { #page-upload {
display: none; display: none;
padding: 10px 10px 0px 10px; padding: 10px 10px 0px 10px;
@ -196,7 +198,6 @@ a:hover { text-decoration: underline; }
#page-view .file-info { #page-view .file-info {
display: grid; display: grid;
grid-template-columns: 25% 25% 25% 25%; grid-template-columns: 25% 25% 25% 25%;
text-align: center;
border: 1px solid #aaa; border: 1px solid #aaa;
margin: 10px 0px 0px 0px; margin: 10px 0px 0px 0px;
padding: 5px; padding: 5px;
@ -288,7 +289,7 @@ a:hover { text-decoration: underline; }
margin-top: 0; margin-top: 0;
border-radius: 0; border-radius: 0;
} }
.header { .header {
border-radius: 0; border-radius: 0;
} }

View File

@ -35,6 +35,12 @@ const App = {
* Sets up the page * Sets up the page
*/ */
Init: async function () { Init: async function () {
window.site_info = await Api.GetSiteInfo();
App.Elements.PageView.style.display = "none";
App.Elements.PageUpload.style.display = "none";
App.Elements.PageFaq.style.display = "none";
if (location.hash !== "") { if (location.hash !== "") {
if (location.hash == "#faq") { if (location.hash == "#faq") {
let faq_headers = document.querySelectorAll('#page-faq .faq-header'); let faq_headers = document.querySelectorAll('#page-faq .faq-header');
@ -43,26 +49,22 @@ const App = {
this.nextElementSibling.classList.toggle("show"); this.nextElementSibling.classList.toggle("show");
}.bind(faq_headers[x])); }.bind(faq_headers[x]));
} }
App.Elements.PageUpload.style.display = "none";
App.Elements.PageFaq.style.display = "block"; App.Elements.PageFaq.style.display = "block";
} else { } else {
App.Elements.PageUpload.style.display = "none";
App.Elements.PageView.style.display = "block"; App.Elements.PageView.style.display = "block";
new ViewManager(); new ViewManager();
} }
} else { } else {
App.Elements.PageUpload.style.display = "block"; App.Elements.PageUpload.style.display = "block";
App.Elements.PageView.style.display = "none"; $('#dropzone').innerHTML = `Click me!<br><small>(${Utils.FormatBytes(window.site_info.data.max_upload_size)} max)</small>`;
new DropzoneManager(App.Elements.Dropzone); new DropzoneManager(App.Elements.Dropzone);
} }
let stats = await Api.GetSiteInfo(); if(window.site_info.ok){
if(stats.ok){
let elms = document.querySelectorAll("#footer-stats div span"); let elms = document.querySelectorAll("#footer-stats div span");
elms[0].textContent = stats.data.basic_stats.Files; elms[0].textContent = window.site_info.data.basic_stats.Files;
elms[1].textContent = Utils.FormatBytes(stats.data.basic_stats.Size, 2); elms[1].textContent = Utils.FormatBytes(window.site_info.data.basic_stats.Size, 2);
elms[2].textContent = Utils.FormatBytes(stats.data.basic_stats.Transfer_24h, 2); elms[2].textContent = Utils.FormatBytes(window.site_info.data.basic_stats.Transfer_24h, 2);
} }
} }
}; };

View File

@ -17,8 +17,10 @@ const DropzoneManager = function (dz) {
i.addEventListener('change', function (evt) { i.addEventListener('change', function (evt) {
this.SetUI(); this.SetUI();
let fl = evt.target.files; let fl = evt.target.files;
let host = window.site_info.ok ? window.site_info.data.upload_host : window.location.host;
for (let z = 0; z < fl.length; z++) { for (let z = 0; z < fl.length; z++) {
new FileUpload(fl[z]).ProcessUpload(); new FileUpload(fl[z], host).ProcessUpload();
} }
}.bind(this)); }.bind(this));
i.click(); i.click();

View File

@ -2,10 +2,12 @@
* File upload handler class * File upload handler class
* @class * @class
* @param {File} file - The file handle to upload * @param {File} file - The file handle to upload
* @param {string} host - The hostname to upload to
*/ */
const FileUpload = function (file) { const FileUpload = function (file, host) {
this.hasCrypto = typeof window.crypto.subtle === "object"; this.hasCrypto = typeof window.crypto.subtle === "object";
this.file = file; this.file = file;
this.host = host;
this.domNode = null; this.domNode = null;
this.key = null; this.key = null;
this.hmackey = null; this.hmackey = null;
@ -243,7 +245,7 @@ const FileUpload = function (file) {
this.UploadData = async function (fileData) { this.UploadData = async function (fileData) {
this.uploadStats.lastProgress = new Date().getTime(); this.uploadStats.lastProgress = new Date().getTime();
this.HandleProgress('state-upload-start'); this.HandleProgress('state-upload-start');
let uploadResult = await XHR("POST", "/upload", fileData, undefined, function (ev) { let uploadResult = await XHR("POST", `${window.location.protocol}//${this.host}/upload`, fileData, undefined, function (ev) {
let now = new Date().getTime(); let now = new Date().getTime();
let dxLoaded = ev.loaded - this.uploadStats.lastLoaded; let dxLoaded = ev.loaded - this.uploadStats.lastLoaded;
let dxTime = now - this.uploadStats.lastProgress; let dxTime = now - this.uploadStats.lastProgress;

View File

@ -27,7 +27,9 @@
$rsp->ok = true; $rsp->ok = true;
$rsp->data = array( $rsp->data = array(
"max_upload_size" => Config::$Instance->max_upload_size, "max_upload_size" => Config::$Instance->max_upload_size,
"basic_stats" => Stats::Get() "basic_stats" => Stats::Get(),
"upload_host" => Upload::GetUploadHost(),
"geoip_info" => geoip_database_info()
); );
break; break;
} }

View File

@ -91,5 +91,20 @@
return $id; return $id;
} }
public static function GetUploadHost() : string {
$cont = geoip_continent_code_by_name(USER_IP);
if($cont === False){
$cont = "EU";
}
$redis = StaticRedis::$Instance;
$map = $redis->hGetAll(REDIS_PREFIX . "upload-region-mapping");
if($map !== False && isset($map[$cont])) {
return $map[$cont];
} else {
return $_SERVER["HTTP_HOST"];
}
}
} }
?> ?>