Add ability to cache bookmark
This commit is contained in:
@@ -1,21 +1,16 @@
|
||||
require "readability"
|
||||
require "down"
|
||||
|
||||
module Admin
|
||||
module Commands
|
||||
module Bookmarks
|
||||
class Cache
|
||||
include Dry::Monads[:result]
|
||||
include Deps["repos.bookmark_repo"]
|
||||
include Deps["repos.bookmark_repo", "post_utilities.page_cacher"]
|
||||
|
||||
def call(bookmark_id:)
|
||||
bookmark = bookmark_repo.fetch(id: bookmark_id)
|
||||
bookmark.url
|
||||
|
||||
tempfile = Down.download(bookmark.url)
|
||||
content = Readability::Document.new(tempfile.read, tags: %w[div section header p h1 h2 h3 h4 h5 h6 ol ul li table td tr thead tbody a code pre], attributes: %w[href]).content
|
||||
|
||||
bookmark_repo.update(id: bookmark_id, cached_content: content)
|
||||
page_cacher.call(url: bookmark.url) do |content|
|
||||
bookmark_repo.update(id: bookmark_id, cached_content: content)
|
||||
end
|
||||
|
||||
Success()
|
||||
end
|
||||
|
@@ -1,8 +1,7 @@
|
||||
module Adamantium
|
||||
class AuthenticatedAdminAction
|
||||
def self.call(action:)
|
||||
|
||||
action_proc = ->(env) { Admin::Container["actions.#{action}"].(env) }
|
||||
action_proc = ->(env) { Admin::Container["actions.#{action}"].call(env) }
|
||||
|
||||
if Hanami.app.settings.basic_auth_username && Hanami.app.settings.basic_auth_password
|
||||
Rack::Auth::Basic.new(action_proc) do |username, password|
|
||||
@@ -14,4 +13,4 @@ module Adamantium
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -9,43 +9,43 @@ module Admin
|
||||
|
||||
Auth = Adamantium::AuthenticatedAdminAction
|
||||
|
||||
get "/", to: Auth.(action: "index")
|
||||
get "/", to: Auth.call(action: "index")
|
||||
|
||||
get "/tags", to: Auth.(action: "tags.index")
|
||||
delete "/tags/:id", to: Auth.(action: "tags.delete")
|
||||
get "/tags", to: Auth.call(action: "tags.index")
|
||||
delete "/tags/:id", to: Auth.call(action: "tags.delete")
|
||||
|
||||
get "/tags/auto_tagging", to: Auth.(action: "auto_tagging.index")
|
||||
get "/tags/auto_tagging/new", to: Auth.(action: "auto_tagging.new")
|
||||
post "/tags/auto_tagging", to: Auth.(action: "auto_tagging.create")
|
||||
delete "/tags/auto_taggings/:id", to: Auth.(action: "auto_tagging.delete")
|
||||
get "/tags/auto_tagging", to: Auth.call(action: "auto_tagging.index")
|
||||
get "/tags/auto_tagging/new", to: Auth.call(action: "auto_tagging.new")
|
||||
post "/tags/auto_tagging", to: Auth.call(action: "auto_tagging.create")
|
||||
delete "/tags/auto_taggings/:id", to: Auth.call(action: "auto_tagging.delete")
|
||||
|
||||
get "/tags/merge", to: Auth.(action: "merge_tags.index")
|
||||
get "/tags/merge/:id", to: Auth.(action: "merge_tags.new")
|
||||
post "/tags/merge", to: Auth.(action: "merge_tags.merge")
|
||||
get "/tags/merge", to: Auth.call(action: "merge_tags.index")
|
||||
get "/tags/merge/:id", to: Auth.call(action: "merge_tags.new")
|
||||
post "/tags/merge", to: Auth.call(action: "merge_tags.merge")
|
||||
|
||||
get "/bookmarks", to: Auth.(action: "bookmarks.index")
|
||||
delete "/bookmarks/:id", to: Auth.(action: "bookmarks.delete")
|
||||
post "/bookmarks/clean", to: Auth.(action: "bookmarks.clean")
|
||||
post "/bookmarks/cache/:id", to: Auth.(action: "bookmarks.cache")
|
||||
post "/bookmarks/:id/archive", to: Auth.(action: "bookmarks.archive")
|
||||
post "/bookmarks/:id/publish", to: Auth.(action: "bookmarks.publish")
|
||||
get "/bookmarks", to: Auth.call(action: "bookmarks.index")
|
||||
delete "/bookmarks/:id", to: Auth.call(action: "bookmarks.delete")
|
||||
post "/bookmarks/clean", to: Auth.call(action: "bookmarks.clean")
|
||||
post "/bookmarks/cache/:id", to: Auth.call(action: "bookmarks.cache")
|
||||
post "/bookmarks/:id/archive", to: Auth.call(action: "bookmarks.archive")
|
||||
post "/bookmarks/:id/publish", to: Auth.call(action: "bookmarks.publish")
|
||||
|
||||
get "/posts", to: Auth.(action: "posts.index")
|
||||
delete "/posts/:id", to: Auth.(action: "posts.delete")
|
||||
post "/posts/:id/archive", to: Auth.(action: "posts.archive")
|
||||
post "/posts/:id/publish", to: Auth.(action: "posts.publish")
|
||||
get "/posts/:id", to: Auth.(action: "posts.show")
|
||||
post "/posts/:id/syndicate/:target", to: Auth.(action: "posts.syndicate")
|
||||
get "/posts", to: Auth.call(action: "posts.index")
|
||||
delete "/posts/:id", to: Auth.call(action: "posts.delete")
|
||||
post "/posts/:id/archive", to: Auth.call(action: "posts.archive")
|
||||
post "/posts/:id/publish", to: Auth.call(action: "posts.publish")
|
||||
get "/posts/:id", to: Auth.call(action: "posts.show")
|
||||
post "/posts/:id/syndicate/:target", to: Auth.call(action: "posts.syndicate")
|
||||
|
||||
get "/media", to: Auth.(action: "photos.index")
|
||||
delete "/media/public/media/:year/:path", to: Auth.(action: "photos.delete")
|
||||
get "/media", to: Auth.call(action: "photos.index")
|
||||
delete "/media/public/media/:year/:path", to: Auth.call(action: "photos.delete")
|
||||
|
||||
get "/trips", to: Auth.(action: "trips.index")
|
||||
get "/trips/:id", to: Auth.(action: "trips.show")
|
||||
post "/trips", to: Auth.(action: "trips.create")
|
||||
post "/trips/add_post", to: Auth.(action: "trips.add_post")
|
||||
post "/trips/remove_post", to: Auth.(action: "trips.remove_post")
|
||||
get "/trips/new", to: Auth.(action: "trips.new")
|
||||
post "/trips/:id", to: Auth.(action: "trips.update")
|
||||
get "/trips", to: Auth.call(action: "trips.index")
|
||||
get "/trips/:id", to: Auth.call(action: "trips.show")
|
||||
post "/trips", to: Auth.call(action: "trips.create")
|
||||
post "/trips/add_post", to: Auth.call(action: "trips.add_post")
|
||||
post "/trips/remove_post", to: Auth.call(action: "trips.remove_post")
|
||||
get "/trips/new", to: Auth.call(action: "trips.new")
|
||||
post "/trips/:id", to: Auth.call(action: "trips.update")
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user