feat: add visible trash restore for files
This commit is contained in:
@@ -240,6 +240,21 @@ func (h *NodeHandler) Move(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, node)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) Restore(w http.ResponseWriter, r *http.Request) {
|
||||
userID := commonmw.GetUserID(r.Context())
|
||||
node, err := h.repo.Restore(r.Context(), chi.URLParam(r, "id"), userID, subordinates(r))
|
||||
if errors.Is(err, repository.ErrNotFound) {
|
||||
writeError(w, http.StatusNotFound, "file not found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeInternalError(w, r, err, "failed to restore file")
|
||||
return
|
||||
}
|
||||
h.repo.Audit(r.Context(), userID, "files.node_restore", "files_node", node.ID, "{}")
|
||||
writeJSON(w, http.StatusOK, node)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
userID := commonmw.GetUserID(r.Context())
|
||||
id := chi.URLParam(r, "id")
|
||||
@@ -338,7 +353,16 @@ func (h *NodeHandler) PublicMeta(w http.ResponseWriter, r *http.Request) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, node)
|
||||
response := model.PublicNodeResponse{Node: node}
|
||||
if node.NodeType == model.NodeTypeFolder {
|
||||
children, err := h.repo.ListChildrenForPublic(r.Context(), node.ID)
|
||||
if err != nil {
|
||||
writeInternalError(w, r, err, "failed to list folder")
|
||||
return
|
||||
}
|
||||
response.Children = children
|
||||
}
|
||||
writeJSON(w, http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) PublicDownload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user