move sort logic to backend, update deleted user name logic

This commit is contained in:
WeidiDeng 2020-12-07 18:57:36 +08:00
parent 3bd90ae2e3
commit 3d2bb9170d
No known key found for this signature in database
GPG Key ID: 25F87CE1741EC7CD
2 changed files with 11 additions and 11 deletions

View File

@ -56,13 +56,13 @@ export default {
},
async created () {
try {
this.links = await api.list()
let links = await api.list()
if (this.user.perm.admin) {
let userMap = new Map()
for (let user of await users.getAll()) userMap.set(user.id, user.username)
for (let link of this.links) link.username = userMap.has(link.userID) ? userMap.get(link.userID) : link.userID
for (let link of links) link.username = userMap.has(link.userID) ? userMap.get(link.userID) : ''
}
this.sort()
this.links = links
} catch (e) {
this.$showError(e)
}
@ -88,14 +88,6 @@ export default {
},
buildLink (hash) {
return `${window.location.origin}${baseURL}/share/${hash}`
},
sort () {
this.links = this.links.sort((a, b) => {
if (a.userID !== b.userID) return a.userID - b.userID
if (a.expire === 0) return -1
if (b.expire === 0) return 1
return new Date(a.expire) - new Date(b.expire)
})
}
}
}

View File

@ -5,6 +5,7 @@ import (
"encoding/base64"
"net/http"
"path"
"sort"
"strconv"
"strings"
"time"
@ -37,6 +38,13 @@ var shareListHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
return http.StatusInternalServerError, err
}
sort.Slice(s, func(i, j int) bool {
if s[i].UserID != s[j].UserID {
return s[i].UserID < s[j].UserID
}
return s[i].Expire < s[j].Expire
})
return renderJSON(w, r, s)
})