Rename interesting files to supported files

This commit is contained in:
Alex Ling 2021-01-26 10:55:50 +00:00
parent 0ba2409c9a
commit def64d9f98
4 changed files with 16 additions and 19 deletions

View File

@ -35,23 +35,20 @@ describe "compare_numerically" do
end end
end end
describe "is_interesting_file" do describe "is_supported_file" do
it "returns true when filename has interesting file extension" do it "returns true when the filename has a supported extension" do
filename = "manga.cbz" filename = "manga.cbz"
result = is_interesting_file filename is_supported_file(filename).should eq true
result.should eq true
end end
it "returns false if file extension is not interesting" do it "returns true when the filename does not have a supported extension" do
filename = "info.json" filename = "info.json"
result = is_interesting_file filename is_supported_file(filename).should eq false
result.should eq false
end end
it "returns true when fileext has uppercase" do it "is case insensitive" do
filename = "manga.ZiP" filename = "manga.ZiP"
result = is_interesting_file filename is_supported_file(filename).should eq true
result.should eq true
end end
end end

View File

@ -36,7 +36,7 @@ class Title
@title_ids << title.id @title_ids << title.id
next next
end end
if is_interesting_file path if is_supported_file path
entry = Entry.new path, self entry = Entry.new path, self
@entries << entry if entry.pages > 0 || entry.err_msg @entries << entry if entry.pages > 0 || entry.err_msg
end end

View File

@ -13,7 +13,7 @@ class File
# ensures that moving (unless to another device) and renaming the file # ensures that moving (unless to another device) and renaming the file
# preserves the signature, while copying or editing the file changes it. # preserves the signature, while copying or editing the file changes it.
def self.signature(filename) : UInt64 def self.signature(filename) : UInt64
return 0u64 unless is_interesting_file filename return 0u64 unless is_supported_file filename
info = File.info filename info = File.info filename
signatures = [ signatures = [
info.inode, info.inode,

View File

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