mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -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)
|
def initialize(@data, @mime, @filename, @size)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class TitleInfo
|
class TitleInfo
|
||||||
|
@ -35,9 +35,11 @@ class Storage
|
|||||||
MainFiber.run do
|
MainFiber.run do
|
||||||
DB.open "sqlite3://#{@path}" do |db|
|
DB.open "sqlite3://#{@path}" do |db|
|
||||||
begin
|
begin
|
||||||
# We create the `ids` table first. even if the uses has an
|
db.exec "create table thumbnails " \
|
||||||
# early version installed and has the `user` table only,
|
"(id text, data blob, filename text, " \
|
||||||
# we will still be able to create `ids`
|
"mime text, size integer)"
|
||||||
|
db.exec "create unique index tn_index on thumbnails (id)"
|
||||||
|
|
||||||
db.exec "create table ids" \
|
db.exec "create table ids" \
|
||||||
"(path text, id text, is_title integer)"
|
"(path text, id text, is_title integer)"
|
||||||
db.exec "create unique index path_idx on ids (path)"
|
db.exec "create unique index path_idx on ids (path)"
|
||||||
@ -243,6 +245,27 @@ class Storage
|
|||||||
end
|
end
|
||||||
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
|
def close
|
||||||
MainFiber.run do
|
MainFiber.run do
|
||||||
unless @db.nil?
|
unless @db.nil?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user