mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 07:11:33 +00:00
Updates
Moved page.prepareShareX() to a single JS file named sharex.js. It'll be loaded in home and dashboard pages, and both home.js and dashboard.js will rely on the function provided by it. The generated ShareX config file will also properly support cases where the safe is being hosted in a subdir now (e.i. https://example.com/lolisafe).
This commit is contained in:
parent
5bd343638a
commit
2f6c728e64
@ -114,7 +114,7 @@ page.prepareDashboard = function () {
|
||||
|
||||
page.getAlbumsSidebar()
|
||||
|
||||
page.prepareShareX()
|
||||
if (typeof page.prepareShareX === 'function') { page.prepareShareX() }
|
||||
}
|
||||
|
||||
page.logout = function () {
|
||||
@ -1399,30 +1399,6 @@ page.setActiveMenu = function (activeItem) {
|
||||
activeItem.classList.add('is-active')
|
||||
}
|
||||
|
||||
page.prepareShareX = function () {
|
||||
if (page.token) {
|
||||
// TODO: "location.origin" is unsuitable if the safe is hosted in a subdir (e.i. http://example.com/safe)
|
||||
var sharexElement = document.getElementById('ShareX')
|
||||
var sharexFile =
|
||||
'{\r\n' +
|
||||
' "Name": "' + location.hostname + '",\r\n' +
|
||||
' "DestinationType": "ImageUploader, FileUploader",\r\n' +
|
||||
' "RequestType": "POST",\r\n' +
|
||||
' "RequestURL": "' + location.origin + '/api/upload",\r\n' +
|
||||
' "FileFormName": "files[]",\r\n' +
|
||||
' "Headers": {\r\n' +
|
||||
' "token": "' + page.token + '"\r\n' +
|
||||
' },\r\n' +
|
||||
' "ResponseType": "Text",\r\n' +
|
||||
' "URL": "$json:files[0].url$",\r\n' +
|
||||
' "ThumbnailURL": "$json:files[0].url$"\r\n' +
|
||||
'}'
|
||||
var sharexBlob = new Blob([sharexFile], { type: 'application/octet-binary' })
|
||||
sharexElement.setAttribute('href', URL.createObjectURL(sharexBlob))
|
||||
sharexElement.setAttribute('download', location.hostname + '.sxcu')
|
||||
}
|
||||
}
|
||||
|
||||
page.getPrettyDate = date => {
|
||||
return date.getFullYear() + '-' +
|
||||
(date.getMonth() < 9 ? '0' : '') + // month's index starts from zero
|
||||
|
@ -292,7 +292,7 @@ page.prepareDropzone = function () {
|
||||
file.previewElement.querySelector('.error').innerHTML = error
|
||||
})
|
||||
|
||||
page.prepareShareX()
|
||||
if (typeof page.prepareShareX === 'function') { page.prepareShareX() }
|
||||
}
|
||||
|
||||
page.uploadUrls = function (button) {
|
||||
@ -391,30 +391,6 @@ page.updateTemplate = function (file, response) {
|
||||
}
|
||||
}
|
||||
|
||||
page.prepareShareX = function () {
|
||||
if (page.token) {
|
||||
// TODO: "location.origin" is unsuitable if the safe is hosted in a subdir (e.i. http://example.com/safe)
|
||||
var sharexElement = document.getElementById('ShareX')
|
||||
var sharexFile =
|
||||
'{\r\n' +
|
||||
' "Name": "' + location.hostname + '",\r\n' +
|
||||
' "DestinationType": "ImageUploader, FileUploader",\r\n' +
|
||||
' "RequestType": "POST",\r\n' +
|
||||
' "RequestURL": "' + location.origin + '/api/upload",\r\n' +
|
||||
' "FileFormName": "files[]",\r\n' +
|
||||
' "Headers": {\r\n' +
|
||||
' "token": "' + page.token + '"\r\n' +
|
||||
' },\r\n' +
|
||||
' "ResponseType": "Text",\r\n' +
|
||||
' "URL": "$json:files[0].url$",\r\n' +
|
||||
' "ThumbnailURL": "$json:files[0].url$"\r\n' +
|
||||
'}'
|
||||
var sharexBlob = new Blob([sharexFile], { type: 'application/octet-binary' })
|
||||
sharexElement.setAttribute('href', URL.createObjectURL(sharexBlob))
|
||||
sharexElement.setAttribute('download', location.hostname + '.sxcu')
|
||||
}
|
||||
}
|
||||
|
||||
page.createAlbum = function () {
|
||||
var div = document.createElement('div')
|
||||
div.innerHTML =
|
||||
|
25
public/js/sharex.js
Normal file
25
public/js/sharex.js
Normal file
@ -0,0 +1,25 @@
|
||||
/* global page */
|
||||
|
||||
page.prepareShareX = function () {
|
||||
if (!page.token) { return }
|
||||
var origin = (location.hostname + location.pathname).replace(/\/(dashboard)?$/, '')
|
||||
var originClean = origin.replace(/\//g, '_')
|
||||
var sharexElement = document.getElementById('ShareX')
|
||||
var sharexFile =
|
||||
'{\r\n' +
|
||||
' "Name": "' + originClean + '",\r\n' +
|
||||
' "DestinationType": "ImageUploader, FileUploader",\r\n' +
|
||||
' "RequestType": "POST",\r\n' +
|
||||
' "RequestURL": "' + origin + '/api/upload",\r\n' +
|
||||
' "FileFormName": "files[]",\r\n' +
|
||||
' "Headers": {\r\n' +
|
||||
' "token": "' + page.token + '"\r\n' +
|
||||
' },\r\n' +
|
||||
' "ResponseType": "Text",\r\n' +
|
||||
' "URL": "$json:files[0].url$",\r\n' +
|
||||
' "ThumbnailURL": "$json:files[0].url$"\r\n' +
|
||||
'}'
|
||||
var sharexBlob = new Blob([sharexFile], { type: 'application/octet-binary' })
|
||||
sharexElement.setAttribute('href', URL.createObjectURL(sharexBlob))
|
||||
sharexElement.setAttribute('download', originClean + '.sxcu')
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
v2: Images and config files (manifest.json, browserconfig.xml, etc).
|
||||
v3: CSS and JS files (libs such as bulma, lazyload, etc).
|
||||
#}
|
||||
{% set v1 = "dK4iWQ3CEe" %}
|
||||
{% set v1 = "gmQt09yByV" %}
|
||||
{% set v2 = "Ii3JYKIhb0" %}
|
||||
{% set v3 = "HrvcYD3KTh" %}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
<script type="text/javascript" src="libs/clipboard.js/clipboard.min.js?v={{ globals.v3 }}"></script>
|
||||
<script type="text/javascript" src="libs/lazyload/lazyload.min.js?v={{ globals.v3 }}"></script>
|
||||
<script type="text/javascript" src="js/dashboard.js?v={{ globals.v1 }}"></script>
|
||||
<script type="text/javascript" src="js/sharex.js?v={{ globals.v1 }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -22,6 +22,7 @@
|
||||
<script type="text/javascript" src="libs/clipboard.js/clipboard.min.js?v={{ globals.v3 }}"></script>
|
||||
<script type="text/javascript" src="libs/lazyload/lazyload.min.js?v={{ globals.v3 }}"></script>
|
||||
<script type="text/javascript" src="js/home.js?v={{ globals.v1 }}"></script>
|
||||
<script type="text/javascript" src="js/sharex.js?v={{ globals.v1 }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
Loading…
Reference in New Issue
Block a user