diff --git a/config/routes.rb b/config/routes.rb index e05de4b..5c7291e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/slices/admin/actions/photos/delete.rb b/slices/admin/actions/photos/delete.rb new file mode 100644 index 0000000..48d7876 --- /dev/null +++ b/slices/admin/actions/photos/delete.rb @@ -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 diff --git a/slices/admin/commands/media/delete.rb b/slices/admin/commands/media/delete.rb new file mode 100644 index 0000000..b9706ea --- /dev/null +++ b/slices/admin/commands/media/delete.rb @@ -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 diff --git a/slices/admin/templates/photos/index.html.slim b/slices/admin/templates/photos/index.html.slim index 40ab50d..6f48026 100644 --- a/slices/admin/templates/photos/index.html.slim +++ b/slices/admin/templates/photos/index.html.slim @@ -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 \ No newline at end of file + button class="text-red-600 hover:text-red-400" hx-delete="/admin/media/#{photo}" hx-target="#photo-#{idx}" Delete \ No newline at end of file