mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
Merge branch 'browser-ecma6' into safe.fiery.me
This commit is contained in:
commit
49ce5aa654
@ -30,15 +30,5 @@
|
||||
"single"
|
||||
],
|
||||
"no-var": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"public/**/*.js"
|
||||
],
|
||||
"env": {
|
||||
"browser": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
5
.markdownlint.json
Normal file
5
.markdownlint.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"default": true,
|
||||
"MD013": false,
|
||||
"MD040": false
|
||||
}
|
14
README.md
14
README.md
@ -15,6 +15,20 @@ If you want to use an existing lolisafe database with this branch, make sure to
|
||||
|
||||
Configuration file of lolisafe, `config.js`, is also not 100% compatible with this branch. There are some options that had been renamed and/or restructured. Please make sure your config matches the sample in `config.sample.js` before starting.
|
||||
|
||||
## Missing thumbnails
|
||||
|
||||
Thumbnails will not be automatically generated for files that have been uploaded prior to enabling thumbnails generation in the config file. To generate thumbnails for old files, you can try running `yarn thumbs` (a shortcut to running `node scripts/thumbs.js`).
|
||||
|
||||
```
|
||||
Usage:
|
||||
yarn thumbs <mode=1|2|3> [force=0|1]
|
||||
|
||||
mode : 1 = images only, 2 = videos only, 3 = both images and videos
|
||||
force: 0 = no force (default), 1 = overwrite existing thumbnails
|
||||
```
|
||||
|
||||
For example, if you only want to generate thumbnails for image files, you can do `yarn thumbs 1`.
|
||||
|
||||
## Running
|
||||
|
||||
1. Ensure you have at least version 8.0.0 of node installed
|
||||
|
@ -138,7 +138,6 @@ albumsController.delete = async (req, res, next) => {
|
||||
return res.json({ success: false, description: 'No album specified.' })
|
||||
}
|
||||
|
||||
let ids = []
|
||||
let failed = []
|
||||
if (purge) {
|
||||
const files = await db.table('files')
|
||||
@ -147,11 +146,13 @@ albumsController.delete = async (req, res, next) => {
|
||||
userid: user.id
|
||||
})
|
||||
|
||||
ids = files.map(file => file.id)
|
||||
failed = await utils.bulkDeleteFiles('id', ids, user)
|
||||
if (files.length) {
|
||||
const ids = files.map(file => file.id)
|
||||
failed = await utils.bulkDeleteFiles('id', ids, user)
|
||||
|
||||
if (failed.length === ids.length) {
|
||||
return res.json({ success: false, description: 'Could not delete any of the files associated with the album.' })
|
||||
if (failed.length === ids.length) {
|
||||
return res.json({ success: false, description: 'Could not delete any of the files associated with the album.' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
10
lolisafe.js
10
lolisafe.js
@ -14,11 +14,11 @@ const safe = express()
|
||||
require('./database/db.js')(db)
|
||||
|
||||
fs.existsSync('./pages/custom') || fs.mkdirSync('./pages/custom')
|
||||
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
|
||||
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
|
||||
fs.existsSync('./' + config.uploads.folder + '/chunks') || fs.mkdirSync('./' + config.uploads.folder + '/chunks')
|
||||
fs.existsSync('./' + config.uploads.folder + '/thumbs') || fs.mkdirSync('./' + config.uploads.folder + '/thumbs')
|
||||
fs.existsSync('./' + config.uploads.folder + '/zips') || fs.mkdirSync('./' + config.uploads.folder + '/zips')
|
||||
fs.existsSync(`./${config.logsFolder}`) || fs.mkdirSync(`./${config.logsFolder}`)
|
||||
fs.existsSync(`./${config.uploads.folder}`) || fs.mkdirSync(`./${config.uploads.folder}`)
|
||||
fs.existsSync(`./${config.uploads.folder}/chunks`) || fs.mkdirSync(`./${config.uploads.folder}/chunks`)
|
||||
fs.existsSync(`./${config.uploads.folder}/thumbs`) || fs.mkdirSync(`./${config.uploads.folder}/thumbs`)
|
||||
fs.existsSync(`./${config.uploads.folder}/zips`) || fs.mkdirSync(`./${config.uploads.folder}/zips`)
|
||||
|
||||
safe.use(helmet())
|
||||
safe.set('trust proxy', 1)
|
||||
|
@ -16,7 +16,8 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"start": "node ./lolisafe.js",
|
||||
"pm2": "pm2 start --name lolisafe ./lolisafe.js"
|
||||
"pm2": "pm2 start --name lolisafe ./lolisafe.js",
|
||||
"thumbs": "node ./scripts/thumbs.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"bcrypt": "^2.0.0",
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Why do this folder only have symlinks?
|
||||
# Disclaimer as to why this folder only have Symlinks
|
||||
|
||||
At safe.fiery.me, we are using this: [https://github.com/BobbyWibowo/HttpErrorPages](https://github.com/BobbyWibowo/HttpErrorPages).
|
||||
At fiery.me, we are using this: [https://github.com/BobbyWibowo/HttpErrorPages](https://github.com/BobbyWibowo/HttpErrorPages).
|
||||
|
||||
It's nothing too important, but we are sharing the error pages from that directory to all other instances in the server.
|
||||
It's nothing too important, but we are sharing the error pages from that directory to all other instances in the server (regular http sites with nginx and node servers).
|
||||
|
39
public/js/.eslintrc.json
Normal file
39
public/js/.eslintrc.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"root": true,
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6
|
||||
},
|
||||
"env": {
|
||||
"browser": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended"
|
||||
],
|
||||
"rules": {
|
||||
"curly": [
|
||||
"error",
|
||||
"all"
|
||||
],
|
||||
"no-console": 0,
|
||||
"semi": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"space-before-function-paren": [
|
||||
"error",
|
||||
{
|
||||
"anonymous": "always",
|
||||
"named": "never",
|
||||
"asyncArrow": "always"
|
||||
}
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"indent": [
|
||||
"error",
|
||||
2
|
||||
]
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/* global LazyLoad */
|
||||
|
||||
const page = {}
|
||||
var page = {}
|
||||
|
||||
window.onload = () => {
|
||||
window.onload = function () {
|
||||
page.lazyLoad = new LazyLoad()
|
||||
}
|
||||
|
@ -1,13 +1,22 @@
|
||||
/* global swal, axios */
|
||||
|
||||
const page = {
|
||||
var page = {
|
||||
// user token
|
||||
token: localStorage.token
|
||||
token: localStorage.token,
|
||||
|
||||
// HTML elements
|
||||
user: null,
|
||||
pass: null
|
||||
}
|
||||
|
||||
page.do = async dest => {
|
||||
const user = document.getElementById('user').value
|
||||
const pass = document.getElementById('pass').value
|
||||
page.do = function (dest, onEnter) {
|
||||
var user = page.user.value
|
||||
var pass = page.pass.value
|
||||
|
||||
// If the form is submitted with Enter button and the form is still empty
|
||||
if (onEnter && !user.length && !pass.length) { return }
|
||||
|
||||
console.log('page.do()\'ing: ' + dest)
|
||||
|
||||
if (!user) {
|
||||
return swal('Error', 'You need to specify a username', 'error')
|
||||
@ -17,51 +26,70 @@ page.do = async dest => {
|
||||
return swal('Error', 'You need to specify a username', 'error')
|
||||
}
|
||||
|
||||
const response = await axios.post(`api/${dest}`, {
|
||||
axios.post(`api/${dest}`, {
|
||||
username: user,
|
||||
password: pass
|
||||
})
|
||||
.catch(error => {
|
||||
.then(function (response) {
|
||||
if (response.data.success === false) {
|
||||
return swal('Error', response.data.description, 'error')
|
||||
}
|
||||
|
||||
localStorage.token = response.data.token
|
||||
window.location = 'dashboard'
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error)
|
||||
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
})
|
||||
if (!response) { return }
|
||||
|
||||
if (response.data.success === false) {
|
||||
return swal('Error', response.data.description, 'error')
|
||||
}
|
||||
|
||||
localStorage.token = response.data.token
|
||||
window.location = 'dashboard'
|
||||
}
|
||||
|
||||
page.verify = async () => {
|
||||
page.verify = function () {
|
||||
if (!page.token) { return }
|
||||
|
||||
const response = await axios.post('api/tokens/verify', {
|
||||
axios.post('api/tokens/verify', {
|
||||
token: page.token
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error)
|
||||
swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
.then(function (response) {
|
||||
if (response.data.success === false) {
|
||||
return swal('Error', response.data.description, 'error')
|
||||
}
|
||||
|
||||
window.location = 'dashboard'
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error)
|
||||
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
})
|
||||
if (!response) { return }
|
||||
|
||||
if (response.data.success === false) {
|
||||
return swal('Error', response.data.description, 'error')
|
||||
}
|
||||
|
||||
window.location = 'dashboard'
|
||||
}
|
||||
|
||||
window.onload = () => {
|
||||
page.formEnter = function (event) {
|
||||
if (event.keyCode === 13 || event.which === 13) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
page.do('login', true)
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
page.verify()
|
||||
|
||||
document.body.addEventListener('keydown', event => {
|
||||
event = event || window.event
|
||||
if (!event) { return }
|
||||
const id = event.target.id
|
||||
if (!['user', 'pass'].includes(id)) { return }
|
||||
if (event.keyCode === 13 || event.which === 13) { page.do('login') }
|
||||
page.user = document.getElementById('user')
|
||||
page.pass = document.getElementById('pass')
|
||||
|
||||
var form = document.getElementById('authForm')
|
||||
form.addEventListener('keyup', page.formEnter)
|
||||
form.addEventListener('keypress', page.formEnter)
|
||||
form.onsubmit = function (event) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
}
|
||||
|
||||
document.getElementById('loginBtn').addEventListener('click', function () {
|
||||
page.do('login')
|
||||
})
|
||||
|
||||
document.getElementById('registerBtn').addEventListener('click', function () {
|
||||
page.do('register')
|
||||
})
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
/* global swal, axios, Dropzone, ClipboardJS, LazyLoad */
|
||||
|
||||
const page = {
|
||||
var page = {
|
||||
// user token
|
||||
token: localStorage.token,
|
||||
|
||||
@ -21,32 +21,32 @@ const page = {
|
||||
lazyLoad: null
|
||||
}
|
||||
|
||||
const imageExtensions = ['.webp', '.jpg', '.jpeg', '.bmp', '.gif', '.png']
|
||||
var imageExtensions = ['.webp', '.jpg', '.jpeg', '.bmp', '.gif', '.png']
|
||||
|
||||
page.checkIfPublic = async () => {
|
||||
const response = await axios.get('api/check')
|
||||
.catch(error => {
|
||||
page.checkIfPublic = function () {
|
||||
axios.get('api/check')
|
||||
.then(function (response) { page.private = response.data.private
|
||||
page.enableUserAccounts = response.data.enableUserAccounts
|
||||
page.maxFileSize = response.data.maxFileSize
|
||||
page.chunkSize = response.data.chunkSize
|
||||
page.preparePage()
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error)
|
||||
const button = document.getElementById('loginToUpload')
|
||||
var button = document.getElementById('loginToUpload')
|
||||
button.classList.remove('is-loading')
|
||||
button.innerText = 'Error occurred. Reload the page?'
|
||||
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
})
|
||||
if (!response) { return }
|
||||
|
||||
page.private = response.data.private
|
||||
page.enableUserAccounts = response.data.enableUserAccounts
|
||||
page.maxFileSize = response.data.maxFileSize
|
||||
page.chunkSize = response.data.chunkSize
|
||||
page.preparePage()
|
||||
}
|
||||
|
||||
page.preparePage = () => {
|
||||
page.preparePage = function () {
|
||||
if (page.private) {
|
||||
if (page.token) {
|
||||
return page.verifyToken(page.token, true)
|
||||
} else {
|
||||
const button = document.getElementById('loginToUpload')
|
||||
var button = document.getElementById('loginToUpload')
|
||||
button.href = 'auth'
|
||||
button.classList.remove('is-loading')
|
||||
|
||||
@ -61,40 +61,40 @@ page.preparePage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
page.verifyToken = async (token, reloadOnError) => {
|
||||
page.verifyToken = function (token, reloadOnError) {
|
||||
if (reloadOnError === undefined) { reloadOnError = false }
|
||||
|
||||
const response = await axios.post('api/tokens/verify', { token })
|
||||
.catch(error => {
|
||||
axios.post('api/tokens/verify', { token })
|
||||
.then(function (response) {
|
||||
if (response.data.success === false) {
|
||||
return swal({
|
||||
title: 'An error occurred!',
|
||||
text: response.data.description,
|
||||
icon: 'error'
|
||||
})
|
||||
.then(function () {
|
||||
if (!reloadOnError) { return }
|
||||
localStorage.removeItem('token')
|
||||
location.reload()
|
||||
})
|
||||
}
|
||||
|
||||
localStorage.token = token
|
||||
page.token = token
|
||||
return page.prepareUpload()
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error)
|
||||
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
})
|
||||
if (!response) { return }
|
||||
|
||||
if (response.data.success === false) {
|
||||
await swal({
|
||||
title: 'An error occurred!',
|
||||
text: response.data.description,
|
||||
icon: 'error'
|
||||
})
|
||||
if (reloadOnError) {
|
||||
localStorage.removeItem('token')
|
||||
location.reload()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
localStorage.token = token
|
||||
page.token = token
|
||||
return page.prepareUpload()
|
||||
}
|
||||
|
||||
page.prepareUpload = () => {
|
||||
page.prepareUpload = function () {
|
||||
// I think this fits best here because we need to check for a valid token before we can get the albums
|
||||
if (page.token) {
|
||||
page.albumSelect = document.getElementById('albumSelect')
|
||||
|
||||
page.albumSelect.addEventListener('change', () => {
|
||||
page.albumSelect.addEventListener('change', function () {
|
||||
page.album = parseInt(page.albumSelect.value)
|
||||
})
|
||||
|
||||
@ -111,18 +111,18 @@ page.prepareUpload = () => {
|
||||
document.getElementById('loginLinkText').innerHTML = 'Create an account and keep track of your uploads'
|
||||
}
|
||||
|
||||
const previewNode = document.querySelector('#tpl')
|
||||
var previewNode = document.querySelector('#tpl')
|
||||
page.previewTemplate = previewNode.innerHTML
|
||||
previewNode.parentNode.removeChild(previewNode)
|
||||
|
||||
page.prepareDropzone()
|
||||
|
||||
const tabs = document.getElementById('tabs')
|
||||
var tabs = document.getElementById('tabs')
|
||||
if (tabs) {
|
||||
tabs.style.display = 'flex'
|
||||
const items = tabs.getElementsByTagName('li')
|
||||
for (const item of items) {
|
||||
item.addEventListener('click', function () {
|
||||
var items = tabs.getElementsByTagName('li')
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
items[i].addEventListener('click', function () {
|
||||
page.setActiveTab(this.dataset.id)
|
||||
})
|
||||
}
|
||||
@ -135,57 +135,55 @@ page.prepareUpload = () => {
|
||||
}
|
||||
}
|
||||
|
||||
page.prepareAlbums = async () => {
|
||||
const option = document.createElement('option')
|
||||
page.prepareAlbums = function () {
|
||||
var option = document.createElement('option')
|
||||
option.value = ''
|
||||
option.innerHTML = 'Upload to album'
|
||||
option.disabled = true
|
||||
option.selected = true
|
||||
page.albumSelect.appendChild(option)
|
||||
|
||||
const response = await axios.get('api/albums', { headers: { token: page.token } })
|
||||
.catch(error => {
|
||||
axios.get('api/albums', { headers: { token: page.token } })
|
||||
.then(function (response) {
|
||||
if (response.data.success === false) {
|
||||
return swal('An error occurred!', response.data.description, 'error')
|
||||
}
|
||||
|
||||
// If the user doesn't have any albums we don't really need to display
|
||||
// an album selection
|
||||
if (!response.data.albums.length) { return }
|
||||
|
||||
// Loop through the albums and create an option for each album
|
||||
for (var album of response.data.albums) {
|
||||
var option = document.createElement('option')
|
||||
option.value = album.id
|
||||
option.innerHTML = album.name
|
||||
page.albumSelect.appendChild(option)
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error)
|
||||
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
})
|
||||
if (!response) { return }
|
||||
|
||||
if (response.data.success === false) {
|
||||
return swal('An error occurred!', response.data.description, 'error')
|
||||
}
|
||||
|
||||
const albums = response.data.albums
|
||||
|
||||
// If the user doesn't have any albums we don't really need to display
|
||||
// an album selection
|
||||
if (albums.length === 0) { return }
|
||||
|
||||
// Loop through the albums and create an option for each album
|
||||
for (const album of albums) {
|
||||
const option = document.createElement('option')
|
||||
option.value = album.id
|
||||
option.innerHTML = album.name
|
||||
page.albumSelect.appendChild(option)
|
||||
}
|
||||
}
|
||||
|
||||
page.setActiveTab = activeId => {
|
||||
const items = document.getElementById('tabs').getElementsByTagName('li')
|
||||
for (const item of items) {
|
||||
const tabId = item.dataset.id
|
||||
page.setActiveTab = function (activeId) {
|
||||
var items = document.getElementById('tabs').getElementsByTagName('li')
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var tabId = items[i].dataset.id
|
||||
if (tabId === activeId) {
|
||||
item.classList.add('is-active')
|
||||
items[i].classList.add('is-active')
|
||||
document.getElementById(tabId).style.display = 'block'
|
||||
} else {
|
||||
item.classList.remove('is-active')
|
||||
items[i].classList.remove('is-active')
|
||||
document.getElementById(tabId).style.display = 'none'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
page.prepareDropzone = () => {
|
||||
const tabDiv = document.getElementById('tab-files')
|
||||
const div = document.createElement('div')
|
||||
page.prepareDropzone = function () {
|
||||
var tabDiv = document.getElementById('tab-files')
|
||||
var div = document.createElement('div')
|
||||
div.className = 'control is-expanded'
|
||||
div.innerHTML = `
|
||||
<div id="dropzone" class="button is-danger is-fullwidth is-unselectable">
|
||||
@ -197,7 +195,7 @@ page.prepareDropzone = () => {
|
||||
`
|
||||
tabDiv.getElementsByClassName('dz-container')[0].appendChild(div)
|
||||
|
||||
const previewsContainer = tabDiv.getElementsByClassName('uploads')[0]
|
||||
var previewsContainer = tabDiv.getElementsByClassName('uploads')[0]
|
||||
page.dropzone = new Dropzone('#dropzone', {
|
||||
url: 'api/upload',
|
||||
paramName: 'files[]',
|
||||
@ -213,12 +211,12 @@ page.prepareDropzone = () => {
|
||||
chunking: Boolean(page.chunkSize),
|
||||
chunkSize: parseInt(page.chunkSize) * 1000000, // 1000000 B = 1 MB,
|
||||
parallelChunkUploads: false, // when set to true, sometimes it often hangs with hundreds of parallel uploads
|
||||
chunksUploaded: async (file, done) => {
|
||||
chunksUploaded: function (file, done) {
|
||||
file.previewElement.querySelector('.progress').setAttribute('value', 100)
|
||||
file.previewElement.querySelector('.progress').innerHTML = '100%'
|
||||
|
||||
// The API supports an array of multiple files
|
||||
const response = await axios.post('api/upload/finishchunks',
|
||||
return axios.post('api/upload/finishchunks',
|
||||
{
|
||||
files: [{
|
||||
uuid: file.upload.uuid,
|
||||
@ -229,47 +227,51 @@ page.prepareDropzone = () => {
|
||||
albumid: page.album
|
||||
}]
|
||||
},
|
||||
{ headers: { token: page.token } })
|
||||
.then(response => response.data)
|
||||
.catch(error => {
|
||||
{
|
||||
headers: {
|
||||
token: page.token
|
||||
}
|
||||
})
|
||||
.then(function (response) {
|
||||
file.previewElement.querySelector('.progress').style.display = 'none'
|
||||
|
||||
if (response.data.success === false) {
|
||||
file.previewElement.querySelector('.error').innerHTML = response.data.description
|
||||
}
|
||||
|
||||
if (response.data.files && response.data.files[0]) {
|
||||
page.updateTemplate(file, response.data.files[0])
|
||||
}
|
||||
return done()
|
||||
})
|
||||
.catch(function (error) {
|
||||
return {
|
||||
success: false,
|
||||
description: error.toString()
|
||||
}
|
||||
})
|
||||
|
||||
file.previewElement.querySelector('.progress').style.display = 'none'
|
||||
|
||||
if (response.success === false) {
|
||||
file.previewElement.querySelector('.error').innerHTML = response.description
|
||||
}
|
||||
|
||||
if (response.files && response.files[0]) {
|
||||
page.updateTemplate(file, response.files[0])
|
||||
}
|
||||
return done()
|
||||
}
|
||||
})
|
||||
|
||||
page.dropzone.on('addedfile', file => {
|
||||
page.dropzone.on('addedfile', function (file) {
|
||||
tabDiv.getElementsByClassName('uploads')[0].style.display = 'block'
|
||||
file.previewElement.querySelector('.name').innerHTML = file.name
|
||||
})
|
||||
|
||||
// Add the selected albumid, if an album is selected, as a header
|
||||
page.dropzone.on('sending', (file, xhr, formData) => {
|
||||
page.dropzone.on('sending', function (file, xhr) {
|
||||
if (file.upload.chunked) { return }
|
||||
if (page.album) { xhr.setRequestHeader('albumid', page.album) }
|
||||
})
|
||||
|
||||
// Update the total progress bar
|
||||
page.dropzone.on('uploadprogress', (file, progress, bytesSent) => {
|
||||
page.dropzone.on('uploadprogress', function (file, progress) {
|
||||
if (file.upload.chunked && progress === 100) { return }
|
||||
file.previewElement.querySelector('.progress').setAttribute('value', progress)
|
||||
file.previewElement.querySelector('.progress').innerHTML = `${progress}%`
|
||||
})
|
||||
|
||||
page.dropzone.on('success', (file, response) => {
|
||||
page.dropzone.on('success', function (file, response) {
|
||||
if (!response) { return }
|
||||
file.previewElement.querySelector('.progress').style.display = 'none'
|
||||
// file.previewElement.querySelector('.name').innerHTML = file.name
|
||||
@ -283,7 +285,7 @@ page.prepareDropzone = () => {
|
||||
}
|
||||
})
|
||||
|
||||
page.dropzone.on('error', (file, error) => {
|
||||
page.dropzone.on('error', function (file, error) {
|
||||
file.previewElement.querySelector('.progress').style.display = 'none'
|
||||
file.previewElement.querySelector('.name').innerHTML = file.name
|
||||
file.previewElement.querySelector('.error').innerHTML = error
|
||||
@ -292,43 +294,57 @@ page.prepareDropzone = () => {
|
||||
page.prepareShareX()
|
||||
}
|
||||
|
||||
page.uploadUrls = async button => {
|
||||
const tabDiv = document.getElementById('tab-urls')
|
||||
page.uploadUrls = function (button) {
|
||||
var tabDiv = document.getElementById('tab-urls')
|
||||
if (!tabDiv) { return }
|
||||
|
||||
if (button.classList.contains('is-loading')) { return }
|
||||
button.classList.add('is-loading')
|
||||
|
||||
await new Promise(async (resolve, reject) => {
|
||||
const albumid = page.album
|
||||
const previewsContainer = tabDiv.getElementsByClassName('uploads')[0]
|
||||
const urls = document.getElementById('urls').value
|
||||
function done(error) {
|
||||
if (error) { swal('An error occurred!', error, 'error') }
|
||||
button.classList.remove('is-loading')
|
||||
}
|
||||
|
||||
function run() {
|
||||
var albumid = page.album
|
||||
var previewsContainer = tabDiv.getElementsByClassName('uploads')[0]
|
||||
var urls = document.getElementById('urls').value
|
||||
.split(/\r?\n/)
|
||||
.filter(url => url.trim().length)
|
||||
.filter(function (url) { return url.trim().length })
|
||||
document.getElementById('urls').value = urls.join('\n')
|
||||
|
||||
if (!urls.length) {
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
return reject('You have not entered any URLs.')
|
||||
return done('You have not entered any URLs.')
|
||||
}
|
||||
|
||||
tabDiv.getElementsByClassName('uploads')[0].style.display = 'block'
|
||||
const files = urls.map(url => {
|
||||
const previewTemplate = document.createElement('template')
|
||||
var files = urls.map(function (url) {
|
||||
var previewTemplate = document.createElement('template')
|
||||
previewTemplate.innerHTML = page.previewTemplate.trim()
|
||||
const previewElement = previewTemplate.content.firstChild
|
||||
var previewElement = previewTemplate.content.firstChild
|
||||
previewElement.querySelector('.name').innerHTML = url
|
||||
previewsContainer.appendChild(previewElement)
|
||||
return {
|
||||
url,
|
||||
previewElement
|
||||
}
|
||||
return { url, previewElement }
|
||||
})
|
||||
|
||||
const post = async i => {
|
||||
if (i === files.length) { return resolve() }
|
||||
const file = files[i]
|
||||
const response = await axios.post('api/upload',
|
||||
function post(i) {
|
||||
if (i === files.length) { return done() }
|
||||
|
||||
var file = files[i]
|
||||
|
||||
function posted(result) {
|
||||
file.previewElement.querySelector('.progress').style.display = 'none'
|
||||
if (result.success) {
|
||||
page.updateTemplate(file, result.files[0])
|
||||
} else {
|
||||
file.previewElement.querySelector('.error').innerHTML = result.description
|
||||
}
|
||||
return post(i + 1)
|
||||
}
|
||||
|
||||
axios.post('api/upload',
|
||||
{
|
||||
urls: [file.url]
|
||||
},
|
||||
@ -338,41 +354,32 @@ page.uploadUrls = async button => {
|
||||
albumid
|
||||
}
|
||||
})
|
||||
.then(response => response.data)
|
||||
.catch(error => {
|
||||
return {
|
||||
.then(function (response) {
|
||||
return posted(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
return posted({
|
||||
success: false,
|
||||
description: error.toString()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
file.previewElement.querySelector('.progress').style.display = 'none'
|
||||
if (response.success) {
|
||||
page.updateTemplate(file, response.files[0])
|
||||
} else {
|
||||
file.previewElement.querySelector('.error').innerHTML = response.description
|
||||
}
|
||||
post(i + 1)
|
||||
}
|
||||
post(0)
|
||||
}).catch(error => {
|
||||
swal('An error occurred!', error.toString(), 'error')
|
||||
})
|
||||
|
||||
button.classList.remove('is-loading')
|
||||
return post(0)
|
||||
}
|
||||
return run()
|
||||
}
|
||||
|
||||
page.updateTemplate = (file, response) => {
|
||||
page.updateTemplate = function (file, response) {
|
||||
if (!response.url) { return }
|
||||
|
||||
const a = file.previewElement.querySelector('.link > a')
|
||||
const clipboard = file.previewElement.querySelector('.clipboard-mobile > .clipboard-js')
|
||||
var a = file.previewElement.querySelector('.link > a')
|
||||
var clipboard = file.previewElement.querySelector('.clipboard-mobile > .clipboard-js')
|
||||
a.href = a.innerHTML = clipboard.dataset['clipboardText'] = response.url
|
||||
clipboard.parentElement.style.display = 'block'
|
||||
|
||||
const exec = /.[\w]+(\?|$)/.exec(response.url)
|
||||
var exec = /.[\w]+(\?|$)/.exec(response.url)
|
||||
if (exec && exec[0] && imageExtensions.includes(exec[0].toLowerCase())) {
|
||||
const img = file.previewElement.querySelector('img')
|
||||
var img = file.previewElement.querySelector('img')
|
||||
img.setAttribute('alt', response.name || '')
|
||||
img.dataset['src'] = response.url
|
||||
img.onerror = function () { this.style.display = 'none' } // hide webp in firefox and ie
|
||||
@ -380,10 +387,10 @@ page.updateTemplate = (file, response) => {
|
||||
}
|
||||
}
|
||||
|
||||
page.prepareShareX = () => {
|
||||
page.prepareShareX = function () {
|
||||
if (page.token) {
|
||||
const sharexElement = document.getElementById('ShareX')
|
||||
const sharexFile =
|
||||
var sharexElement = document.getElementById('ShareX')
|
||||
var sharexFile =
|
||||
'{\r\n' +
|
||||
` "Name": "${location.hostname}",\r\n` +
|
||||
' "DestinationType": "ImageUploader, FileUploader",\r\n' +
|
||||
@ -397,14 +404,14 @@ page.prepareShareX = () => {
|
||||
' "URL": "$json:files[0].url$",\r\n' +
|
||||
' "ThumbnailURL": "$json:files[0].url$"\r\n' +
|
||||
'}'
|
||||
const sharexBlob = new Blob([sharexFile], { type: 'application/octet-binary' })
|
||||
var sharexBlob = new Blob([sharexFile], { type: 'application/octet-binary' })
|
||||
sharexElement.setAttribute('href', URL.createObjectURL(sharexBlob))
|
||||
sharexElement.setAttribute('download', `${location.hostname}.sxcu`)
|
||||
}
|
||||
}
|
||||
|
||||
page.createAlbum = async () => {
|
||||
const div = document.createElement('div')
|
||||
page.createAlbum = function () {
|
||||
var div = document.createElement('div')
|
||||
div.innerHTML = `
|
||||
<div class="field">
|
||||
<label class="label">Album name</label>
|
||||
@ -429,7 +436,7 @@ page.createAlbum = async () => {
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
const value = await swal({
|
||||
swal({
|
||||
title: 'Create new album',
|
||||
icon: 'info',
|
||||
content: div,
|
||||
@ -440,61 +447,66 @@ page.createAlbum = async () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
if (!value) { return }
|
||||
.then(function (value) {
|
||||
if (!value) { return }
|
||||
|
||||
const name = document.getElementById('_name').value
|
||||
const response = await axios.post('api/albums', {
|
||||
name,
|
||||
download: document.getElementById('_download').checked,
|
||||
public: document.getElementById('_public').checked
|
||||
}, { headers: { token: page.token } })
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
var name = document.getElementById('_name').value
|
||||
axios.post('api/albums', {
|
||||
name,
|
||||
download: document.getElementById('_download').checked,
|
||||
public: document.getElementById('_public').checked
|
||||
}, { headers: { token: page.token } })
|
||||
.then(function (response) {
|
||||
if (response.data.success === false) {
|
||||
return swal('An error occurred!', response.data.description, 'error')
|
||||
}
|
||||
|
||||
var option = document.createElement('option')
|
||||
option.value = response.data.id
|
||||
option.innerHTML = name
|
||||
page.albumSelect.appendChild(option)
|
||||
|
||||
swal('Woohoo!', 'Album was created successfully', 'success')
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error)
|
||||
return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error')
|
||||
})
|
||||
})
|
||||
if (!response) { return }
|
||||
|
||||
if (response.data.success === false) {
|
||||
return swal('An error occurred!', response.data.description, 'error')
|
||||
}
|
||||
|
||||
const option = document.createElement('option')
|
||||
option.value = response.data.id
|
||||
option.innerHTML = name
|
||||
page.albumSelect.appendChild(option)
|
||||
|
||||
swal('Woohoo!', 'Album was created successfully', 'success')
|
||||
}
|
||||
|
||||
// Handle image paste event
|
||||
window.addEventListener('paste', event => {
|
||||
const items = (event.clipboardData || event.originalEvent.clipboardData).items
|
||||
for (const index in items) {
|
||||
const item = items[index]
|
||||
window.addEventListener('paste', function (event) {
|
||||
var items = (event.clipboardData || event.originalEvent.clipboardData).items
|
||||
for (var index in items) {
|
||||
var item = items[index]
|
||||
if (item.kind === 'file') {
|
||||
const blob = item.getAsFile()
|
||||
console.log(blob.type)
|
||||
const file = new File([blob], `pasted-image.${blob.type.match(/(?:[^/]*\/)([^;]*)/)[1]}`)
|
||||
var blob = item.getAsFile()
|
||||
var file = new File([blob], `pasted-image.${blob.type.match(/(?:[^/]*\/)([^;]*)/)[1]}`)
|
||||
file.type = blob.type
|
||||
console.log(file)
|
||||
page.dropzone.addFile(file)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
window.onload = () => {
|
||||
window.onload = function () {
|
||||
page.checkIfPublic()
|
||||
|
||||
page.clipboardJS = new ClipboardJS('.clipboard-js')
|
||||
|
||||
page.clipboardJS.on('success', () => {
|
||||
page.clipboardJS.on('success', function () {
|
||||
return swal('Copied!', 'The link has been copied to clipboard.', 'success')
|
||||
})
|
||||
|
||||
page.clipboardJS.on('error', event => {
|
||||
page.clipboardJS.on('error', function (event) {
|
||||
console.error(event)
|
||||
return swal('An error occurred!', 'There was an error when trying to copy the link to clipboard, please check the console for more information.', 'error')
|
||||
})
|
||||
|
||||
page.lazyLoad = new LazyLoad()
|
||||
|
||||
document.getElementById('createAlbum').addEventListener('click', function () {
|
||||
page.createAlbum()
|
||||
})
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ thumbs.do = async () => {
|
||||
thumbs.force = parseInt(args[1])
|
||||
if ((isNaN(thumbs.mode) || ![1, 2, 3].includes(thumbs.mode)) ||
|
||||
(!isNaN(thumbs.force) && ![0, 1].includes(thumbs.force))) {
|
||||
console.log('Usage : node THIS_FILE <mode=1|2|3> [force=0|1]')
|
||||
console.log('mode : 1 = images only, 2 = videos only, 3 = both images and videos')
|
||||
console.log('force : 0 = no force (default), 1 = overwrite existing thumbnails')
|
||||
console.log('Usage:\nyarn thumbs <mode=1|2|3> [force=0|1]\n')
|
||||
console.log('mode : 1 = images only, 2 = videos only, 3 = both images and videos')
|
||||
console.log('force: 0 = no force (default), 1 = overwrite existing thumbnails')
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
v2: Images and config files (manifest.json, browserconfig.xml, etc).
|
||||
v3: CSS and JS files (libs such as bulma, lazyload, etc).
|
||||
#}
|
||||
{% set v1 = "BvoZYURztW" %}
|
||||
{% set v1 = "iz81GIx05U" %}
|
||||
{% set v2 = "Ii3JYKIhb0" %}
|
||||
{% set v3 = "HrvcYD3KTh" %}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<!-- Scripts -->
|
||||
<script type="text/javascript" src="../libs/lazyload/lazyload.min.js?v={{ globals.v3 }}"></script>
|
||||
<script type="text/javascript" src="../js/album.js?v={{ globals.v1 }}"></script>
|
||||
{% endblock %}
|
||||
|
@ -28,34 +28,36 @@
|
||||
<h2 class="subtitle">
|
||||
Login or register
|
||||
</h2>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<input id="user" class="input" type="text" placeholder="Your username">
|
||||
<form id="authForm">
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<input id="user" name="user" class="input" type="text" placeholder="Your username">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<input id="pass" class="input" type="password" placeholder="Your password">
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<input id="pass" name="pass" class="input" type="password" placeholder="Your password">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field is-grouped is-grouped-right">
|
||||
<div class="control">
|
||||
<a id="registerBtn" class="button" onclick="page.do('register')">
|
||||
<span class="icon">
|
||||
<i class="icon-user-plus"></i>
|
||||
</span>
|
||||
<span>Register</span>
|
||||
</a>
|
||||
<div class="field is-grouped is-grouped-right">
|
||||
<div class="control">
|
||||
<a id="registerBtn" class="button">
|
||||
<span class="icon">
|
||||
<i class="icon-user-plus"></i>
|
||||
</span>
|
||||
<span>Register</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button id="loginBtn" type="submit" class="button">
|
||||
<span class="icon">
|
||||
<i class="icon-login"></i>
|
||||
</span>
|
||||
<span>Log in</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<a id="loginBtn" class="button" onclick="page.do('login')">
|
||||
<span class="icon">
|
||||
<i class="icon-login"></i>
|
||||
</span>
|
||||
<span>Log in</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column is-one-third is-hidden-mobile"></div>
|
||||
</div>
|
||||
|
@ -53,16 +53,16 @@
|
||||
<a href=".">Frontpage</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="itemUploads" onclick="page.getUploads()">Uploads</a>
|
||||
<a id="itemUploads">Uploads</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="itemDeleteByNames" onclick="page.deleteByNames()">Delete by names</a>
|
||||
<a id="itemDeleteByNames">Delete by names</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="menu-label">Albums</p>
|
||||
<ul class="menu-list">
|
||||
<li>
|
||||
<a id="itemManageGallery" onclick="page.getAlbums()">Manage your albums</a>
|
||||
<a id="itemManageGallery">Manage your albums</a>
|
||||
</li>
|
||||
<li>
|
||||
<ul id="albumsContainer"></ul>
|
||||
@ -71,16 +71,16 @@
|
||||
<p class="menu-label">Administration</p>
|
||||
<ul class="menu-list">
|
||||
<li>
|
||||
<a id="itemFileLength" onclick="page.changeFileLength()">File name length</a>
|
||||
<a id="itemFileLength">File name length</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="itemTokens" onclick="page.changeToken()">Manage your token</a>
|
||||
<a id="itemTokens">Manage your token</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="itemPassword" onclick="page.changePassword()">Change your password</a>
|
||||
<a id="itemPassword">Change your password</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="itemLogout" onclick="page.logout()">Logout</a>
|
||||
<a id="itemLogout">Logout</a>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
@ -41,7 +41,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<a class="button is-breeze" title="Create new album" onclick="page.createAlbum()">
|
||||
<a id="createAlbum" class="button is-breeze" title="Create new album">
|
||||
<i class="icon-plus"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user