diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 965a397..3eadf88 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -1651,14 +1651,19 @@ self.list = async (req, res) => { offset = Math.max(0, Math.ceil(result.count / uploadsPerPage) + offset) } + // Database columns to query const columns = ['id', 'name', 'original', 'userid', 'size', 'timestamp'] + if (utils.retentions.enabled) { columns.push('expirydate') } - if (!all || - filterObj.queries.albumid || + + const filterByAlbums = filterObj.queries.albumid || filterObj.queries.exclude.albumid || - filterObj.flags.albumidNull !== undefined) { + filterObj.flags.albumidNull !== undefined + + // If not listing all uploads, OR specifically filtering by album IDs + if (!all || filterByAlbums) { columns.push('albumid') } @@ -1702,16 +1707,23 @@ self.list = async (req, res) => { result.albums = {} - // If we queried albumid, query album names - if (columns.includes('albumid')) { + // If not listing all uploads, OR specifically filtering by album IDs + if (!all || filterByAlbums) { const albumids = result.files .map(file => file.albumid) .filter(utils.filterUniquifySqlArray) result.albums = await utils.db.table('albums') - .whereIn('id', albumids) - .where('enabled', 1) - .select('id', 'name') + .where(function () { + this.whereIn('id', albumids) + + // Only include data of disabled albums if listing all uploads + // and filtering by album IDs + if (!all) { + this.andWhere('enabled', 1) + } + }) + .select('id', 'name', 'enabled') .then(rows => { // Build Object indexed by their IDs const obj = {} @@ -1720,12 +1732,19 @@ self.list = async (req, res) => { } return obj }) + + // If filtering by album IDs, + // then filter out uploads with missing albums data (assume disabled/deleted) + if (filterByAlbums) { + result.files = result.files.filter(file => result.albums[file.albumid] !== undefined) + } } // If we are not listing all uploads, send response if (!all) { return res.json(result) } + // Otherwise proceed to querying usernames let usersTable = filterObj.uploaders if (!usersTable.length) { diff --git a/src/js/dashboard.js b/src/js/dashboard.js index 272e857..ae30dc8 100644 --- a/src/js/dashboard.js +++ b/src/js/dashboard.js @@ -674,8 +674,9 @@ page.getUploads = (params = {}) => { // Whether there are any unselected items let unselected = false - const showOriginalNames = page.views[page.currentView].originalNames + const filterAllByAlbums = params.all && params.filters && params.filters.includes('albumid:') const hasExpiryDateColumn = files.some(file => typeof file.expirydate !== 'undefined') + const showOriginalNames = page.views[page.currentView].originalNames for (let i = 0; i < files.length; i++) { // Build full URLs @@ -710,8 +711,14 @@ page.getUploads = (params = {}) => { } // Prettify + files[i].prettyAlbum = (albums && files[i].albumid && albums[files[i].albumid]) + ? `[${files[i].albumid}] ${albums[files[i].albumid]}` || '' + : '' files[i].prettyBytes = page.getPrettyBytes(parseInt(files[i].size)) files[i].prettyDate = page.getPrettyDate(new Date(files[i].timestamp * 1000)) + files[i].prettyUser = (users && files[i].userid && users[files[i].userid]) + ? users[files[i].userid] + : '' if (hasExpiryDateColumn) { files[i].prettyExpiryDate = files[i].expirydate @@ -724,17 +731,6 @@ page.getUploads = (params = {}) => { if (!files[i].selected) { unselected = true } - - // Appendix (display album or user) - if (params.all) { - files[i].appendix = files[i].userid - ? users[files[i].userid] || '' - : '' - } else if (typeof params.album === 'undefined') { - files[i].appendix = files[i].albumid - ? `[${files[i].albumid}] ${albums[files[i].albumid]}` || '' - : '' - } } if (page.views[page.currentView].type === 'thumbs') { @@ -753,14 +749,22 @@ page.getUploads = (params = {}) => { for (let i = 0; i < files.length; i++) { const upload = files[i] + let appendix = '' + if (params.all) { + appendix += upload.prettyUser ? `${upload.prettyUser} \u2013 ` : '' + } + if (!params.all || filterAllByAlbums) { + appendix += upload.prettyAlbum ? `${upload.prettyAlbum} \u2013 ` : '' + } + const div = document.createElement('div') div.className = 'image-container column' div.dataset.id = upload.id - if (typeof upload.thumb !== 'undefined') { - div.innerHTML = `${upload.name}` - } else { + if (upload.thumb === undefined) { div.innerHTML = `

${upload.extname || 'N/A'}

` + } else { + div.innerHTML = `${upload.name}` } div.innerHTML += ` @@ -797,7 +801,7 @@ page.getUploads = (params = {}) => {

${upload.name}

${showOriginalNames ? `

${upload.original}

` : ''} -

${upload.appendix ? `${upload.appendix} – ` : ''}${upload.prettyBytes}

+

${appendix}${upload.prettyBytes}

${hasExpiryDateColumn && upload.prettyExpiryDate ? `

EXP: ${upload.prettyExpiryDate}

` : ''} @@ -808,7 +812,6 @@ page.getUploads = (params = {}) => { page.checkboxes = table.querySelectorAll('.checkbox[data-action="select"]') } } else { - const allAlbums = params.all && params.filters && params.filters.includes('albumid:') page.dom.innerHTML = ` ${pagination} ${extraControls} @@ -820,8 +823,8 @@ page.getUploads = (params = {}) => { File name ${showOriginalNames ? 'Original name' : ''} - ${typeof params.album === 'undefined' ? `User' : 'albumid">Album'}` : ''} - ${allAlbums ? 'Album' : ''} + ${params.all ? 'User' : ''} + ${!params.all || filterAllByAlbums ? 'Album' : ''} Size ${params.all ? 'IP' : ''} Upload date @@ -842,14 +845,15 @@ page.getUploads = (params = {}) => { for (let i = 0; i < files.length; i++) { const upload = files[i] + const tr = document.createElement('tr') tr.dataset.id = upload.id tr.innerHTML = ` ${upload.name} ${showOriginalNames ? `${upload.original}` : ''} - ${typeof params.album === 'undefined' ? `${upload.appendix}` : ''} - ${allAlbums ? `${upload.albumid ? (`[${upload.albumid}] ${albums[upload.albumid]}` || '') : ''}` : ''} + ${params.all ? `${upload.prettyUser}` : ''} + ${!params.all || filterAllByAlbums ? `${upload.prettyAlbum}` : ''} ${upload.prettyBytes} ${params.all ? `${upload.ip || ''}` : ''} ${upload.prettyDate}