mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-04 03:45:32 -04:00
parent
fc6a33e5fd
commit
39f4897fc5
@ -106,7 +106,13 @@ class Title
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
if [".zip", ".cbz"].includes? File.extname path
|
if [".zip", ".cbz"].includes? File.extname path
|
||||||
next if !valid_zip path
|
zip_exception = validate_zip path
|
||||||
|
unless zip_exception.nil?
|
||||||
|
@logger.warn "File #{path} is corrupted or is not a valid zip " \
|
||||||
|
"archive. Ignoring it."
|
||||||
|
@logger.debug "Zip error: #{zip_exception}"
|
||||||
|
next
|
||||||
|
end
|
||||||
entry = Entry.new path, self, @id, storage
|
entry = Entry.new path, self, @id, storage
|
||||||
@entries << entry if entry.pages > 0
|
@entries << entry if entry.pages > 0
|
||||||
end
|
end
|
||||||
@ -171,20 +177,6 @@ class Title
|
|||||||
@entries.size + @title_ids.size
|
@entries.size + @title_ids.size
|
||||||
end
|
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)
|
|
||||||
file = Zip::File.new path
|
|
||||||
file.close
|
|
||||||
true
|
|
||||||
rescue
|
|
||||||
@logger.warn "File #{path} is corrupted or is not a valid zip " \
|
|
||||||
"archive. Ignoring it."
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_entry(eid)
|
def get_entry(eid)
|
||||||
@entries.find { |e| e.id == eid }
|
@entries.find { |e| e.id == eid }
|
||||||
end
|
end
|
||||||
|
@ -343,10 +343,16 @@ module MangaDex
|
|||||||
"#{fail_count}/#{page_jobs.size} failed"
|
"#{fail_count}/#{page_jobs.size} failed"
|
||||||
writer.close
|
writer.close
|
||||||
@logger.debug "cbz File created at #{zip_path}"
|
@logger.debug "cbz File created at #{zip_path}"
|
||||||
if fail_count == 0
|
|
||||||
@queue.set_status JobStatus::Completed, job
|
zip_exception = validate_zip zip_path
|
||||||
else
|
if !zip_exception.nil?
|
||||||
|
@queue.add_message "The downloaded archive is corrupted. " \
|
||||||
|
"Error: #{zip_exception}", job
|
||||||
|
@queue.set_status JobStatus::Error, job
|
||||||
|
elsif fail_count > 0
|
||||||
@queue.set_status JobStatus::MissingPages, job
|
@queue.set_status JobStatus::MissingPages, job
|
||||||
|
else
|
||||||
|
@queue.set_status JobStatus::Completed, job
|
||||||
end
|
end
|
||||||
@downloading = false
|
@downloading = false
|
||||||
end
|
end
|
||||||
|
12
src/util.cr
12
src/util.cr
@ -81,3 +81,15 @@ end
|
|||||||
def compare_alphanumerically(a : String, b : String)
|
def compare_alphanumerically(a : String, b : String)
|
||||||
compare_alphanumerically split_by_alphanumeric(a), split_by_alphanumeric(b)
|
compare_alphanumerically split_by_alphanumeric(a), split_by_alphanumeric(b)
|
||||||
end
|
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
|
||||||
|
def validate_zip(path : String) : Exception?
|
||||||
|
file = Zip::File.new path
|
||||||
|
file.close
|
||||||
|
return
|
||||||
|
rescue e
|
||||||
|
e
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user