Initial commit
This commit is contained in:
0
app/actions/.keep
Normal file
0
app/actions/.keep
Normal file
13
app/actions/bookmarks/index.rb
Normal file
13
app/actions/bookmarks/index.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Bookmarks
|
||||
class Index < Action
|
||||
include Deps["views.bookmarks.index"]
|
||||
|
||||
def handle(req, res)
|
||||
res.render index, query: req.params[:q]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
12
app/actions/bookmarks/show.rb
Normal file
12
app/actions/bookmarks/show.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Bookmarks
|
||||
class Show < Action
|
||||
include Deps["views.bookmarks.show"]
|
||||
def handle(req, res)
|
||||
res.render show, slug: req.params[:slug]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
app/actions/feeds/rss.rb
Normal file
14
app/actions/feeds/rss.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Feeds
|
||||
class Rss < Action
|
||||
include Deps["views.feeds.rss"]
|
||||
|
||||
def handle(req, res)
|
||||
res.content_type = "application/rss+xml"
|
||||
res.render rss, format: :xml
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
app/actions/key/show.rb
Normal file
13
app/actions/key/show.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Key
|
||||
class Show < Action
|
||||
include Deps["settings"]
|
||||
def handle(req, res)
|
||||
res.content_type = "text/plain"
|
||||
res.body = settings.micropub_pub_key
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
app/actions/media/create.rb
Normal file
28
app/actions/media/create.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Media
|
||||
class Create < Action
|
||||
before :authenticate
|
||||
|
||||
include Deps["commands.media.upload"]
|
||||
|
||||
def handle(req, res)
|
||||
data = req.params[:file]
|
||||
|
||||
halt 401 if verify_scope(req: req, scope: :media)
|
||||
|
||||
upload(file: data) do |m|
|
||||
m.failure do |v|
|
||||
res.status = 422
|
||||
end
|
||||
|
||||
m.success do |v|
|
||||
res.status = 201
|
||||
res.body = v
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
app/actions/pages/show.rb
Normal file
15
app/actions/pages/show.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Pages
|
||||
class Show < Action
|
||||
include Deps["views.pages.show"]
|
||||
|
||||
def handle(req, res)
|
||||
slug = req.params[:slug]
|
||||
|
||||
res.render show, slug: slug
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
66
app/actions/posts/handle.rb
Normal file
66
app/actions/posts/handle.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
require "pry"
|
||||
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Posts
|
||||
class Handle < Action
|
||||
before :authenticate!
|
||||
|
||||
include Deps[
|
||||
"settings",
|
||||
post_param_parser: "param_parser.micropub_post",
|
||||
create_resolver: "commands.posts.creation_resolver",
|
||||
delete_post: "commands.posts.delete",
|
||||
undelete_post: "commands.posts.undelete",
|
||||
update_post: "commands.posts.update"
|
||||
]
|
||||
|
||||
def handle(req, res)
|
||||
req_entity = post_param_parser.call(params: req.params.to_h)
|
||||
action = req.params[:action]
|
||||
|
||||
if action
|
||||
operation, permission_check = resolve_operation(action)
|
||||
|
||||
if permission_check.call(req)
|
||||
operation.call(params: req.params.to_h)
|
||||
res.status = 200
|
||||
else
|
||||
res.status = 401
|
||||
end
|
||||
elsif req_entity
|
||||
halt 401 unless verify_scope(req: req, scope: :create)
|
||||
|
||||
command, contract = create_resolver.call(entry_type: req_entity).values_at(:command, :validation)
|
||||
|
||||
validation = contract.call(req_entity.to_h)
|
||||
if validation.success?
|
||||
post = command.call(validation.to_h)
|
||||
|
||||
res.status = 201
|
||||
res.headers.merge!(
|
||||
"Location" => "#{settings.micropub_site_url}/#{post.post_type}/#{post.slug}"
|
||||
)
|
||||
else
|
||||
res.body = {error: validation.errors.to_h}.to_json
|
||||
res.status = 422
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def resolve_operation(action)
|
||||
case action
|
||||
when "delete"
|
||||
[delete_post, ->(req) { verify_scope(req: req, scope: :delete) }]
|
||||
when "undelete"
|
||||
[undelete_post, ->(req) { verify_scope(req: req, scope: :undelete) }]
|
||||
when "update"
|
||||
[update_post, ->(req) { verify_scope(req: req, scope: :update) }]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
12
app/actions/posts/index.rb
Normal file
12
app/actions/posts/index.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Posts
|
||||
class Index < Action
|
||||
include Deps["views.posts.index"]
|
||||
def handle(req, res)
|
||||
res.render index
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
app/actions/posts/show.rb
Normal file
15
app/actions/posts/show.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Posts
|
||||
class Show < Action
|
||||
include Deps["views.posts.show"]
|
||||
|
||||
def handle(req, res)
|
||||
slug = req.params[:slug]
|
||||
|
||||
res.render show, slug: slug
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
app/actions/site/config.rb
Normal file
31
app/actions/site/config.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Site
|
||||
class Config < Action
|
||||
include Deps["settings", "views.site.home"]
|
||||
|
||||
def handle(req, res)
|
||||
if req.params[:q] == "config"
|
||||
res.status = 200
|
||||
res.content_type = "Application/JSON"
|
||||
res.body = {
|
||||
"media-endpoint" => settings.micropub_media_endpoint,
|
||||
"destination" => [
|
||||
{uid: settings.micropub_site_id, name: settings.micropub_site_name}
|
||||
],
|
||||
"post-types" => [
|
||||
{type: "note", name: "Note", properties: %w[content category]},
|
||||
{type: "article", name: "Article", properties: %w[name content category]},
|
||||
{type: "photo", name: "Photo", properties: %w[name content category]},
|
||||
{type: "bookmark", name: "Bookmark", properties: %w[name content category]}
|
||||
],
|
||||
"syndicate-to" => []
|
||||
}.to_json
|
||||
else
|
||||
res.render home
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
12
app/actions/site/home.rb
Normal file
12
app/actions/site/home.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Site
|
||||
class Home < Action
|
||||
include Deps["views.site.home"]
|
||||
def handle(req, res)
|
||||
res.render home
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
app/actions/tags/show.rb
Normal file
15
app/actions/tags/show.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Adamantium
|
||||
module Actions
|
||||
module Tags
|
||||
class Show < Action
|
||||
include Deps["views.tags.show"]
|
||||
|
||||
def handle(req, res)
|
||||
slug = req.params[:slug]
|
||||
|
||||
res.render show, slug: slug
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user