Added disk usage column to manage users

This commit is contained in:
Bobby Wibowo 2018-10-12 17:19:14 +07:00
parent 31f44a1b91
commit 8e46eaf4ac
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
3 changed files with 43 additions and 38 deletions

View File

@ -248,6 +248,8 @@ authController.listUsers = async (req, res, next) => {
.offset(25 * offset)
.select('id', 'username', 'enabled', 'fileLength', 'permission')
if (!users.length) { return res.json({ success: true, users }) }
const userids = []
for (const user of users) {
@ -256,20 +258,23 @@ authController.listUsers = async (req, res, next) => {
userids.push(user.id)
user.uploadsCount = 0
user.diskUsage = 0
}
if (!userids.length) { return res.json({ success: true, users }) }
const maps = {}
const uploads = await db.table('files').whereIn('userid', userids)
for (const upload of uploads) {
// This is the fastest method that I can think of
if (maps[upload.userid] === undefined) { maps[upload.userid] = 0 }
maps[upload.userid]++
if (maps[upload.userid] === undefined) { maps[upload.userid] = { count: 0, size: 0 } }
maps[upload.userid].count++
maps[upload.userid].size += parseInt(upload.size)
}
for (const user of users) {
user.uploadsCount = maps[user.id] || 0
if (!maps[user.id]) { continue }
user.uploadsCount = maps[user.id].count
user.diskUsage = maps[user.id].size
}
return res.json({ success: true, users })

View File

@ -456,7 +456,7 @@ page.getUploads = function ({ album, pageNum, all } = {}, element) {
const tr = document.createElement('tr')
tr.dataset.id = upload.id
tr.innerHTML = `
<th class="controls"><input type="checkbox" class="checkbox" title="Select this file" data-action="select"${selected ? ' checked' : ''}></th>
<td class="controls"><input type="checkbox" class="checkbox" title="Select this file" data-action="select"${selected ? ' checked' : ''}></td>
<th><a href="${upload.file}" target="_blank" rel="noopener" title="${upload.file}">${upload.name}</a></th>
<th>${displayAlbumOrUser}</th>
<td>${upload.prettyBytes}</td>
@ -1010,35 +1010,33 @@ page.getAlbums = function () {
const tr = document.createElement('tr')
tr.innerHTML = `
<tr>
<th>${album.id}</th>
<th>${album.name}</th>
<th>${album.files}</th>
<td>${album.prettyDate}</td>
<td><a ${album.public ? `href="${albumUrl}"` : 'class="is-linethrough"'} target="_blank" rel="noopener">${albumUrl}</a></td>
<td style="text-align: right" data-id="${album.id}">
<a class="button is-small is-primary" title="Edit album" data-action="edit-album">
<span class="icon is-small">
<i class="icon-pencil-1"></i>
</span>
</a>
<a class="button is-small is-info clipboard-js" title="Copy link to clipboard" ${album.public ? `data-clipboard-text="${albumUrl}"` : 'disabled'}>
<span class="icon is-small">
<i class="icon-clipboard-1"></i>
</span>
</a>
<a class="button is-small is-warning" title="Download album" ${album.download ? `href="api/album/zip/${album.identifier}?v=${album.editedAt}"` : 'disabled'}>
<span class="icon is-small">
<i class="icon-download"></i>
</span>
</a>
<a class="button is-small is-danger" title="Delete album" data-action="delete-album">
<span class="icon is-small">
<i class="icon-trash"></i>
</span>
</a>
</td>
</tr>
<th>${album.id}</th>
<th>${album.name}</th>
<th>${album.files}</th>
<td>${album.prettyDate}</td>
<td><a ${album.public ? `href="${albumUrl}"` : 'class="is-linethrough"'} target="_blank" rel="noopener">${albumUrl}</a></td>
<td style="text-align: right" data-id="${album.id}">
<a class="button is-small is-primary" title="Edit album" data-action="edit-album">
<span class="icon is-small">
<i class="icon-pencil-1"></i>
</span>
</a>
<a class="button is-small is-info clipboard-js" title="Copy link to clipboard" ${album.public ? `data-clipboard-text="${albumUrl}"` : 'disabled'}>
<span class="icon is-small">
<i class="icon-clipboard-1"></i>
</span>
</a>
<a class="button is-small is-warning" title="Download album" ${album.download ? `href="api/album/zip/${album.identifier}?v=${album.editedAt}"` : 'disabled'}>
<span class="icon is-small">
<i class="icon-download"></i>
</span>
</a>
<a class="button is-small is-danger" title="Delete album" data-action="delete-album">
<span class="icon is-small">
<i class="icon-trash"></i>
</span>
</a>
</td>
`
table.appendChild(tr)
@ -1572,6 +1570,7 @@ page.getUsers = ({ pageNum } = {}, element) => {
<th>ID</th>
<th style="width: 25%">Username</th>
<th>Uploads</th>
<th>Usage</th>
<th>File length</th>
<th>Group</th>
<th></th>
@ -1610,10 +1609,11 @@ page.getUsers = ({ pageNum } = {}, element) => {
const tr = document.createElement('tr')
tr.dataset.id = user.id
tr.innerHTML = `
<th class="controls"><input type="checkbox" class="checkbox" title="Select this user" data-action="select"${selected ? ' checked' : ''}></th>
<td class="controls"><input type="checkbox" class="checkbox" title="Select this user" data-action="select"${selected ? ' checked' : ''}></td>
<th>${user.id}</th>
<th${enabled ? '' : ' class="is-linethrough"'}>${user.username}</th>
<th${enabled ? '' : ' class="is-linethrough"'}>${user.username}</td>
<th>${user.uploadsCount}</th>
<td>${page.getPrettyBytes(user.diskUsage)}</td>
<td>${user.fileLength || 'default'}</td>
<td>${displayGroup}</td>
<td class="controls" style="text-align: right">

View File

@ -15,7 +15,7 @@
v2: Images and config files (manifest.json, browserconfig.xml, etc).
v3: CSS and JS files (libs such as bulma, lazyload, etc).
#}
{% set v1 = "fvsYyXUQZE" %}
{% set v1 = "C77dh2BOT7" %}
{% set v2 = "Ii3JYKIhb0" %}
{% set v3 = "4TRCinLWfk" %}