Skip to content

Commit

Permalink
refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed May 5, 2022
1 parent 3741bb9 commit 5189ba0
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 105 deletions.
19 changes: 17 additions & 2 deletions caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ var (
diskcache gcache.Cache
)

// package caches
var (
// cache with images thumbnails which are placed in box 256x256.
thumbpkg *CachePackage
// cache with images tiles, size of each tile is placed as sufix
// of path in format "full/path/to/file.ext?144x108".
tilespkg *CachePackage
)

// Error messages
var (
ErrNoPUID = errors.New("file with given puid not found")
Expand Down Expand Up @@ -469,12 +478,17 @@ func GetCachedTile(syspath string, wdh, hgt int) (md *MediaData, err error) {
return
}

// CachePackage describes package cache functionality.
// Package splitted in two files - tags table file and
// cached images data file.
type CachePackage struct {
*fsys.Package
WPT wpk.WriteSeekCloser // package tags part
WPF wpk.WriteSeekCloser // package files part
}

// InitCacheWriter opens existing cache with given file name placed in
// cache directory, or creates new cache file if no one found.
func InitCacheWriter(fname string) (cw *CachePackage, err error) {
var pkgpath = wpk.MakeTagsPath(path.Join(CachePath, fname))
var datpath = wpk.MakeDataPath(path.Join(CachePath, fname))
Expand Down Expand Up @@ -518,6 +532,7 @@ func InitCacheWriter(fname string) (cw *CachePackage, err error) {
return
}

// Close saves actual tags table and closes opened cache.
func (cw *CachePackage) Close() (err error) {
if et := cw.Sync(cw.WPT, cw.WPF); et != nil && err == nil {
err = et
Expand All @@ -532,6 +547,7 @@ func (cw *CachePackage) Close() (err error) {
return
}

// GetImage extracts image from the cache with given file name.
func (cw *CachePackage) GetImage(fpath string) (md *MediaData, err error) {
if ts, ok := cw.Tagset(fpath); ok {
var str string
Expand Down Expand Up @@ -572,8 +588,7 @@ func (cw *CachePackage) PutImage(fpath string, md *MediaData) (err error) {
return
}

var thumbpkg, tilespkg *CachePackage

// PackInfo writes info to log about opened cache.
func PackInfo(fname string, pack wpk.Packager) {
var num, size int64
pack.Enum(func(fkey string, ts *wpk.Tagset_t) bool {
Expand Down
6 changes: 4 additions & 2 deletions exifprop.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ type ExifProp struct {
Flash int `json:"flash,omitempty" yaml:"flash,omitempty"`
UniqueID string `json:"uniqueid,omitempty" yaml:"uniqueid,omitempty"`
ThumbJpegLen int `json:"thumbjpeglen,omitempty" yaml:"thumbjpeglen,omitempty"`
thumbJpeg []byte
// GPS
Latitude float64 `json:"latitude,omitempty" yaml:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty" yaml:"longitude,omitempty"`
Altitude float64 `json:"altitude,omitempty" yaml:"altitude,omitempty"`
Satelites string `json:"satelites,omitempty" yaml:"satelites,omitempty"`
// private
thumb MediaData
}

func ratfloat(t *tiff.Tag) float64 {
Expand Down Expand Up @@ -167,7 +168,8 @@ func (ep *ExifProp) Setup(x *exif.Exif) {
ep.ThumbJpegLen, _ = t.Int(0)
}
if pic, err = x.JpegThumbnail(); err == nil {
ep.thumbJpeg = pic
ep.thumb.Data = pic
ep.thumb.Mime = MimeJpeg
}
if lat, lng, err := x.LatLong(); err == nil {
ep.Latitude, ep.Longitude = lat, lng
Expand Down
26 changes: 13 additions & 13 deletions fileprop.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,20 @@ func (fg *FileGrp) IsZero() bool {

// PathBase returns safe base of path or CID as is.
func PathBase(syspath string) string {
if len(syspath) > 0 {
var pos1 int
var pos2 = len(syspath)
if syspath[0] == '[' && syspath[pos2-1] == ']' {
return syspath
}
if syspath[pos2-1] == '/' || syspath[pos2-1] == '\\' {
pos2--
}
for pos1 = pos2; pos1 > 0 && syspath[pos1-1] != '/' && syspath[pos1-1] != '\\'; pos1-- {
}
return syspath[pos1:pos2]
var pos1 int
var pos2 = len(syspath)
if pos2 == 0 {
return ""
}
if syspath[0] == '<' && syspath[pos2-1] == '>' {
return syspath
}
if syspath[pos2-1] == '/' || syspath[pos2-1] == '\\' {
pos2--
}
for pos1 = pos2; pos1 > 0 && syspath[pos1-1] != '/' && syspath[pos1-1] != '\\'; pos1-- {
}
return syspath
return syspath[pos1:pos2]
}

// DirProp is directory properties chunk.
Expand Down
69 changes: 68 additions & 1 deletion frontend/devmode/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,24 @@ const VueDirCard = {
},
onunselect() {
eventHub.emit('select', null);
},
onshown(e) {
},
onhidden(e) {
}
},
mounted() {
const el = document.getElementById('card' + this.iid);
if (el) {
el.addEventListener('shown.bs.collapse', this.onshown);
el.addEventListener('hidden.bs.collapse', this.onhidden);
}
},
unmounted() {
const el = document.getElementById('card' + this.iid);
if (el) {
el.removeEventListener('shown.bs.collapse', this.onshown);
el.removeEventListener('hidden.bs.collapse', this.onhidden);
}
}
};
Expand Down Expand Up @@ -494,13 +512,27 @@ const VueFileCard = {
},
onaudioonly(val) {
this.audioonly = val;
},
onshown(e) {
},
onhidden(e) {
}
},
created() {
mounted() {
eventHub.on('audioonly', this.onaudioonly);
const el = document.getElementById('card' + this.iid);
if (el) {
el.addEventListener('shown.bs.collapse', this.onshown);
el.addEventListener('hidden.bs.collapse', this.onhidden);
}
},
unmounted() {
eventHub.off('audioonly', this.onaudioonly);
const el = document.getElementById('card' + this.iid);
if (el) {
el.removeEventListener('shown.bs.collapse', this.onshown);
el.removeEventListener('hidden.bs.collapse', this.onhidden);
}
}
};

Expand Down Expand Up @@ -837,6 +869,24 @@ const VueTileCard = {
onopen(file) {
eventHub.emit('select', file);
eventHub.emit('open', file, this.photolist);
},
onshown(e) {
},
onhidden(e) {
}
},
mounted() {
const el = document.getElementById('card' + this.iid);
if (el) {
el.addEventListener('shown.bs.collapse', this.onshown);
el.addEventListener('hidden.bs.collapse', this.onhidden);
}
},
unmounted() {
const el = document.getElementById('card' + this.iid);
if (el) {
el.removeEventListener('shown.bs.collapse', this.onshown);
el.removeEventListener('hidden.bs.collapse', this.onhidden);
}
}
};
Expand Down Expand Up @@ -1251,9 +1301,19 @@ const VueMapCard = {
this.map.flyToBounds(bounds, {
padding: [20, 20]
});
},
onshown(e) {
},
onhidden(e) {
}
},
mounted() {
const el = document.getElementById('card' + this.iid);
if (el) {
el.addEventListener('shown.bs.collapse', this.onshown);
el.addEventListener('hidden.bs.collapse', this.onhidden);
}

this.tiles = this.maketiles('mapbox-hybrid');
this.map = L.map(this.$refs.map, {
attributionControl: true,
Expand Down Expand Up @@ -1291,6 +1351,13 @@ const VueMapCard = {
return new L.Control.Fullscreen(opts);
};
L.control.fullscreen({ position: 'topright' }).addTo(this.map);
},
unmounted() {
const el = document.getElementById('card' + this.iid);
if (el) {
el.removeEventListener('shown.bs.collapse', this.onshown);
el.removeEventListener('hidden.bs.collapse', this.onhidden);
}
}
};

Expand Down
6 changes: 3 additions & 3 deletions frontend/devmode/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ if (!String.prototype.printf) {
function callback(exp, p0, p1, p2, p3, p4) {
if (exp === '%%') return '%';
if (arr[++i] === undefined) return undefined;
exp = p2 ? parseInt(p2.substr(1)) : undefined;
var base = p3 ? parseInt(p3.substr(1)) : undefined;
exp = p2 ? parseInt(p2.substring(1)) : undefined;
var base = p3 ? parseInt(p3.substring(1)) : undefined;
var val;
switch (p4) {
case 's': val = arr[i]; break;
Expand Down Expand Up @@ -52,7 +52,7 @@ const pathjoin = (...args) => {
}).filter(x => x.length).join('/');
};

const pathext = fname => fname.substr(fname.lastIndexOf('.')).toLowerCase();
const pathext = fname => fname.substring(fname.lastIndexOf('.')).toLowerCase();

const fmtfilesize = (size) => {
if (size < 1536) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/devmode/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@

<!-- common functionality used in all components -->
<script src="/devm/devmode.js?0.8.0"></script>
<script src="/devm/common.js?0.7.6"></script>
<script src="/devm/common.js?0.8.0"></script>
<script src="/devm/request.js?0.7.6"></script>
<!-- register Vue.js components -->
<script src="/devm/fileitem.js?0.8.0"></script>
<script src="/devm/cards.js?0.7.8"></script>
<script src="/devm/cards.js?0.8.0"></script>
<script src="/devm/mp3player.js?0.7.6"></script>
<script src="/devm/slider.js?0.7.8"></script>
<!-- load application script -->
Expand Down
4 changes: 2 additions & 2 deletions frontend/devmode/mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,8 @@ const VueMainApp = {
}

// get profile id
if (chunks[0].substr(0, 2) === "id") {
this.aid = Number(chunks[0].substr(2));
if (chunks[0].substring(0, 2) === "id") {
this.aid = Number(chunks[0].substring(2));
chunks.shift();
} else {
this.aid = 1;
Expand Down
Binary file added frontend/icon/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/icon/blank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ require (
github.com/stretchr/testify v1.7.1 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16C
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 h1:Js08h5hqB5xyWR789+QqueR6sDE8mk+YvpETZ+F6X9Y=
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
40 changes: 19 additions & 21 deletions opendisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,36 +189,34 @@ func OpenDir(syspath string) (ret []fs.FileInfo, err error) {
}

// ScanDir returns file properties list for given file system directory, or directory in iso-disk.
func ScanDir(syspath string, cg *CatGrp, pass func(string) bool) (ret []Pather, skip int, err error) {
func ScanDir(syspath string, cg *CatGrp, filter func(string) bool) (ret []Pather, skip int, err error) {
var files []fs.FileInfo
if files, err = OpenDir(syspath); err != nil {
return
}

if pass == nil {
pass = func(string) bool { return true }
}

var fgrp = FileGrp{}
for _, fi := range files {
if fi != nil {
var fpath = path.Join(syspath, fi.Name())
if pass(fpath) {
var grp = GetFileGroup(fpath)
if cg[grp] {
var prop Pather
if propcache.Has(fpath) {
var pv, _ = propcache.Get(fpath)
prop = pv.(Pather)
} else {
prop = MakeProp(fpath, fi)
propcache.Set(fpath, prop)
}
ret = append(ret, prop)
}
fgrp[grp]++
if fi == nil {
continue
}
var fpath = path.Join(syspath, fi.Name())
if filter != nil && !filter(fpath) {
continue
}
var grp = GetFileGroup(fpath)
if cg[grp] {
var prop Pather
if propcache.Has(fpath) {
var pv, _ = propcache.Get(fpath)
prop = pv.(Pather)
} else {
prop = MakeProp(fpath, fi)
propcache.Set(fpath, prop)
}
ret = append(ret, prop)
}
fgrp[grp]++
}

if pv, err := propcache.Get(syspath); err == nil {
Expand Down
Loading

0 comments on commit 5189ba0

Please sign in to comment.