mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-04 11:55:30 -04:00
List the parent title objects in Title.to_json
This commit is contained in:
parent
6407cea7bf
commit
3e42266955
@ -73,10 +73,12 @@ class Entry
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Title
|
class Title
|
||||||
property dir : String, title_ids : Array(String), entries : Array(Entry),
|
property dir : String, parent_id : String, title_ids : Array(String),
|
||||||
title : String, id : String, encoded_title : String, mtime : Time
|
entries : Array(Entry), title : String, id : String,
|
||||||
|
encoded_title : String, mtime : Time
|
||||||
|
|
||||||
def initialize(dir : String, storage, @logger : MLogger, @library : Library)
|
def initialize(dir : String, @parent_id, storage,
|
||||||
|
@logger : MLogger, @library : Library)
|
||||||
@dir = dir
|
@dir = dir
|
||||||
@id = storage.get_id @dir, true
|
@id = storage.get_id @dir, true
|
||||||
@title = File.basename dir
|
@title = File.basename dir
|
||||||
@ -88,7 +90,7 @@ class Title
|
|||||||
next if fn.starts_with? "."
|
next if fn.starts_with? "."
|
||||||
path = File.join dir, fn
|
path = File.join dir, fn
|
||||||
if File.directory? path
|
if File.directory? path
|
||||||
title = Title.new path, storage, @logger, library
|
title = Title.new path, @id, storage, @logger, library
|
||||||
next if title.entries.size == 0 && title.titles.size == 0
|
next if title.entries.size == 0 && title.titles.size == 0
|
||||||
@library.title_hash[title.id] = title
|
@library.title_hash[title.id] = title
|
||||||
@title_ids << title.id
|
@title_ids << title.id
|
||||||
@ -124,6 +126,16 @@ class Title
|
|||||||
json.field "entries" do
|
json.field "entries" do
|
||||||
json.raw @entries.to_json
|
json.raw @entries.to_json
|
||||||
end
|
end
|
||||||
|
json.field "parents" do
|
||||||
|
json.array do
|
||||||
|
self.parents.each do |title|
|
||||||
|
json.object do
|
||||||
|
json.field "title", title.title
|
||||||
|
json.field "id", title.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -131,6 +143,17 @@ class Title
|
|||||||
@title_ids.map {|tid| @library.get_title! tid}
|
@title_ids.map {|tid| @library.get_title! tid}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parents
|
||||||
|
ary = [] of Title
|
||||||
|
tid = @parent_id
|
||||||
|
while !tid.empty?
|
||||||
|
title = @library.get_title! tid
|
||||||
|
ary << title
|
||||||
|
tid = title.parent_id
|
||||||
|
end
|
||||||
|
ary
|
||||||
|
end
|
||||||
|
|
||||||
# When downloading from MangaDex, the zip/cbz file would not be valid
|
# When downloading from MangaDex, the zip/cbz file would not be valid
|
||||||
# before the download is completed. If we scan the zip file,
|
# before the download is completed. If we scan the zip file,
|
||||||
# Entry.new would throw, so we use this method to check before
|
# Entry.new would throw, so we use this method to check before
|
||||||
@ -267,7 +290,7 @@ class Library
|
|||||||
.select { |fn| !fn.starts_with? "." }
|
.select { |fn| !fn.starts_with? "." }
|
||||||
.map { |fn| File.join @dir, fn }
|
.map { |fn| File.join @dir, fn }
|
||||||
.select { |path| File.directory? path }
|
.select { |path| File.directory? path }
|
||||||
.map { |path| Title.new path, @storage, @logger, self }
|
.map { |path| Title.new path, "", @storage, @logger, self }
|
||||||
.select { |title| !(title.entries.empty? && title.titles.empty?) }
|
.select { |title| !(title.entries.empty? && title.titles.empty?) }
|
||||||
.sort { |a, b| a.title <=> b.title }
|
.sort { |a, b| a.title <=> b.title }
|
||||||
.each do |title|
|
.each do |title|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user