Skip to content

Commit e017ff4

Browse files
committed
Add download count psi-4ward#297
1 parent fac9529 commit e017ff4

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

app/src/Admin.vue

+13-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
th SID
2626
th Created
2727
th Downloaded
28+
th Download Count
2829
th Expire
2930
th Size
3031
th Actions
@@ -38,6 +39,7 @@
3839
td
3940
template(v-if="sum[sid].lastDownload") {{ sum[sid].lastDownload | date}}
4041
template(v-else="") -
42+
td {{ sum[sid].downloadCountPre }} {{ sum[sid].downloadCount }}
4143
td
4244
template(v-if="typeof sum[sid].firstExpire === 'number'") {{ sum[sid].firstExpire | date }}
4345
template(v-else) {{ sum[sid].firstExpire }}
@@ -56,6 +58,7 @@
5658
td
5759
template(v-if="file.metadata.lastDownload") {{ +file.metadata.lastDownload | date}}
5860
template(v-else="") -
61+
td {{ file.metadata.downloadCount }}
5962
td
6063
template(v-if="typeof file.expireDate === 'number'") {{ file.expireDate | date }}
6164
template(v-else) {{ file.expireDate }}
@@ -65,7 +68,7 @@
6568
icon(name="trash")
6669
tfoot
6770
tr
68-
td(colspan="3")
71+
td(colspan="4")
6972
td.text-right(colspan="2") Sum: {{ humanFileSize(sizeSum) }}
7073
td
7174

@@ -94,7 +97,9 @@
9497
error: '',
9598
passwordWrong: false,
9699
expand: false,
97-
sizeSum: 0
100+
sizeSum: 0,
101+
downloadCount: 0,
102+
downloadCountPre: "",
98103
}
99104
},
100105
@@ -141,6 +146,12 @@
141146
};
142147
this.db[sid].forEach(file => {
143148
bucketSum.size += file.size;
149+
if(bucketSum.downloadCount == undefined) {
150+
bucketSum.downloadCount = isNaN(file.metadata.downloadCount) ? "-" : file.metadata.downloadCount;
151+
} else if(bucketSum.downloadCount != file.metadata.downloadCount ) {
152+
bucketSum.downloadCountPre = bucketSum.downloadCount != 0 ? "~" : "";
153+
bucketSum.downloadCount = bucketSum.downloadCount < file.metadata.downloadCount ? file.metadata.downloadCount : bucketSum.downloadCount;
154+
}
144155
if(file.metadata._password) {
145156
bucketSum.password = true;
146157
}

app/src/Download.vue

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
span.btn.btn-sm.btn-default(:title="$root.lang.download")
4949
a
5050
icon(name="download")
51+
strong(v-if="!isNaN(file.metadata.downloadCount)" style="padding-left:5px;") {{file.metadata.downloadCount}}
5152
i.pull-right.fa.fa-check.text-success.downloaded(v-show='file.downloaded')
5253
icon(name="check")
5354
p
@@ -135,6 +136,7 @@
135136
aEl.click();
136137
document.body.removeChild(aEl);
137138
file.downloaded = true;
139+
file.metadata.downloadCount = isNaN(file.metadata.downloadCount) ? 1 : ++file.metadata.downloadCount;
138140
},
139141
140142
downloadAll(format) {
@@ -148,6 +150,7 @@
148150
149151
this.files.forEach(f => {
150152
f.downloaded = true;
153+
f.metadata.downloadCount = isNaN(f.metadata.downloadCount) ? 1 : ++f.metadata.downloadCount;
151154
});
152155
},
153156

lib/db.js

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ module.exports = class DB {
120120
const data = this.get(sid).find(item => item.key === key);
121121
if(!data) return;
122122
data.metadata.lastDownload = Date.now();
123+
data.metadata.downloadCount = isNaN(data.metadata.downloadCount) ? 1 : ++data.metadata.downloadCount;
123124
await this.store.update(`${sid}++${key}`, data);
124125
}
125126

0 commit comments

Comments
 (0)