diff --git a/res/include/script/file_viewer/Viewer.js b/res/include/script/file_viewer/Viewer.js index db8f957..39e810e 100644 --- a/res/include/script/file_viewer/Viewer.js +++ b/res/include/script/file_viewer/Viewer.js @@ -78,6 +78,12 @@ function Viewer(type, viewToken, data) { this.embedWindow = new EmbedWindow(this) + if (userAuthenticated && !this.file.can_edit) { + let btnGrab = document.getElementById("btn_grab") + btnGrab.style.display = "" + btnGrab.addEventListener("click", () => { this.grabFile() }) + } + this.renderSponsors() window.addEventListener("resize", e => { this.renderSponsors() }) @@ -245,6 +251,9 @@ Viewer.prototype.keyboardEvent = function (evt) { case 77: // M to open the embed window this.embedWindow.toggle() break + case 71: // G to grab this file + this.grabFile() + break case 81: // Q to close the window window.close() break @@ -263,6 +272,28 @@ Viewer.prototype.toggleFullscreen = function () { } } +Viewer.prototype.grabFile = async function () { + if (!userAuthenticated || this.file.can_edit) { + return + } + + const form = new FormData() + form.append("grab_file", this.file.id) + console.log(this.file.id) + + try { + const resp = await fetch(apiEndpoint + "/file", { method: "POST", body: form }); + if (resp.status >= 400) { + throw (await resp.json()).message + } + + window.open(domainURL() + "/u/" + (await resp.json()).id, "_blank") + } catch (err) { + alert("Failed to grab file: " + err) + return + } +} + // Against XSS attacks function escapeHTML(str) { diff --git a/res/include/style/layout.css b/res/include/style/layout.css index e4b1853..dec5589 100644 --- a/res/include/style/layout.css +++ b/res/include/style/layout.css @@ -27,8 +27,6 @@ font-display: block; src: local('Material Icons'), local('MaterialIcons-Regular'), - url(/res/misc/MaterialIcons-Regular.woff2) format('woff2'), - url(/res/misc/MaterialIcons-Regular.woff) format('woff'), url(/res/misc/MaterialIcons-Regular.ttf) format('truetype'); } .icon { diff --git a/res/static/misc/MaterialIcons-Regular.ttf b/res/static/misc/MaterialIcons-Regular.ttf index 7015564..e50801b 100644 Binary files a/res/static/misc/MaterialIcons-Regular.ttf and b/res/static/misc/MaterialIcons-Regular.ttf differ diff --git a/res/static/misc/MaterialIcons-Regular.woff b/res/static/misc/MaterialIcons-Regular.woff deleted file mode 100644 index b648a3e..0000000 Binary files a/res/static/misc/MaterialIcons-Regular.woff and /dev/null differ diff --git a/res/static/misc/MaterialIcons-Regular.woff2 b/res/static/misc/MaterialIcons-Regular.woff2 deleted file mode 100644 index 9fa2112..0000000 Binary files a/res/static/misc/MaterialIcons-Regular.woff2 and /dev/null differ diff --git a/res/template/file_viewer.html b/res/template/file_viewer.html index 2877c3a..ae26f04 100644 --- a/res/template/file_viewer.html +++ b/res/template/file_viewer.html @@ -63,13 +63,13 @@ - @@ -77,14 +77,19 @@ help Details - +
+ +
{{ if and .Other.FileAdsEnabled .Other.UserAdsEnabled }} @@ -279,27 +284,26 @@
- - +