feat: list active public file links
All checks were successful
CI / hygiene (push) Successful in 1s
Build and Deploy / build-and-deploy (push) Successful in 30s
CI / test (push) Successful in 21s

This commit is contained in:
Grendgi
2026-06-16 16:29:59 +03:00
parent 44ea1fa36b
commit bfb1c2d0ab
6 changed files with 67 additions and 16 deletions

View File

@@ -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) {