add and apply util method is_interesting_file

This commit is contained in:
Leeingnyo 2021-01-26 04:14:17 +09:00
parent c51cb28df2
commit 2b0cf41336
3 changed files with 13 additions and 6 deletions

View File

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

View File

@ -1,3 +1,5 @@
require "./util"
class File
abstract struct Info
def inode
@ -11,7 +13,7 @@ class File
# ensures that moving (unless to another device) and renaming the file
# preserves the signature, while copying or editing the file changes it.
def self.signature(filename) : UInt64
return 0u64 unless %w(.zip .rar .cbz .cbr).includes? File.extname filename
return 0u64 unless is_interesting_file filename
info = File.info filename
signatures = [
info.inode,

View File

@ -1,7 +1,8 @@
IMGS_PER_PAGE = 5
ENTRIES_IN_HOME_SECTIONS = 8
UPLOAD_URL_PREFIX = "/uploads"
STATIC_DIRS = ["/css", "/js", "/img", "/favicon.ico"]
IMGS_PER_PAGE = 5
ENTRIES_IN_HOME_SECTIONS = 8
UPLOAD_URL_PREFIX = "/uploads"
STATIC_DIRS = ["/css", "/js", "/img", "/favicon.ico"]
INTERESTING_FILE_EXTNAMES = [".zip", ".cbz", ".rar", ".cbr"]
def random_str
UUID.random.to_s.gsub "-", ""
@ -31,6 +32,10 @@ def register_mime_types
end
end
def is_interesting_file(path)
INTERESTING_FILE_EXTNAMES.includes? (File.extname path).downcase
end
struct Int
def or(other : Int)
if self == 0