mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-21 02:31:33 +00:00
feat: list albums' total size and zip size
This commit is contained in:
parent
5d9d499642
commit
cf4a1af209
@ -111,7 +111,7 @@ self.list = async (req, res, next) => {
|
|||||||
if (isNaN(offset)) offset = 0
|
if (isNaN(offset)) offset = 0
|
||||||
else if (offset < 0) offset = Math.max(0, Math.ceil(count / 25) + offset)
|
else if (offset < 0) offset = Math.max(0, Math.ceil(count / 25) + offset)
|
||||||
|
|
||||||
fields.push('identifier', 'enabled', 'timestamp', 'editedAt', 'download', 'public', 'description')
|
fields.push('identifier', 'enabled', 'timestamp', 'editedAt', 'zipGeneratedAt', 'download', 'public', 'description')
|
||||||
if (all) fields.push('userid')
|
if (all) fields.push('userid')
|
||||||
|
|
||||||
albums = await db.table('albums')
|
albums = await db.table('albums')
|
||||||
@ -126,18 +126,34 @@ self.list = async (req, res, next) => {
|
|||||||
album.download = album.download !== 0
|
album.download = album.download !== 0
|
||||||
album.public = album.public !== 0
|
album.public = album.public !== 0
|
||||||
album.uploads = 0
|
album.uploads = 0
|
||||||
|
album.size = 0
|
||||||
|
album.zipSize = null
|
||||||
|
|
||||||
// Map by IDs
|
// Map by IDs
|
||||||
albumids[album.id] = album
|
albumids[album.id] = album
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAlbumZipSize = async album => {
|
||||||
|
if (!album.zipGeneratedAt) return
|
||||||
|
try {
|
||||||
|
const filePath = path.join(paths.zips, `${album.identifier}.zip`)
|
||||||
|
const stats = await paths.stat(filePath)
|
||||||
|
albumids[album.id].zipSize = stats.size
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code !== 'ENOENT') logger.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(albums.map(album => getAlbumZipSize(album)))
|
||||||
|
|
||||||
const uploads = await db.table('files')
|
const uploads = await db.table('files')
|
||||||
.whereIn('albumid', Object.keys(albumids))
|
.whereIn('albumid', Object.keys(albumids))
|
||||||
.select('albumid')
|
.select('albumid', 'size')
|
||||||
|
|
||||||
for (const upload of uploads) {
|
for (const upload of uploads) {
|
||||||
if (albumids[upload.albumid]) {
|
if (albumids[upload.albumid]) {
|
||||||
albumids[upload.albumid].uploads++
|
albumids[upload.albumid].uploads++
|
||||||
|
albumids[upload.albumid].size += parseInt(upload.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ const fsFuncs = [
|
|||||||
'readFile',
|
'readFile',
|
||||||
'rename',
|
'rename',
|
||||||
'rmdir',
|
'rmdir',
|
||||||
|
'stat',
|
||||||
'symlink',
|
'symlink',
|
||||||
'unlink',
|
'unlink',
|
||||||
'writeFile'
|
'writeFile'
|
||||||
|
@ -153,10 +153,19 @@ li[data-action="page-ellipsis"] {
|
|||||||
color: $grey-lightest
|
color: $grey-lightest
|
||||||
}
|
}
|
||||||
|
|
||||||
.table .originalname {
|
.table {
|
||||||
|
.originalname {
|
||||||
max-width: 200px;
|
max-width: 200px;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
|
}
|
||||||
|
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
&[title] {
|
||||||
|
cursor: help
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Thumbs extension **/
|
/** Thumbs extension **/
|
||||||
|
@ -1757,7 +1757,10 @@ page.getAlbums = (params = {}) => {
|
|||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
${params.all ? '<th>User</th>' : ''}
|
${params.all ? '<th>User</th>' : ''}
|
||||||
<th>Uploads</th>
|
<th>Uploads</th>
|
||||||
|
<th>Size</th>
|
||||||
<th>Created at</th>
|
<th>Created at</th>
|
||||||
|
<th>ZIP size</th>
|
||||||
|
<th>ZIP generated at</th>
|
||||||
<th>Public link</th>
|
<th>Public link</th>
|
||||||
<th class="has-text-right">(${response.data.count} total)</th>
|
<th class="has-text-right">(${response.data.count} total)</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -1775,13 +1778,18 @@ page.getAlbums = (params = {}) => {
|
|||||||
|
|
||||||
for (let i = 0; i < albums.length; i++) {
|
for (let i = 0; i < albums.length; i++) {
|
||||||
const album = albums[i]
|
const album = albums[i]
|
||||||
const albumUrl = `${homeDomain}/a/${album.identifier}`
|
const urlPath = '/a/'
|
||||||
|
const albumUrlText = urlPath + album.identifier
|
||||||
|
const albumUrl = homeDomain + albumUrlText
|
||||||
|
|
||||||
const selected = page.selected[page.currentView].includes(album.id)
|
const selected = page.selected[page.currentView].includes(album.id)
|
||||||
if (!selected) unselected = true
|
if (!selected) unselected = true
|
||||||
|
|
||||||
// Prettify
|
// Prettify
|
||||||
|
album.hasZip = album.zipSize !== null
|
||||||
album.prettyDate = page.getPrettyDate(new Date(album.timestamp * 1000))
|
album.prettyDate = page.getPrettyDate(new Date(album.timestamp * 1000))
|
||||||
|
album.prettyZipDate = album.hasZip ? page.getPrettyDate(new Date(album.zipGeneratedAt * 1000)) : null
|
||||||
|
album.isZipExpired = album.hasZip && !(album.zipGeneratedAt > album.editedAt)
|
||||||
|
|
||||||
// Server-side explicitly expect this value to consider an album as disabled
|
// Server-side explicitly expect this value to consider an album as disabled
|
||||||
const enabled = album.enabled !== 0
|
const enabled = album.enabled !== 0
|
||||||
@ -1790,7 +1798,10 @@ page.getAlbums = (params = {}) => {
|
|||||||
download: album.download,
|
download: album.download,
|
||||||
public: album.public,
|
public: album.public,
|
||||||
description: album.description,
|
description: album.description,
|
||||||
enabled
|
enabled,
|
||||||
|
homeDomain,
|
||||||
|
urlPath,
|
||||||
|
identifier: album.identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
const tr = document.createElement('tr')
|
const tr = document.createElement('tr')
|
||||||
@ -1801,8 +1812,11 @@ page.getAlbums = (params = {}) => {
|
|||||||
<th${enabled ? '' : ' class="has-text-grey"'}>${album.name}</td>
|
<th${enabled ? '' : ' class="has-text-grey"'}>${album.name}</td>
|
||||||
${params.all ? `<th>${album.userid ? (users[album.userid] || '') : ''}</th>` : ''}
|
${params.all ? `<th>${album.userid ? (users[album.userid] || '') : ''}</th>` : ''}
|
||||||
<th>${album.uploads}</th>
|
<th>${album.uploads}</th>
|
||||||
|
<td>${page.getPrettyBytes(album.size)}</td>
|
||||||
<td>${album.prettyDate}</td>
|
<td>${album.prettyDate}</td>
|
||||||
<td><a ${enabled && album.public ? '' : 'class="is-linethrough" '}href="${albumUrl}" target="_blank">${albumUrl}</a></td>
|
<td>${album.hasZip ? page.getPrettyBytes(album.zipSize) : '-'}</td>
|
||||||
|
<td${album.isZipExpired ? ' class="has-text-warning" title="This album has been modified since the last time its ZIP was generated."' : ''}>${album.hasZip ? album.prettyZipDate : '-'}</td$>
|
||||||
|
<td><a ${enabled && album.public ? '' : 'class="is-linethrough" '}href="${albumUrl}" target="_blank">${albumUrlText}</a></td>
|
||||||
<td class="has-text-right" data-id="${album.id}">
|
<td class="has-text-right" data-id="${album.id}">
|
||||||
<a class="button is-small is-primary is-outlined" title="Edit album" data-action="edit-album">
|
<a class="button is-small is-primary is-outlined" title="Edit album" data-action="edit-album">
|
||||||
<span class="icon is-small">
|
<span class="icon is-small">
|
||||||
@ -1867,6 +1881,9 @@ page.editAlbum = id => {
|
|||||||
const album = page.cache[id]
|
const album = page.cache[id]
|
||||||
if (!album) return
|
if (!album) return
|
||||||
|
|
||||||
|
const albumUrlText = album.urlPath + album.identifier
|
||||||
|
const albumUrl = album.homeDomain + albumUrlText
|
||||||
|
|
||||||
const div = document.createElement('div')
|
const div = document.createElement('div')
|
||||||
div.innerHTML = `
|
div.innerHTML = `
|
||||||
<div class="field">
|
<div class="field">
|
||||||
@ -1915,6 +1932,9 @@ page.editAlbum = id => {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<p>Current public link: <a href="${albumUrl}" target="_blank" class="is-underline">${albumUrlText}</a></p>
|
||||||
|
</div>
|
||||||
`
|
`
|
||||||
|
|
||||||
swal({
|
swal({
|
||||||
|
Loading…
Reference in New Issue
Block a user