Add trash: deleted files go to trash, restore or empty
This commit is contained in:
@@ -286,3 +286,41 @@ func (s *Server) handleSharedFiles(w http.ResponseWriter, r *http.Request) {
|
||||
// For now return empty list
|
||||
writeJSON(w, 200, []files.FileInfo{})
|
||||
}
|
||||
|
||||
func (s *Server) handleListTrash(w http.ResponseWriter, r *http.Request) {
|
||||
userID := getUserID(r)
|
||||
items, err := files.ListTrash(s.dataDir, userID)
|
||||
if err != nil {
|
||||
writeJSON(w, 500, map[string]string{"error": "failed to list trash"})
|
||||
return
|
||||
}
|
||||
if items == nil {
|
||||
items = []files.FileInfo{}
|
||||
}
|
||||
writeJSON(w, 200, items)
|
||||
}
|
||||
|
||||
func (s *Server) handleRestoreTrash(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
if err := decodeBody(r, &req); err != nil || req.Name == "" {
|
||||
writeJSON(w, 400, map[string]string{"error": "name required"})
|
||||
return
|
||||
}
|
||||
userID := getUserID(r)
|
||||
if err := files.RestoreFromTrash(s.dataDir, userID, req.Name); err != nil {
|
||||
writeJSON(w, 500, map[string]string{"error": "restore failed"})
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, map[string]string{"status": "restored"})
|
||||
}
|
||||
|
||||
func (s *Server) handleEmptyTrash(w http.ResponseWriter, r *http.Request) {
|
||||
userID := getUserID(r)
|
||||
if err := files.EmptyTrash(s.dataDir, userID); err != nil {
|
||||
writeJSON(w, 500, map[string]string{"error": "empty trash failed"})
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, map[string]string{"status": "emptied"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user