Allow media deletion
This commit is contained in:
@@ -91,6 +91,7 @@ module Adamantium
|
|||||||
post "/posts/:id/syndicate/:target", to: "posts.syndicate"
|
post "/posts/:id/syndicate/:target", to: "posts.syndicate"
|
||||||
|
|
||||||
get "/media", to: "photos.index"
|
get "/media", to: "photos.index"
|
||||||
|
delete "/media/public/media/:year/:path", to: "photos.delete"
|
||||||
|
|
||||||
get "/trips", to: "trips.index"
|
get "/trips", to: "trips.index"
|
||||||
get "/trips/:id", to: "trips.show"
|
get "/trips/:id", to: "trips.show"
|
||||||
|
13
slices/admin/actions/photos/delete.rb
Normal file
13
slices/admin/actions/photos/delete.rb
Normal 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
|
15
slices/admin/commands/media/delete.rb
Normal file
15
slices/admin/commands/media/delete.rb
Normal 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
|
@@ -11,9 +11,9 @@ div class="mb-4 max-w-prose mx-auto prose dark:prose-invert"
|
|||||||
- next unless photos.count > 0
|
- next unless photos.count > 0
|
||||||
h2 = year
|
h2 = year
|
||||||
div class="grid grid-cols-3 gap-4"
|
div class="grid grid-cols-3 gap-4"
|
||||||
- photos.each do |photo|
|
- photos.each_with_index do |photo, idx|
|
||||||
- next if photo.match(/small/)
|
- 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/", "")}"
|
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="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
|
Reference in New Issue
Block a user