mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-05 04:15:35 -04:00
Finish OPDS
This commit is contained in:
parent
871a5fe755
commit
8a0e9250c8
32
src/routes/opds.cr
Normal file
32
src/routes/opds.cr
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
require "./router"
|
||||||
|
|
||||||
|
class OPDSRouter < Router
|
||||||
|
def initialize
|
||||||
|
get "/opds" do |env|
|
||||||
|
titles = @context.library.titles
|
||||||
|
render_xml "src/views/opds/index.ecr"
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/opds/book/:title_id" do |env|
|
||||||
|
begin
|
||||||
|
title = @context.library.get_title(env.params.url["title_id"]).not_nil!
|
||||||
|
render_xml "src/views/opds/title.ecr"
|
||||||
|
rescue e
|
||||||
|
@context.error e
|
||||||
|
env.response.status_code = 404
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/opds/download/:title/:entry" do |env|
|
||||||
|
begin
|
||||||
|
title = (@context.library.get_title env.params.url["title"]).not_nil!
|
||||||
|
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||||
|
|
||||||
|
send_attachment env, entry.zip_path
|
||||||
|
rescue e
|
||||||
|
@context.error e
|
||||||
|
env.response.status_code = 404
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -53,6 +53,7 @@ class Server
|
|||||||
AdminRouter.new
|
AdminRouter.new
|
||||||
ReaderRouter.new
|
ReaderRouter.new
|
||||||
APIRouter.new
|
APIRouter.new
|
||||||
|
OPDSRouter.new
|
||||||
|
|
||||||
Kemal.config.logging = false
|
Kemal.config.logging = false
|
||||||
add_handler LogHandler.new
|
add_handler LogHandler.new
|
||||||
|
24
src/views/opds/index.ecr
Normal file
24
src/views/opds/index.ecr
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!--TODO: respect base URL-->
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<id>urn:mango:index</id>
|
||||||
|
|
||||||
|
<link rel="self" href="/opds/" type="application/atom+xml;profile=opds-catalog;kind=navigation" />
|
||||||
|
<link rel="start" href="/opds/" type="application/atom+xml;profile=opds-catalog;kind=navigation" />
|
||||||
|
|
||||||
|
<title>Library</title>
|
||||||
|
|
||||||
|
<author>
|
||||||
|
<name>Mango</name>
|
||||||
|
<uri>https://github.com/hkalexling/Mango</uri>
|
||||||
|
</author>
|
||||||
|
|
||||||
|
<% titles.each do |t| %>
|
||||||
|
<entry>
|
||||||
|
<title><%= t.display_name %></title>
|
||||||
|
<id>urn:mango:<%= t.id %></id>
|
||||||
|
<link type="application/atom+xml;profile=opds-catalog;kind=navigation" rel="subsection" href="/opds/book/<%= t.id %>" />
|
||||||
|
</entry>
|
||||||
|
<% end %>
|
||||||
|
</feed>
|
38
src/views/opds/title.ecr
Normal file
38
src/views/opds/title.ecr
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<id>urn:mango:<%= title.id %></id>
|
||||||
|
|
||||||
|
<link rel="self" href="/opds/book/<%= title.id %>" type="application/atom+xml;profile=opds-catalog;kind=navigation" />
|
||||||
|
<link rel="start" href="/opds/" type="application/atom+xml;profile=opds-catalog;kind=navigation" />
|
||||||
|
|
||||||
|
<title><%= title.display_name %></title>
|
||||||
|
|
||||||
|
<author>
|
||||||
|
<name>Mango</name>
|
||||||
|
<uri>https://github.com/hkalexling/Mango</uri>
|
||||||
|
</author>
|
||||||
|
|
||||||
|
<% title.titles.each do |t| %>
|
||||||
|
<entry>
|
||||||
|
<title><%= t.display_name %></title>
|
||||||
|
<id>urn:mango:<%= t.id %></id>
|
||||||
|
<link type="application/atom+xml;profile=opds-catalog;kind=navigation" rel="subsection" href="/opds/book/<%= t.id %>" />
|
||||||
|
</entry>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% title.entries.each do |e| %>
|
||||||
|
<entry>
|
||||||
|
<title><%= e.display_name %></title>
|
||||||
|
<id>urn:mango:<%= e.id %></id>
|
||||||
|
|
||||||
|
<link rel="http://opds-spec.org/image" href="<%= e.cover_url %>" />
|
||||||
|
<link rel="http://opds-spec.org/image/thumbnail" href="<%= e.cover_url %>" />
|
||||||
|
|
||||||
|
<link rel="http://opds-spec.org/acquisition" href="/opds/download/<%= e.title_id %>/<%= e.id %>" title="Read" type="<%= MIME.from_filename e.zip_path %>" />
|
||||||
|
|
||||||
|
<link type="text/html" rel="alternate" title="Read in Mango" href="/reader/<%= e.title_id %>/<%= e.id %>" />
|
||||||
|
<link type="text/html" rel="alternate" title="Open in Mango" href="/book/<%= e.title_id %>" />
|
||||||
|
</entry>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</feed>
|
Loading…
x
Reference in New Issue
Block a user