-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreviews.go
86 lines (74 loc) · 1.77 KB
/
previews.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package luminosity
import (
"fmt"
"path/filepath"
"strings"
)
type CatalogPreviews struct {
Catalog *Catalog
root string
db *DB
}
func openCatalogPreviews(cat *Catalog) (*CatalogPreviews, error) {
p := &CatalogPreviews{
Catalog: cat,
root: previewsRootPath(cat),
}
if db, err := OpenDB(p.DbPath()); err != nil {
return nil, err
} else {
p.db = db
return p, nil
}
}
func previewsRootPath(cat *Catalog) string {
dir, file := filepath.Split(cat.Path())
basename := strings.TrimSuffix(file, CatalogExtension)
return filepath.Join(dir, basename+" Previews.lrdata")
}
func (c *CatalogPreviews) Close() error {
if err := c.db.Close(); err != nil {
return err
}
return nil
}
func (c *CatalogPreviews) Path() string {
return c.root
}
func (c *CatalogPreviews) DbPath() string {
return filepath.Join(c.root, "previews.db")
}
func (c *CatalogPreviews) GetPhotoCacheInfo(p *PhotoRecord) (*PhotoCacheInfo, error) {
const query = `
SELECT ice.imageId,
ice.uuid,
ice.digest,
max(pl.level)
FROM ImageCacheEntry ice
INNER JOIN PyramidLevel pl
ON pl.uuid = ice.uuid
`
var where = fmt.Sprintf(" WHERE ice.imageId = %d", p.Id)
row := c.db.queryRow("get_photo_cache_info", query+where)
ci := &PhotoCacheInfo{
previews: c,
}
if err := row.Scan(&ci.Id, &ci.UUID, &ci.Digest, &ci.MaxLevel); err != nil {
return nil, err
} else {
return ci, nil
}
}
type PhotoCacheInfo struct {
previews *CatalogPreviews
Id int `json:"id"`
UUID string `json:"uuid"`
Digest string `json:"digest"`
MaxLevel int `json:"max_level"`
}
func (ci *PhotoCacheInfo) Path() string {
return filepath.Join(ci.previews.Path(),
string(ci.UUID[0]),
string(ci.UUID[0:4]),
fmt.Sprintf("%s-%s.lrprev", ci.UUID, ci.Digest))
}