mirror of
https://github.com/hkalexling/Mango.git
synced 2026-04-03 00:03:14 -04:00
- implement login and load images from zip
This commit is contained in:
@@ -1,4 +1,14 @@
|
||||
require "zip"
|
||||
require "mime"
|
||||
|
||||
class Image
|
||||
property data : Bytes
|
||||
property mime : String
|
||||
property filename : String
|
||||
property size : Int32
|
||||
def initialize(@data, @mime, @filename, @size)
|
||||
end
|
||||
end
|
||||
|
||||
class Entry
|
||||
property zip_path : String
|
||||
@@ -10,6 +20,29 @@ class Entry
|
||||
@title = File.basename path, ".zip"
|
||||
@size = (File.size path).humanize_bytes
|
||||
end
|
||||
def read_page(page_num)
|
||||
Zip::File.open @zip_path do |file|
|
||||
page = file.entries
|
||||
.select { |e|
|
||||
["image/jpeg", "image/png"].includes? \
|
||||
MIME.from_filename? e.filename
|
||||
}
|
||||
.sort { |a, b| a.filename <=> b.filename }
|
||||
.[page_num]
|
||||
page.open do |io|
|
||||
slice = Bytes.new page.uncompressed_size
|
||||
bytes_read = io.read_fully? slice
|
||||
unless bytes_read
|
||||
return nil
|
||||
end
|
||||
return Image.new slice, MIME.from_filename(page.filename),\
|
||||
page.filename, bytes_read
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_cover()
|
||||
read_page 0
|
||||
end
|
||||
end
|
||||
|
||||
class Title
|
||||
@@ -25,6 +58,9 @@ class Title
|
||||
.map { |path| Entry.new File.join dir, path }
|
||||
.sort { |a, b| a.title <=> b.title }
|
||||
end
|
||||
def get_cover()
|
||||
@entries[0].get_cover
|
||||
end
|
||||
end
|
||||
|
||||
class Library
|
||||
|
||||
Reference in New Issue
Block a user