mirror of
https://github.com/1f349/orchid.git
synced 2025-01-20 22:26:33 +00:00
Output slice from owned endpoint
This commit is contained in:
parent
55bfc13457
commit
25e1065f05
@ -14,6 +14,7 @@ import (
|
|||||||
vUtils "github.com/1f349/violet/utils"
|
vUtils "github.com/1f349/violet/utils"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -46,6 +47,7 @@ func NewApiServer(listen string, db *database.Queries, signer mjwt.Verifier, dom
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Endpoint for grabbing owned certificates
|
// Endpoint for grabbing owned certificates
|
||||||
|
// TODO(melon): rewrite this endpoint to prevent using a map then converting into a slice later
|
||||||
r.GET("/owned", checkAuthWithPerm(signer, "orchid:cert", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims) {
|
r.GET("/owned", checkAuthWithPerm(signer, "orchid:cert", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims) {
|
||||||
domains := getDomainOwnershipClaims(b.Claims.Perms)
|
domains := getDomainOwnershipClaims(b.Claims.Perms)
|
||||||
domainMap := make(map[string]bool)
|
domainMap := make(map[string]bool)
|
||||||
@ -107,8 +109,18 @@ func NewApiServer(listen string, db *database.Queries, signer mjwt.Verifier, dom
|
|||||||
m[c.Id] = &c
|
m[c.Id] = &c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remap into a slice
|
||||||
|
arr := make([]*Certificate, 0, len(m))
|
||||||
|
slices.SortFunc(arr, func(a, b *Certificate) int {
|
||||||
|
return int(a.Id - b.Id)
|
||||||
|
})
|
||||||
|
for _, v := range m {
|
||||||
|
arr = append(arr, v)
|
||||||
|
}
|
||||||
|
|
||||||
rw.WriteHeader(http.StatusOK)
|
rw.WriteHeader(http.StatusOK)
|
||||||
_ = json.NewEncoder(rw).Encode(m)
|
_ = json.NewEncoder(rw).Encode(arr)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Endpoint for looking up a certificate
|
// Endpoint for looking up a certificate
|
||||||
|
Loading…
Reference in New Issue
Block a user