Allow media deletion

This commit is contained in:
2023-06-24 13:52:46 +10:00
parent 79d5c3c5cf
commit e266ed52ad
4 changed files with 32 additions and 3 deletions

View File

@@ -91,6 +91,7 @@ module Adamantium
post "/posts/:id/syndicate/:target", to: "posts.syndicate"
get "/media", to: "photos.index"
delete "/media/public/media/:year/:path", to: "photos.delete"
get "/trips", to: "trips.index"
get "/trips/:id", to: "trips.show"

View File

@@ -0,0 +1,13 @@
module Admin
module Actions
module Photos
class Delete < Admin::Action
include Deps["commands.media.delete"]
def handle(req, res)
delete.call(path: File.join(Hanami.app.root, "public", "media",req.params[:year], req.params[:path]))
end
end
end
end
end

View File

@@ -0,0 +1,15 @@
module Admin
module Commands
module Media
class Delete
include Dry::Monads[:result]
def call(path:)
File.delete(path)
Success()
end
end
end
end
end

View File

@@ -11,9 +11,9 @@ div class="mb-4 max-w-prose mx-auto prose dark:prose-invert"
- next unless photos.count > 0
h2 = year
div class="grid grid-cols-3 gap-4"
- photos.each do |photo|
- photos.each_with_index do |photo, idx|
- next if photo.match(/small/)
div class="rounded max-w-xs" x-data=""
div class="rounded max-w-xs" x-data="" id="photo-#{idx}"
img class="rounded object-cover hover:opacity-80 h-48 w-48" src="/#{photo.gsub("public/", "")}"
button class="hover:text-blue-400 p-2 bg-blue-100 rounded text-blue-600 mr-4 no-underline" @click="$clipboard('#{Hanami.app.settings.micropub_site_url}/#{photo.gsub("public/", "")}')" Copy URL
button class="text-red-600 hover:text-red-400" hx-delete="/admin/media/#{photo}" hx-target="#post-#{photo}" Delete
button class="text-red-600 hover:text-red-400" hx-delete="/admin/media/#{photo}" hx-target="#photo-#{idx}" Delete