feat: list active public file links
This commit is contained in:
@@ -315,6 +315,22 @@ func (h *NodeHandler) ReplaceAccess(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) ListPublicLinks(w http.ResponseWriter, r *http.Request) {
|
||||
userID := commonmw.GetUserID(r.Context())
|
||||
id := chi.URLParam(r, "id")
|
||||
links, err := h.repo.ListPublicLinks(r.Context(), id, userID)
|
||||
if err != nil {
|
||||
writeInternalError(w, r, err, "failed to list public links")
|
||||
return
|
||||
}
|
||||
for i := range links {
|
||||
if links[i].URL != "" {
|
||||
links[i].URL = h.publicURL(links[i].URL)
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, links)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) CreatePublicLink(w http.ResponseWriter, r *http.Request) {
|
||||
var req model.PublicLinkRequest
|
||||
if err := decodeJSON(r, &req); err != nil {
|
||||
@@ -332,7 +348,7 @@ func (h *NodeHandler) CreatePublicLink(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
userID := commonmw.GetUserID(r.Context())
|
||||
id := chi.URLParam(r, "id")
|
||||
linkID, err := h.repo.CreatePublicLink(r.Context(), id, userID, token, req.ExpiresAt)
|
||||
link, err := h.repo.CreatePublicLink(r.Context(), id, userID, token, req.ExpiresAt)
|
||||
if errors.Is(err, repository.ErrNotFound) {
|
||||
writeError(w, http.StatusNotFound, "file not found")
|
||||
return
|
||||
@@ -342,11 +358,8 @@ func (h *NodeHandler) CreatePublicLink(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
h.repo.Audit(r.Context(), userID, "files.public_link_create", "files_node", id, "{}")
|
||||
writeJSON(w, http.StatusCreated, model.PublicLinkResponse{
|
||||
ID: linkID,
|
||||
URL: h.publicURL(token),
|
||||
ExpiresAt: req.ExpiresAt,
|
||||
})
|
||||
link.URL = h.publicURL(token)
|
||||
writeJSON(w, http.StatusCreated, link)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) PublicMeta(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user