Skip to content

Commit 7371f56

Browse files
committed
Fix: refresh btn duplicates sizeSum
1 parent 6268dcf commit 7371f56

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

app/src/Admin.vue

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
.download-app
3-
a.btn.btn-sm.btn-info.btn-new-session(@click='login()', title='Refresh')
3+
a.btn.btn-sm.btn-info.btn-new-session(@click='login()', title='Refresh', v-if="loggedIn")
44
i.fa.fa-fw.fa-refresh
55

66
.alert.alert-danger(v-show="error")
@@ -95,10 +95,10 @@
9595
if(xhr.status === 200) {
9696
try {
9797
this.db = JSON.parse(xhr.responseText);
98-
this.expandDb();
9998
this.loggedIn = true;
10099
this.error = '';
101100
this.passwordWrong = false;
101+
this.expandDb();
102102
}
103103
catch(e) {
104104
this.error = e.toString();
@@ -112,36 +112,37 @@
112112
},
113113
114114
expandDb() {
115+
this.sizeSum = 0;
115116
Object.keys(this.db).forEach(sid => {
116-
const sum = {
117+
const bucketSum = {
117118
firstExpire: Number.MAX_SAFE_INTEGER,
118119
lastDownload: 0,
119120
created: Number.MAX_SAFE_INTEGER,
120121
password: false,
121122
size: 0
122123
};
123124
this.db[sid].forEach(file => {
124-
sum.size += file.size;
125+
bucketSum.size += file.size;
125126
if(file.metadata._password) {
126-
sum.password = true;
127+
bucketSum.password = true;
127128
}
128-
if(+file.metadata.createdAt < sum.created) {
129-
sum.created = +file.metadata.createdAt;
129+
if(+file.metadata.createdAt < bucketSum.created) {
130+
bucketSum.created = +file.metadata.createdAt;
130131
}
131-
if(file.metadata.lastDownload && +file.metadata.lastDownload > sum.lastDownload) {
132-
sum.lastDownload = +file.metadata.lastDownload;
132+
if(file.metadata.lastDownload && +file.metadata.lastDownload > bucketSum.lastDownload) {
133+
bucketSum.lastDownload = +file.metadata.lastDownload;
133134
}
134135
if(file.metadata.retention === 'one-time') {
135-
sum.firstExpire = 'one-time';
136+
bucketSum.firstExpire = 'one-time';
136137
file.expireDate = file.metadata.retention;
137138
}
138139
else {
139140
file.expireDate = +file.metadata.createdAt + (+file.metadata.retention * 1000);
140-
if(sum.firstExpire > file.expireDate) sum.firstExpire = file.expireDate;
141+
if(bucketSum.firstExpire > file.expireDate) bucketSum.firstExpire = file.expireDate;
141142
}
142143
});
143-
this.sizeSum += sum.size;
144-
this.$set(this.sum, sid, sum);
144+
this.sizeSum += bucketSum.size;
145+
this.$set(this.sum, sid, bucketSum);
145146
});
146147
},
147148

0 commit comments

Comments
 (0)