Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin page display download count #297

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions app/src/Admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
th SID
th Created
th Downloaded
th Download Count
th Expire
th Size
template(v-for="(bucket, sid) in db")
Expand All @@ -37,6 +38,7 @@
td
template(v-if="sum[sid].lastDownload") {{ sum[sid].lastDownload | date}}
template(v-else="") -
td {{ sum[sid].downloadCountPre }} {{ sum[sid].downloadCount }}
td
template(v-if="typeof sum[sid].firstExpire === 'number'") {{ sum[sid].firstExpire | date }}
template(v-else) {{ sum[sid].firstExpire }}
Expand All @@ -49,13 +51,14 @@
td
template(v-if="file.metadata.lastDownload") {{ +file.metadata.lastDownload | date}}
template(v-else="") -
td {{ file.metadata.downloadCount }}
td
template(v-if="typeof file.expireDate === 'number'") {{ file.expireDate | date }}
template(v-else) {{ file.expireDate }}
td.text-right {{ humanFileSize(file.size) }}
tfoot
tr
td(colspan="3")
td(colspan="4")
td.text-right(colspan="2") Sum: {{ humanFileSize(sizeSum) }}

</template>
Expand Down Expand Up @@ -123,10 +126,19 @@
lastDownload: 0,
created: Number.MAX_SAFE_INTEGER,
password: false,
size: 0
size: 0,
downloadCount:0,
downloadCountPre: "",
};
this.db[sid].forEach(file => {
bucketSum.size += file.size;

if(bucketSum.downloadCount == undefined) {
bucketSum.downloadCount = isNaN(file.metadata.downloadCount) ? "-" : file.metadata.downloadCount;
} else if(bucketSum.downloadCount != file.metadata.downloadCount ) {
bucketSum.downloadCountPre = bucketSum.downloadCount != 0 ? "~" : "";
bucketSum.downloadCount = bucketSum.downloadCount < file.metadata.downloadCount ? file.metadata.downloadCount : bucketSum.downloadCount;
}
if(file.metadata._password) {
bucketSum.password = true;
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/Download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
i.pull-right.fa.fa-check.text-success.downloaded(v-show='file.downloaded')
p
strong {{ file.metadata.name }}
small.file-size(v-if="isFinite(file.size)") ({{ humanFileSize(file.size) }})
small.file-size(v-if="isFinite(file.size)") ({{ humanFileSize(file.size) }})
small(v-if="!isNaN(file.metadata.downloadCount)" style="padding-left:10px;")
icon.fa-fw(name="download")
strong(style="padding-left:5px;") {{file.metadata.downloadCount}}
p {{ file.metadata.comment }}

preview-modal(:preview="preview", :files="previewFiles", :max-size="config.maxPreviewSize", @close="preview=false")
Expand Down Expand Up @@ -124,6 +127,7 @@
aEl.click();
document.body.removeChild(aEl);
file.downloaded = true;
file.metadata.downloadCount = isNaN(file.metadata.downloadCount) ? 1 : ++file.metadata.downloadCount;
},

downloadAll(format) {
Expand All @@ -137,6 +141,7 @@

this.files.forEach(f => {
f.downloaded = true;
f.metadata.downloadCount = isNaN(f.metadata.downloadCount) ? 1 : ++f.metadata.downloadCount;
});
},

Expand Down
1 change: 1 addition & 0 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module.exports = class DB {
const data = this.get(sid).find(item => item.key === key);
if(!data) return;
data.metadata.lastDownload = Date.now();
data.metadata.downloadCount = isNaN(data.metadata.downloadCount) ? 1 : ++data.metadata.downloadCount
await this.store.update(`${sid}++${key}`, data);
}

Expand Down