diff --git a/frontend/src/views/settings/Shares.vue b/frontend/src/views/settings/Shares.vue index 50dfa8e1..1085d90e 100644 --- a/frontend/src/views/settings/Shares.vue +++ b/frontend/src/views/settings/Shares.vue @@ -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) - }) } } } diff --git a/http/share.go b/http/share.go index 971662a7..d2b4637f 100644 --- a/http/share.go +++ b/http/share.go @@ -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) })