diff --git a/public/js/title.js b/public/js/title.js
index 876c70c..d46c173 100644
--- a/public/js/title.js
+++ b/public/js/title.js
@@ -55,7 +55,7 @@ function showModal(encodedPath, pages, percentage, encodedeTitle, encodedEntryTi
$('#modal-edit-btn').attr('onclick', `edit("${entryID}")`);
- $('#modal-download-btn').attr('href', `${base_url}opds/download/${titleID}/${entryID}`);
+ $('#modal-download-btn').attr('href', `${base_url}api/download/${titleID}/${entryID}`);
UIkit.modal($('#modal')).show();
}
diff --git a/src/routes/api.cr b/src/routes/api.cr
index 8bff6b4..dd1facb 100644
--- a/src/routes/api.cr
+++ b/src/routes/api.cr
@@ -652,6 +652,23 @@ class APIRouter < Router
end
end
+ Koa.describe "Downloads an entry"
+ Koa.path "tid", desc: "A title ID"
+ Koa.path "eid", desc: "An entry ID"
+ Koa.response 200, ref: "$binary"
+ Koa.response 404, "Entry not found"
+ get "/api/download/:tid/:eid" do |env|
+ begin
+ title = (@context.library.get_title env.params.url["tid"]).not_nil!
+ entry = (title.get_entry env.params.url["eid"]).not_nil!
+
+ send_attachment env, entry.zip_path
+ rescue e
+ @context.error e
+ env.response.status_code = 404
+ end
+ end
+
doc = Koa.generate
@@api_json = doc.to_json if doc
diff --git a/src/routes/opds.cr b/src/routes/opds.cr
index 567931e..eafbcb9 100644
--- a/src/routes/opds.cr
+++ b/src/routes/opds.cr
@@ -16,17 +16,5 @@ class OPDSRouter < Router
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
diff --git a/src/views/opds/title.xml.ecr b/src/views/opds/title.xml.ecr
index 392978c..b159687 100644
--- a/src/views/opds/title.xml.ecr
+++ b/src/views/opds/title.xml.ecr
@@ -29,7 +29,7 @@
-
+