Remove unneeded property title_id from Entry

This commit is contained in:
Alex Ling 2020-07-18 13:34:55 +00:00
parent bdba7bdd13
commit 6acfa02314
4 changed files with 11 additions and 11 deletions

View File

@ -1,10 +1,9 @@
class Entry class Entry
property zip_path : String, book : Title, title : String, property zip_path : String, book : Title, title : String,
size : String, pages : Int32, id : String, title_id : String, size : String, pages : Int32, id : String, encoded_path : String,
encoded_path : String, encoded_title : String, mtime : Time, encoded_title : String, mtime : Time, err_msg : String?
err_msg : String?
def initialize(@zip_path, @book, @title_id, storage) def initialize(@zip_path, @book, storage)
@encoded_path = URI.encode @zip_path @encoded_path = URI.encode @zip_path
@title = File.basename @zip_path, File.extname @zip_path @title = File.basename @zip_path, File.extname @zip_path
@encoded_title = URI.encode @title @encoded_title = URI.encode @title
@ -46,10 +45,11 @@ class Entry
def to_json(json : JSON::Builder) def to_json(json : JSON::Builder)
json.object do json.object do
{% for str in ["zip_path", "title", "size", "id", "title_id", {% for str in ["zip_path", "title", "size", "id",
"encoded_path", "encoded_title"] %} "encoded_path", "encoded_title"] %}
json.field {{str}}, @{{str.id}} json.field {{str}}, @{{str.id}}
{% end %} {% end %}
json.field "title_id", @book.id
json.field "display_name", @book.display_name @title json.field "display_name", @book.display_name @title
json.field "cover_url", cover_url json.field "cover_url", cover_url
json.field "pages" { json.number @pages } json.field "pages" { json.number @pages }
@ -67,7 +67,7 @@ class Entry
def cover_url def cover_url
return "#{Config.current.base_url}img/icon.png" if @err_msg return "#{Config.current.base_url}img/icon.png" if @err_msg
url = "#{Config.current.base_url}api/page/#{@title_id}/#{@id}/1" url = "#{Config.current.base_url}api/page/#{@book.id}/#{@id}/1"
TitleInfo.new @book.dir do |info| TitleInfo.new @book.dir do |info|
info_url = info.entry_cover_url[@title]? info_url = info.entry_cover_url[@title]?
unless info_url.nil? || info_url.empty? unless info_url.nil? || info_url.empty?

View File

@ -128,7 +128,7 @@ class Library
.each do |e| .each do |e|
break if recently_added.size > 12 break if recently_added.size > 12
last = recently_added.last? last = recently_added.last?
if last && e[:entry].title_id == last[:entry].title_id && if last && e[:entry].book.id == last[:entry].book.id &&
(e[:date_added] - last_date_added.not_nil!).duration < 1.day (e[:date_added] - last_date_added.not_nil!).duration < 1.day
# A NamedTuple is immutable, so we have to cast it to a Hash first # A NamedTuple is immutable, so we have to cast it to a Hash first
last_hash = last.to_h last_hash = last.to_h

View File

@ -34,7 +34,7 @@ class Title
next next
end end
if [".zip", ".cbz", ".rar", ".cbr"].includes? File.extname path if [".zip", ".cbz", ".rar", ".cbr"].includes? File.extname path
entry = Entry.new path, self, @id, storage entry = Entry.new path, self, storage
@entries << entry if entry.pages > 0 || entry.err_msg @entries << entry if entry.pages > 0 || entry.err_msg
end end
end end

View File

@ -28,10 +28,10 @@
<link rel="http://opds-spec.org/image" href="<%= e.cover_url %>" /> <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/image/thumbnail" href="<%= e.cover_url %>" />
<link rel="http://opds-spec.org/acquisition" href="<%= base_url %>opds/download/<%= e.title_id %>/<%= e.id %>" title="Read" type="<%= MIME.from_filename e.zip_path %>" /> <link rel="http://opds-spec.org/acquisition" href="<%= base_url %>opds/download/<%= e.book.id %>/<%= e.id %>" title="Read" type="<%= MIME.from_filename e.zip_path %>" />
<link type="text/html" rel="alternate" title="Read in Mango" href="<%= base_url %>reader/<%= e.title_id %>/<%= e.id %>" /> <link type="text/html" rel="alternate" title="Read in Mango" href="<%= base_url %>reader/<%= e.book.id %>/<%= e.id %>" />
<link type="text/html" rel="alternate" title="Open in Mango" href="<%= base_url %>book/<%= e.title_id %>" /> <link type="text/html" rel="alternate" title="Open in Mango" href="<%= base_url %>book/<%= e.book.id %>" />
</entry> </entry>
<% end %> <% end %>