mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 19:05:32 -04:00
Rename Entries to ArchiveEntry and DirEntry
This commit is contained in:
parent
f18f6a5418
commit
1f5aed64f7
@ -15,9 +15,9 @@ abstract class Entry
|
|||||||
|
|
||||||
def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
|
def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
|
||||||
# TODO: check node? and select proper subclass
|
# TODO: check node? and select proper subclass
|
||||||
ZippedEntry.new ctx, node
|
ArchiveEntry.new ctx, node
|
||||||
rescue e
|
rescue e
|
||||||
DirectoryEntry.new ctx, node
|
DirEntry.new ctx, node
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_json(*, slim = false)
|
def build_json(*, slim = false)
|
||||||
@ -230,7 +230,7 @@ abstract class Entry
|
|||||||
abstract def examine : Bool?
|
abstract def examine : Bool?
|
||||||
end
|
end
|
||||||
|
|
||||||
class ZippedEntry < Entry
|
class ArchiveEntry < Entry
|
||||||
include YAML::Serializable
|
include YAML::Serializable
|
||||||
|
|
||||||
getter zip_path : String
|
getter zip_path : String
|
||||||
@ -341,7 +341,7 @@ class ZippedEntry < Entry
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DirectoryEntry < Entry
|
class DirEntry < Entry
|
||||||
include YAML::Serializable
|
include YAML::Serializable
|
||||||
|
|
||||||
getter dir_path : String
|
getter dir_path : String
|
||||||
@ -364,7 +364,7 @@ class DirectoryEntry < Entry
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
unless DirectoryEntry.validate_directory_entry @dir_path
|
unless DirEntry.validate_directory_entry @dir_path
|
||||||
@err_msg = "Directory #{@dir_path} is not valid directory entry."
|
@err_msg = "Directory #{@dir_path} is not valid directory entry."
|
||||||
Logger.warn "#{@err_msg} Please make sure the " \
|
Logger.warn "#{@err_msg} Please make sure the " \
|
||||||
"directory has valid images."
|
"directory has valid images."
|
||||||
@ -441,7 +441,7 @@ class DirectoryEntry < Entry
|
|||||||
def examine : Bool
|
def examine : Bool
|
||||||
existence = File.exists? @dir_path
|
existence = File.exists? @dir_path
|
||||||
return false unless existence
|
return false unless existence
|
||||||
files = DirectoryEntry.get_valid_files @dir_path
|
files = DirEntry.get_valid_files @dir_path
|
||||||
signature = Dir.directory_entry_signature @dir_path
|
signature = Dir.directory_entry_signature @dir_path
|
||||||
existence = files.size > 0 && @signature == signature
|
existence = files.size > 0 && @signature == signature
|
||||||
@sorted_files = nil unless existence
|
@sorted_files = nil unless existence
|
||||||
@ -454,12 +454,12 @@ class DirectoryEntry < Entry
|
|||||||
def sorted_files
|
def sorted_files
|
||||||
cached_sorted_files = @sorted_files
|
cached_sorted_files = @sorted_files
|
||||||
return cached_sorted_files if cached_sorted_files
|
return cached_sorted_files if cached_sorted_files
|
||||||
@sorted_files = DirectoryEntry.get_valid_files_sorted @dir_path
|
@sorted_files = DirEntry.get_valid_files_sorted @dir_path
|
||||||
@sorted_files.not_nil!
|
@sorted_files.not_nil!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.validate_directory_entry(dir_path)
|
def self.validate_directory_entry(dir_path)
|
||||||
files = DirectoryEntry.get_valid_files dir_path
|
files = DirEntry.get_valid_files dir_path
|
||||||
files.size > 0
|
files.size > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -477,7 +477,7 @@ class DirectoryEntry < Entry
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.get_valid_files_sorted(dir_path)
|
def self.get_valid_files_sorted(dir_path)
|
||||||
files = DirectoryEntry.get_valid_files dir_path
|
files = DirEntry.get_valid_files dir_path
|
||||||
files.sort! { |a, b| compare_numerically a, b }
|
files.sort! { |a, b| compare_numerically a, b }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -53,14 +53,14 @@ class Title
|
|||||||
Library.default.title_hash[title.id] = title
|
Library.default.title_hash[title.id] = title
|
||||||
@title_ids << title.id
|
@title_ids << title.id
|
||||||
end
|
end
|
||||||
if DirectoryEntry.validate_directory_entry path
|
if DirEntry.validate_directory_entry path
|
||||||
entry = DirectoryEntry.new path, self
|
entry = DirEntry.new path, self
|
||||||
@entries << entry if entry.pages > 0 || entry.err_msg
|
@entries << entry if entry.pages > 0 || entry.err_msg
|
||||||
end
|
end
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
if is_supported_file path
|
if is_supported_file path
|
||||||
entry = ZippedEntry.new path, self
|
entry = ArchiveEntry.new path, self
|
||||||
@entries << entry if entry.pages > 0 || entry.err_msg
|
@entries << entry if entry.pages > 0 || entry.err_msg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -146,8 +146,8 @@ class Title
|
|||||||
path = File.join dir, fn
|
path = File.join dir, fn
|
||||||
if File.directory? path
|
if File.directory? path
|
||||||
unless remained_entry_paths.includes? path
|
unless remained_entry_paths.includes? path
|
||||||
if DirectoryEntry.validate_directory_entry path
|
if DirEntry.validate_directory_entry path
|
||||||
entry = DirectoryEntry.new path, self
|
entry = DirEntry.new path, self
|
||||||
if entry.pages > 0 || entry.err_msg
|
if entry.pages > 0 || entry.err_msg
|
||||||
@entries << entry
|
@entries << entry
|
||||||
is_entries_added = true
|
is_entries_added = true
|
||||||
@ -181,7 +181,7 @@ class Title
|
|||||||
end
|
end
|
||||||
if is_supported_file path
|
if is_supported_file path
|
||||||
next if remained_entry_paths.includes? path
|
next if remained_entry_paths.includes? path
|
||||||
entry = ZippedEntry.new path, self
|
entry = ArchiveEntry.new path, self
|
||||||
if entry.pages > 0 || entry.err_msg
|
if entry.pages > 0 || entry.err_msg
|
||||||
@entries << entry
|
@entries << entry
|
||||||
is_entries_added = true
|
is_entries_added = true
|
||||||
|
@ -142,7 +142,7 @@ struct APIRouter
|
|||||||
env.response.status_code = 304
|
env.response.status_code = 304
|
||||||
""
|
""
|
||||||
else
|
else
|
||||||
if entry.is_a? DirectoryEntry
|
if entry.is_a? DirEntry
|
||||||
cache_control = "no-cache, max-age=86400"
|
cache_control = "no-cache, max-age=86400"
|
||||||
else
|
else
|
||||||
cache_control = "public, max-age=86400"
|
cache_control = "public, max-age=86400"
|
||||||
@ -1143,7 +1143,7 @@ struct APIRouter
|
|||||||
entry = title.get_entry eid
|
entry = title.get_entry eid
|
||||||
raise "Entry ID `#{eid}` of `#{title.title}` not found" if entry.nil?
|
raise "Entry ID `#{eid}` of `#{title.title}` not found" if entry.nil?
|
||||||
|
|
||||||
if entry.is_a? DirectoryEntry
|
if entry.is_a? DirEntry
|
||||||
file_hash = Digest::SHA1.hexdigest(entry.path + entry.mtime.to_s + entry.size)
|
file_hash = Digest::SHA1.hexdigest(entry.path + entry.mtime.to_s + entry.size)
|
||||||
else
|
else
|
||||||
file_hash = Digest::SHA1.hexdigest(entry.path + entry.mtime.to_s)
|
file_hash = Digest::SHA1.hexdigest(entry.path + entry.mtime.to_s)
|
||||||
@ -1154,7 +1154,7 @@ struct APIRouter
|
|||||||
send_text env, ""
|
send_text env, ""
|
||||||
else
|
else
|
||||||
sizes = entry.page_dimensions
|
sizes = entry.page_dimensions
|
||||||
if entry.is_a? DirectoryEntry
|
if entry.is_a? DirEntry
|
||||||
cache_control = "no-cache, max-age=86400"
|
cache_control = "no-cache, max-age=86400"
|
||||||
else
|
else
|
||||||
cache_control = "public, max-age=86400"
|
cache_control = "public, max-age=86400"
|
||||||
|
@ -64,7 +64,7 @@ class Dir
|
|||||||
path = File.join dirname, fn
|
path = File.join dirname, fn
|
||||||
if File.directory? path
|
if File.directory? path
|
||||||
signatures << Dir.contents_signature path, cache
|
signatures << Dir.contents_signature path, cache
|
||||||
if DirectoryEntry.validate_directory_entry path
|
if DirEntry.validate_directory_entry path
|
||||||
signatures << fn
|
signatures << fn
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -84,7 +84,7 @@ class Dir
|
|||||||
return cache[dirname + "?entry"] if cache[dirname + "?entry"]?
|
return cache[dirname + "?entry"] if cache[dirname + "?entry"]?
|
||||||
Fiber.yield
|
Fiber.yield
|
||||||
signatures = [] of String
|
signatures = [] of String
|
||||||
image_files = DirectoryEntry.get_valid_files_sorted dirname
|
image_files = DirEntry.get_valid_files_sorted dirname
|
||||||
if image_files.size > 0
|
if image_files.size > 0
|
||||||
image_files.each do |path|
|
image_files.each do |path|
|
||||||
signatures << File.signature(path).to_s
|
signatures << File.signature(path).to_s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user