Add grab file button
This commit is contained in:
@@ -78,6 +78,12 @@ function Viewer(type, viewToken, data) {
|
|||||||
|
|
||||||
this.embedWindow = new EmbedWindow(this)
|
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()
|
this.renderSponsors()
|
||||||
window.addEventListener("resize", e => { 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
|
case 77: // M to open the embed window
|
||||||
this.embedWindow.toggle()
|
this.embedWindow.toggle()
|
||||||
break
|
break
|
||||||
|
case 71: // G to grab this file
|
||||||
|
this.grabFile()
|
||||||
|
break
|
||||||
case 81: // Q to close the window
|
case 81: // Q to close the window
|
||||||
window.close()
|
window.close()
|
||||||
break
|
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
|
// Against XSS attacks
|
||||||
function escapeHTML(str) {
|
function escapeHTML(str) {
|
||||||
|
@@ -27,8 +27,6 @@
|
|||||||
font-display: block;
|
font-display: block;
|
||||||
src: local('Material Icons'),
|
src: local('Material Icons'),
|
||||||
local('MaterialIcons-Regular'),
|
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');
|
url(/res/misc/MaterialIcons-Regular.ttf) format('truetype');
|
||||||
}
|
}
|
||||||
.icon {
|
.icon {
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -63,13 +63,13 @@
|
|||||||
</button>
|
</button>
|
||||||
<button id="btn_copy" class="toolbar_button button_full_width">
|
<button id="btn_copy" class="toolbar_button button_full_width">
|
||||||
<i class="icon">content_copy</i>
|
<i class="icon">content_copy</i>
|
||||||
<span><u>C</u>opy Link</span>
|
<span><u>C</u>opy link</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="btn_share" class="toolbar_button button_full_width">
|
<button id="btn_share" class="toolbar_button button_full_width">
|
||||||
<i class="icon">share</i>
|
<i class="icon">share</i>
|
||||||
<span>Share</span>
|
<span>Share</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="btn_shuffle" class="toolbar_button button_full_width" style="display: none;">
|
<button id="btn_shuffle" class="toolbar_button button_full_width" style="display: none;" title="Randomize the order of the files in this list">
|
||||||
<i class="icon">shuffle</i>
|
<i class="icon">shuffle</i>
|
||||||
<span>Shuffle ☐</span>
|
<span>Shuffle ☐</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -77,14 +77,19 @@
|
|||||||
<i class="icon">help</i>
|
<i class="icon">help</i>
|
||||||
<span>Deta<u>i</u>ls</span>
|
<span>Deta<u>i</u>ls</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="btn_embed" class="toolbar_button button_full_width">
|
<hr/>
|
||||||
<i class="icon">code</i>
|
|
||||||
<span>E<u>m</u>bed</span>
|
|
||||||
</button>
|
|
||||||
<button id="btn_edit" class="toolbar_button button_full_width" style="display: none;">
|
<button id="btn_edit" class="toolbar_button button_full_width" style="display: none;">
|
||||||
<i class="icon">edit</i>
|
<i class="icon">edit</i>
|
||||||
<span><u>E</u>dit</span>
|
<span><u>E</u>dit</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button id="btn_grab" class="toolbar_button button_full_width" style="display: none;" title="Copy this file to your own pixeldrain account">
|
||||||
|
<i class="icon">save_alt</i>
|
||||||
|
<span><u>G</u>rab file</span>
|
||||||
|
</button>
|
||||||
|
<button id="btn_embed" class="toolbar_button button_full_width" title="Include this file in your own webpages">
|
||||||
|
<i class="icon">code</i>
|
||||||
|
<span>E<u>m</u>bed</span>
|
||||||
|
</button>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
{{ if and .Other.FileAdsEnabled .Other.UserAdsEnabled }}
|
{{ if and .Other.FileAdsEnabled .Other.UserAdsEnabled }}
|
||||||
@@ -279,27 +284,26 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<div class="captcha_popup_captcha" style="text-align: center;"></div>
|
<div class="captcha_popup_captcha" style="text-align: center;"></div>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<template id="tpl_embed_popup">
|
<template id="tpl_embed_popup">
|
||||||
<p>
|
<p>
|
||||||
You can embed pixeldrain's file viewer in your own web pages. We
|
You can embed pixeldrain's file viewer in your own web pages. We
|
||||||
have created a special HTML code which renders a minimalistic
|
have created a special HTML code which renders a minimalistic
|
||||||
version of the file viewer where the title bar is a bit thinner and
|
version of the file viewer where the title bar is a bit thinner and
|
||||||
the toolbar is collapsed by default.
|
the toolbar is collapsed by default.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Unless it was uploaded using a pixeldrain Pro account the embedded
|
Unless it was uploaded using a pixeldrain Pro account the embedded
|
||||||
file will also show advertisements.
|
file will also show advertisements.
|
||||||
</p>
|
</p>
|
||||||
<h3>Code</h3>
|
<h3>Code</h3>
|
||||||
<textarea class="embed_html_code" style="width: 100%; height: 4em; margin: 0;"></textarea>
|
<textarea class="embed_html_code" style="width: 100%; height: 4em; margin: 0;"></textarea>
|
||||||
<br/>
|
<br/>
|
||||||
<button class="embed_copy_html"><i class="icon">content_copy</i> Copy HTML</button>
|
<button class="embed_copy_html"><i class="icon">content_copy</i> Copy HTML</button>
|
||||||
<button class="embed_show_preview"><i class="icon">visibility</i> Show example</button>
|
<button class="embed_show_preview"><i class="icon">visibility</i> Show example</button>
|
||||||
<h3>Example</h3>
|
<h3>Example</h3>
|
||||||
<div class="embed_preview_area" style="text-align: center;"></div>
|
<div class="embed_preview_area" style="text-align: center;"></div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="/res/script/Chart.min.js"></script>
|
<script src="/res/script/Chart.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
@@ -307,6 +311,7 @@
|
|||||||
let apiEndpoint = '{{.APIEndpoint}}';
|
let apiEndpoint = '{{.APIEndpoint}}';
|
||||||
let captchaKey = '{{.Other.CaptchaKey}}';
|
let captchaKey = '{{.Other.CaptchaKey}}';
|
||||||
let embeddedViewer = {{.Other.Embedded}};
|
let embeddedViewer = {{.Other.Embedded}};
|
||||||
|
let userAuthenticated = {{.Authenticated}};
|
||||||
let highlightColor = '#{{.Style.HighlightColor.RGB}}';
|
let highlightColor = '#{{.Style.HighlightColor.RGB}}';
|
||||||
{{template `util.js`}}
|
{{template `util.js`}}
|
||||||
{{template `drawGraph.js`}}
|
{{template `drawGraph.js`}}
|
||||||
|
Reference in New Issue
Block a user