mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
Updates
* New uploads that can NOT be added to an album, for whatever reason, will print out message that they can not be added to the said album, but their links will still also be shown underneath the message. Previously it would only print out the message but not the link. * Improved uploadController.processFilesForDisplay(). Previously it would loop through all uploaded files and update album info for EVERY file, even though to begin with it was designed so that every call would only have to access ONE album. So yeah, this time it will only update album info ONCE no matter how many files are being processed in that session.
This commit is contained in:
parent
ed8a5ed0a9
commit
95de5ee3fd
@ -190,7 +190,7 @@ uploadsController.actuallyUpload = async (req, res, user, albumid) => {
|
||||
.catch(erred)
|
||||
|
||||
if (result) {
|
||||
return uploadsController.processFilesForDisplay(req, res, result.files, result.existingFiles)
|
||||
return uploadsController.processFilesForDisplay(req, res, result.files, result.existingFiles, albumid)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -298,7 +298,7 @@ uploadsController.actuallyFinishChunks = async (req, res, user, albumid) => {
|
||||
.catch(erred)
|
||||
|
||||
if (result) {
|
||||
return uploadsController.processFilesForDisplay(req, res, result.files, result.existingFiles)
|
||||
return uploadsController.processFilesForDisplay(req, res, result.files, result.existingFiles, albumid)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -386,7 +386,7 @@ uploadsController.writeFilesToDb = async (req, res, user, albumid, infoMap) => {
|
||||
})
|
||||
}
|
||||
|
||||
uploadsController.processFilesForDisplay = async (req, res, files, existingFiles) => {
|
||||
uploadsController.processFilesForDisplay = async (req, res, files, existingFiles, albumid) => {
|
||||
let basedomain = config.domain
|
||||
if (files.length === 0) {
|
||||
return res.json({
|
||||
@ -409,28 +409,29 @@ uploadsController.processFilesForDisplay = async (req, res, files, existingFiles
|
||||
files.push(efile)
|
||||
}
|
||||
|
||||
let albumErrored = false
|
||||
await Promise.all(files.map(async file => {
|
||||
files.forEach(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)
|
||||
})
|
||||
}
|
||||
}))
|
||||
let albumSuccess = true
|
||||
if (albumid) {
|
||||
albumSuccess = await db.table('albums')
|
||||
.where('id', albumid)
|
||||
.update('editedAt', files[files.length - 1].timestamp)
|
||||
.then(() => true)
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return res.json({
|
||||
success: !albumErrored,
|
||||
description: albumErrored ? 'Successfully uploaded files but unable to add to album.' : undefined,
|
||||
success: albumSuccess,
|
||||
description: albumSuccess ? null : 'Successfully uploaded file(s) but unable to add to album.',
|
||||
files: files.map(file => {
|
||||
return {
|
||||
name: file.name,
|
||||
|
@ -17,7 +17,7 @@
|
||||
<script type="text/javascript" src="libs/dropzone/dropzone.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/home.js?v=vvtL7Y3cjD"></script>
|
||||
<script type="text/javascript" src="js/home.js?v=6Zr9q4fQ0o"></script>
|
||||
|
||||
<!-- Open Graph tags -->
|
||||
<meta property="og:type" content="website" />
|
||||
|
@ -189,11 +189,12 @@ upload.prepareDropzone = () => {
|
||||
|
||||
if (response.success === false) {
|
||||
file.previewTemplate.querySelector('.error').innerHTML = response.description
|
||||
return done()
|
||||
}
|
||||
|
||||
upload.appendLink(file, response.files[0].url)
|
||||
upload.showThumbnail(file, response.files[0].url)
|
||||
if (response.files && response.files[0] && response.files[0].url) {
|
||||
upload.appendLink(file, response.files[0].url)
|
||||
upload.showThumbnail(file, response.files[0].url)
|
||||
}
|
||||
return done()
|
||||
}
|
||||
})
|
||||
@ -220,11 +221,12 @@ upload.prepareDropzone = () => {
|
||||
|
||||
if (response.success === false) {
|
||||
file.previewTemplate.querySelector('.error').innerHTML = response.description
|
||||
return
|
||||
}
|
||||
|
||||
upload.appendLink(file, response.files[0].url)
|
||||
upload.showThumbnail(file, response.files[0].url)
|
||||
if (response.files && response.files[0] && response.files[0].url) {
|
||||
upload.appendLink(file, response.files[0].url)
|
||||
upload.showThumbnail(file, response.files[0].url)
|
||||
}
|
||||
})
|
||||
|
||||
upload.dropzone.on('error', (file, error) => {
|
||||
|
Loading…
Reference in New Issue
Block a user