implement file deleting routes/model

This commit is contained in:
Gered 2013-05-25 12:23:04 -04:00
parent c8805f8726
commit 1302c45ada
2 changed files with 12 additions and 0 deletions

View file

@ -63,3 +63,8 @@
(if-let [updated-doc (couch/update-document (-> doc (if-let [updated-doc (couch/update-document (-> doc
(assoc :last_modified_at (get-timestamp))))] (assoc :last_modified_at (get-timestamp))))]
(couch/put-attachment updated-doc file :filename filename :mime-type content-type)))))) (couch/put-attachment updated-doc file :filename filename :mime-type content-type))))))
(defn delete-file [id]
(couch/with-db files
(if-let [doc (couch/get-document id)]
(couch/delete-document doc))))

View file

@ -28,6 +28,12 @@
(resp/redirect (str "/listfiles" p)) (resp/redirect (str "/listfiles" p))
(throw (Exception. "Error uploading file"))))) (throw (Exception. "Error uploading file")))))
(defn handle-delete-file [file]
(let [id (ensure-prefix file "/")]
(if-let [deleted (files/delete-file file)]
(resp/redirect "/listfiles")
(throw (Exception. "Error deleting file")))))
(defn get-file [path] (defn get-file [path]
(if-let [file (files/get-file path)] (if-let [file (files/get-file path)]
(resp/content-type (:content_type file) (:data file)) (resp/content-type (:content_type file) (:data file))
@ -37,4 +43,5 @@
(restricted GET "/listfiles" [] (list-files "/")) (restricted GET "/listfiles" [] (list-files "/"))
(restricted GET "/listfiles/*" [*] (list-files *)) (restricted GET "/listfiles/*" [*] (list-files *))
(restricted POST "/uploadfile" [path file] (handle-new-file path file)) (restricted POST "/uploadfile" [path file] (handle-new-file path file))
(restricted POST "/deletefile" [file] (handle-delete-file file))
(GET "/files/*" [*] (get-file *))) (GET "/files/*" [*] (get-file *)))