diff --git a/src/library/entry.cr b/src/library/entry.cr index 77af3e5..ef0556d 100644 --- a/src/library/entry.cr +++ b/src/library/entry.cr @@ -15,9 +15,9 @@ abstract class Entry def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) # TODO: check node? and select proper subclass - ZippedEntry.new ctx, node + ArchiveEntry.new ctx, node rescue e - DirectoryEntry.new ctx, node + DirEntry.new ctx, node end def build_json(*, slim = false) @@ -230,7 +230,7 @@ abstract class Entry abstract def examine : Bool? end -class ZippedEntry < Entry +class ArchiveEntry < Entry include YAML::Serializable getter zip_path : String @@ -341,7 +341,7 @@ class ZippedEntry < Entry end end -class DirectoryEntry < Entry +class DirEntry < Entry include YAML::Serializable getter dir_path : String @@ -364,7 +364,7 @@ class DirectoryEntry < Entry return 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." Logger.warn "#{@err_msg} Please make sure the " \ "directory has valid images." @@ -441,7 +441,7 @@ class DirectoryEntry < Entry def examine : Bool existence = File.exists? @dir_path 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 existence = files.size > 0 && @signature == signature @sorted_files = nil unless existence @@ -454,12 +454,12 @@ class DirectoryEntry < Entry def sorted_files cached_sorted_files = @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! end def self.validate_directory_entry(dir_path) - files = DirectoryEntry.get_valid_files dir_path + files = DirEntry.get_valid_files dir_path files.size > 0 end @@ -477,7 +477,7 @@ class DirectoryEntry < Entry end 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 } end end diff --git a/src/library/title.cr b/src/library/title.cr index f3b4866..3f30490 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -53,14 +53,14 @@ class Title Library.default.title_hash[title.id] = title @title_ids << title.id end - if DirectoryEntry.validate_directory_entry path - entry = DirectoryEntry.new path, self + if DirEntry.validate_directory_entry path + entry = DirEntry.new path, self @entries << entry if entry.pages > 0 || entry.err_msg end next end if is_supported_file path - entry = ZippedEntry.new path, self + entry = ArchiveEntry.new path, self @entries << entry if entry.pages > 0 || entry.err_msg end end @@ -146,8 +146,8 @@ class Title path = File.join dir, fn if File.directory? path unless remained_entry_paths.includes? path - if DirectoryEntry.validate_directory_entry path - entry = DirectoryEntry.new path, self + if DirEntry.validate_directory_entry path + entry = DirEntry.new path, self if entry.pages > 0 || entry.err_msg @entries << entry is_entries_added = true @@ -181,7 +181,7 @@ class Title end if is_supported_file 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 @entries << entry is_entries_added = true diff --git a/src/routes/api.cr b/src/routes/api.cr index bf2c4c9..509f13d 100644 --- a/src/routes/api.cr +++ b/src/routes/api.cr @@ -142,7 +142,7 @@ struct APIRouter env.response.status_code = 304 "" else - if entry.is_a? DirectoryEntry + if entry.is_a? DirEntry cache_control = "no-cache, max-age=86400" else cache_control = "public, max-age=86400" @@ -1143,7 +1143,7 @@ struct APIRouter entry = title.get_entry eid 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) else file_hash = Digest::SHA1.hexdigest(entry.path + entry.mtime.to_s) @@ -1154,7 +1154,7 @@ struct APIRouter send_text env, "" else sizes = entry.page_dimensions - if entry.is_a? DirectoryEntry + if entry.is_a? DirEntry cache_control = "no-cache, max-age=86400" else cache_control = "public, max-age=86400" diff --git a/src/util/signature.cr b/src/util/signature.cr index 904d4e6..b5fe781 100644 --- a/src/util/signature.cr +++ b/src/util/signature.cr @@ -64,7 +64,7 @@ class Dir path = File.join dirname, fn if File.directory? path signatures << Dir.contents_signature path, cache - if DirectoryEntry.validate_directory_entry path + if DirEntry.validate_directory_entry path signatures << fn end else @@ -84,7 +84,7 @@ class Dir return cache[dirname + "?entry"] if cache[dirname + "?entry"]? Fiber.yield signatures = [] of String - image_files = DirectoryEntry.get_valid_files_sorted dirname + image_files = DirEntry.get_valid_files_sorted dirname if image_files.size > 0 image_files.each do |path| signatures << File.signature(path).to_s