* If files have to be added to an album on upload, it will now wait until they have either been succesfully added to the album or errored.

* File names in thumb view will now show their full URL on their tooltip.
This commit is contained in:
Bobby Wibowo 2018-04-05 00:38:15 +07:00
parent b31f28ddcf
commit 7f10cccf70
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
5 changed files with 30 additions and 24 deletions

View File

@ -409,8 +409,28 @@ uploadsController.processFilesForDisplay = async (req, res, files, existingFiles
files.push(efile)
}
res.json({
success: true,
let albumErrored = false
await Promise.all(files.map(async file => {
const ext = path.extname(file.name).toLowerCase()
if ((config.uploads.generateThumbnails.image && utils.imageExtensions.includes(ext)) || (config.uploads.generateThumbnails.video && utils.videoExtensions.includes(ext))) {
file.thumb = `${basedomain}/thumbs/${file.name.slice(0, -ext.length)}.png`
utils.generateThumbs(file)
}
if (file.albumid) {
return db.table('albums')
.where('id', file.albumid)
.update('editedAt', file.timestamp)
.catch(error => {
albumErrored = true
console.log(error)
})
}
}))
return res.json({
success: !albumErrored,
description: albumErrored ? 'Successfully uploaded files but unable to add to album.' : undefined,
files: files.map(file => {
return {
name: file.name,
@ -419,22 +439,6 @@ uploadsController.processFilesForDisplay = async (req, res, files, existingFiles
}
})
})
for (let file of files) {
let ext = path.extname(file.name).toLowerCase()
if ((config.uploads.generateThumbnails.image && utils.imageExtensions.includes(ext)) || (config.uploads.generateThumbnails.video && utils.videoExtensions.includes(ext))) {
file.thumb = `${basedomain}/thumbs/${file.name.slice(0, -ext.length)}.png`
utils.generateThumbs(file)
}
if (file.albumid) {
db.table('albums')
.where('id', file.albumid)
.update('editedAt', file.timestamp)
.then(() => {})
.catch(error => { console.log(error); res.json({ success: false, description: 'Error updating album.' }) })
}
}
}
uploadsController.delete = async (req, res) => {

View File

@ -56,9 +56,11 @@ utilsController.generateThumbs = (file, basedomain) => {
const isVideoExt = utilsController.videoExtensions.includes(ext)
const isImageExt = utilsController.imageExtensions.includes(ext)
if (!isVideoExt && !isImageExt) { return }
if (isVideoExt && config.uploads.generateThumbnails.video !== true) { return }
if (isImageExt && config.uploads.generateThumbnails.image !== true) { return }
if ((!isVideoExt && !isImageExt) ||
(isVideoExt && config.uploads.generateThumbnails.video !== true) ||
(isImageExt && config.uploads.generateThumbnails.image !== true)) {
return
}
let thumbname = path.join(__dirname, '..', config.uploads.folder, 'thumbs', file.name.slice(0, -ext.length) + '.png')
fs.access(thumbname, error => {

View File

@ -35,7 +35,7 @@ safe.use(bodyParser.json())
const setHeaders = (res, path, stat) => {
if (/\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|js|css|eot|svg|ttf|woff|woff2)$/.test(path)) {
res.set('Access-Control-Allow-Origin', '*')
res.set('Cache-Control', `public, max-age=2592000, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800`) // max-age: 30 days
res.set('Cache-Control', 'public, max-age=2592000, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800') // max-age: 30 days
}
}

View File

@ -17,7 +17,7 @@
<script type="text/javascript" src="libs/sweetalert/sweetalert.min.js?v=vvtL7Y3cjD"></script>
<script type="text/javascript" src="libs/axios/axios.min.js?v=vvtL7Y3cjD"></script>
<script type="text/javascript" src="libs/clipboard.js/clipboard.min.js?v=vvtL7Y3cjD"></script>
<script type="text/javascript" src="js/dashboard.js?v=U4oQBt8aIF"></script>
<script type="text/javascript" src="js/dashboard.js?v=pH3317eTYZ"></script>
<!-- Open Graph tags -->
<meta property="og:type" content="website" />

View File

@ -218,7 +218,7 @@ panel.getUploads = (album, page, element) => {
</a>
</div>
<div class="details">
<p><span class="name">${file.name}</span></p>
<p><span class="name" title="${file.file}">${file.name}</span></p>
<p>${displayAlbumOrUser ? `<span>${displayAlbumOrUser}</span> ` : ''}${file.size}</div>
`
table.appendChild(div)