diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index ab090ed..6e9ad03 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -11,7 +11,7 @@ WHERE id = :id SELECT * FROM images WHERE id = :id -- :name delete-image! :! :n -DELETE FROM image +DELETE FROM images WHERE id = :id -- :name get-all-images :? :* @@ -43,6 +43,10 @@ VALUES (:tagname) INSERT OR IGNORE INTO image_tags (image_id, tag_id) VALUES (:imageid, :tagid) +-- :name delete-image-tags! :! +DELETE FROM image_tags +WHERE image_id = :id + -- :name get-tag :? :1 SELECT * FROM tags WHERE tagname = :tagname @@ -74,3 +78,7 @@ ORDER BY created_at DESC SELECT * FROM comments ORDER BY created_at DESC LIMIT :num-comments + +-- :name delete-image-comments! :! +DELETE FROM comments +WHERE image_id = :id diff --git a/resources/templates/detail.html b/resources/templates/detail.html index 6fe67bb..65ff194 100644 --- a/resources/templates/detail.html +++ b/resources/templates/detail.html @@ -45,6 +45,7 @@
{{ image.created_at|parse-date|date:"dd-MM-yyyy HH:mm" }} Uhr
{% if image.description|length > 0 %} diff --git a/src/clj/yenu/helpers/images.clj b/src/clj/yenu/helpers/images.clj index 912b529..d4e2bec 100644 --- a/src/clj/yenu/helpers/images.clj +++ b/src/clj/yenu/helpers/images.clj @@ -28,6 +28,9 @@ (let [file (io/file image-file-path)] (str (.lastModified file) "-" (digest/md5 file)))) +(defn delete-image! [image-hash] + (run! #(fs/delete (data-path "gallery" % (str image-hash ".png"))) + ["normal" "raw" "thumbnails"])) (defn scale-thumbnail [width] #(let [image-file % diff --git a/src/clj/yenu/routes/admin.clj b/src/clj/yenu/routes/admin.clj index 221f628..7958805 100644 --- a/src/clj/yenu/routes/admin.clj +++ b/src/clj/yenu/routes/admin.clj @@ -25,7 +25,6 @@ (defn add-tag [image-id tag] (db/create-tag! {:tagname tag}) - (let [{tag-id :id} (db/get-tag {:tagname tag})] (db/add-tag-to-image! {:imageid image-id :tagid tag-id}))) @@ -35,6 +34,13 @@ all-tags (str/split tags, #"(\s*,\s*|\s+)")] (run! #(add-tag image-id %) all-tags))) +(defn delete-image! [id request] + (let [image (db/get-image {:id id})] + (db/delete-image! {:id id}) + (db/delete-image-tags! {:id id}) + (db/delete-image-comments! {:id id}) + (images/delete-image! (:hash image)))) + (defroutes admin-routes (GET "/upload" [:as request] (-> (layout/render @@ -47,6 +53,11 @@ (-> (redirect "/upload") (assoc :flash {:message "Upload erfolgreich." :type "success"}))) + (GET "/delete/:id" [id :as request] + (delete-image! id request) + (-> (redirect "/page/1") + (assoc :flash {:message "Bild wurde gelöscht" :type "success"}))) + (GET "/statistics" [] (layout/render "statistics.html")) (GET "/comments" []