mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Ignore invalid zip files in library
This commit is contained in:
parent
98baf63b0c
commit
f837be0718
@ -66,12 +66,27 @@ class Title
|
||||
@encoded_title = URI.encode @title
|
||||
@entries = (Dir.entries dir)
|
||||
.select { |path| [".zip", ".cbz"].includes? File.extname path }
|
||||
.map { |path| File.join dir, path }
|
||||
.select { |path| valid_zip path }
|
||||
.map { |path|
|
||||
Entry.new File.join(dir, path), @title, @id, storage
|
||||
Entry.new path, @title, @id, storage
|
||||
}
|
||||
.select { |e| e.pages > 0 }
|
||||
.sort { |a, b| a.title <=> b.title }
|
||||
end
|
||||
# When downloading from MangaDex, the zip/cbz file would not be valid
|
||||
# before the download is completed. If we scan the zip file,
|
||||
# Entry.new would throw, so we use this method to check before
|
||||
# constructing Entry
|
||||
private def valid_zip(path : String)
|
||||
begin
|
||||
file = Zip::File.new path
|
||||
file.close
|
||||
return true
|
||||
rescue
|
||||
return false
|
||||
end
|
||||
end
|
||||
def get_entry(eid)
|
||||
@entries.find { |e| e.id == eid }
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user