mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
Update DB to save thumbnails
This commit is contained in:
parent
ad940f30d5
commit
968c2f4ad5
@ -57,6 +57,16 @@ struct Image
|
||||
|
||||
def initialize(@data, @mime, @filename, @size)
|
||||
end
|
||||
|
||||
def self.from_db(res : DB::ResultSet)
|
||||
img = Image.allocate
|
||||
res.read String
|
||||
img.data = res.read Bytes
|
||||
img.filename = res.read String
|
||||
img.mime = res.read String
|
||||
img.size = res.read Int32
|
||||
img
|
||||
end
|
||||
end
|
||||
|
||||
class TitleInfo
|
||||
|
@ -35,9 +35,11 @@ class Storage
|
||||
MainFiber.run do
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
begin
|
||||
# We create the `ids` table first. even if the uses has an
|
||||
# early version installed and has the `user` table only,
|
||||
# we will still be able to create `ids`
|
||||
db.exec "create table thumbnails " \
|
||||
"(id text, data blob, filename text, " \
|
||||
"mime text, size integer)"
|
||||
db.exec "create unique index tn_index on thumbnails (id)"
|
||||
|
||||
db.exec "create table ids" \
|
||||
"(path text, id text, is_title integer)"
|
||||
db.exec "create unique index path_idx on ids (path)"
|
||||
@ -243,6 +245,27 @@ class Storage
|
||||
end
|
||||
end
|
||||
|
||||
def save_thumbnail(id : String, img : Image)
|
||||
MainFiber.run do
|
||||
get_db do |db|
|
||||
db.exec "insert into thumbnails values (?, ?, ?, ?, ?)", id, img.data,
|
||||
img.filename, img.mime, img.size
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_thumbnail(id : String) : Image?
|
||||
img = nil
|
||||
MainFiber.run do
|
||||
get_db do |db|
|
||||
db.query_one? "select * from thumbnails where id = (?)", id do |res|
|
||||
img = Image.from_db res
|
||||
end
|
||||
end
|
||||
end
|
||||
img
|
||||
end
|
||||
|
||||
def close
|
||||
MainFiber.run do
|
||||
unless @db.nil?
|
||||
|
Loading…
x
Reference in New Issue
Block a user