Skip to content

Commit

Permalink
shared attr.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Jan 4, 2023
1 parent 7935bb4 commit c1b1bd7
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 147 deletions.
9 changes: 7 additions & 2 deletions cutpaste.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func edtrenameAPI(w http.ResponseWriter, r *http.Request, auth *Profile) {
Dst string `json:"dst" yaml:"dst" xml:"dst"`
Ovw bool `json:"overwrite,omitempty" yaml:"overwrite,omitempty" xml:"overwrite,omitempty,attr"`
}
var ret struct {
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"`

Prop FileKit `json:"prop" yaml:"prop" xml:"prop"`
}

// get arguments
if err = ParseBody(w, r, &arg); err != nil {
Expand Down Expand Up @@ -234,9 +239,9 @@ func edtrenameAPI(w http.ResponseWriter, r *http.Request, auth *Profile) {
WriteError500(w, r, err, AECedtrenstat)
return
}
var prop = MakeProp(session, dstpath, fi)
ret.Prop.Setup(session, dstpath, fi)

WriteOK(w, r, prop)
WriteOK(w, r, &ret)
}

// APIHANDLER
Expand Down
56 changes: 2 additions & 54 deletions fileprop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,6 @@ import (
"path"
)

func GetPropSize(p any) (int64, bool) {
switch v := p.(type) {
case *FileKit:
return v.Size, true
case *DirKit:
return v.Size, true
case *ExifKit:
return v.Size, true
case *TagKit:
return v.Size, true
default:
return 0, false
}
}

func GetPropType(p any) (FT_t, bool) {
switch v := p.(type) {
case *FileKit:
return v.Type, true
case *DirKit:
return v.Type, true
case *ExifKit:
return v.Type, true
case *TagKit:
return v.Type, true
default:
return 0, false
}
}

// FileProp is common file properties chunk.
type FileProp struct {
Name string `xorm:"'name'" json:"name" yaml:"name" xml:"name"`
Expand All @@ -53,7 +23,8 @@ func (fp *FileProp) Setup(fi fs.FileInfo) {

// PuidProp encapsulated path unique ID value for some properties kit.
type PuidProp struct {
PUID Puid_t `xorm:"'puid'" json:"puid" yaml:"puid" xml:"puid"`
PUID Puid_t `xorm:"'puid'" json:"puid" yaml:"puid" xml:"puid"`
Shared bool `xorm:"'shared'" json:"shared" yaml:"shared" xml:"shared"`
}

func (pp *PuidProp) Setup(session *Session, syspath string) {
Expand Down Expand Up @@ -146,27 +117,4 @@ func (dk *DirKit) Setup(session *Session, syspath string, fi fs.FileInfo) {
dk.DirProp, _ = DirStoreGet(session, dk.PUID)
}

// MakeProp is file properties factory.
func MakeProp(session *Session, syspath string, fi fs.FileInfo) any {
if fi.IsDir() {
var dk DirKit
dk.Setup(session, syspath, fi)
return &dk
}
var ext = GetFileExt(syspath)
if IsTypeID3(ext) {
var tk TagKit
tk.Setup(session, syspath, fi)
return &tk
} else if IsTypeEXIF(ext) {
var ek ExifKit
ek.Setup(session, syspath, fi)
return &ek
} else {
var fk FileKit
fk.Setup(session, syspath, fi)
return &fk
}
}

// The End.
5 changes: 3 additions & 2 deletions folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ func folderAPI(w http.ResponseWriter, r *http.Request) {
WriteError500(w, r, err, AECfolderhome)
return
}
go func() {
go SqlSession(func(session *Session) (res any, err error) {
DirStoreSet(session, &DirStore{
Puid: puid,
Prop: lstp,
})
}()
return
})
case PUIDdrives:
if ret.List, err = prf.ScanRoots(session); err != nil {
WriteError500(w, r, err, AECfolderdrives)
Expand Down
4 changes: 2 additions & 2 deletions frontend/devmode/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ const VueMapCard = {
uncached.push(tp)
}
}
this.addmarkers(gpslist);
self.addmarkers(gpslist);
// check cached state loop
if (!uncached.length) {
return;
Expand All @@ -1800,7 +1800,7 @@ const VueMapCard = {
}
}
}
this.addmarkers(gpslist);
self.addmarkers(gpslist);
return;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/devmode/devmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is included only for developer mode linkage

const buildvers = "0.9.0";
const builddate = "2022.12.11";
const builddate = "2023.01.04";
console.info("version: %s, builton: %s", buildvers, builddate);
console.info("starts in developer mode");

Expand Down
42 changes: 0 additions & 42 deletions frontend/devmode/mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,6 @@ const VueMainApp = {
readonly: true, // can't modify content of folder

selfile: null, // current selected item
shared: [], // list of shared items

delfile: null, // file to delete
delensured: false, // deletion request

Expand Down Expand Up @@ -743,7 +741,6 @@ const VueMainApp = {

// update folder settings
this.flist = newlist ?? [];
this.updateshared();

// update page data
this.curscan = new Date(Date.now());
Expand All @@ -753,18 +750,6 @@ const VueMainApp = {
this.$refs.page.scrollTop = 0;
},

async fetchshared() {
const response = await fetchajaxauth("POST", "/api/res/folder", {
aid: this.aid, path: PUID.shares
});
traceajax(response);
if (!response.ok) {
throw new HttpError(response.status, response.data);
}
this.shared = response.data.list ?? [];
this.updateshared();
},

async fetchshareadd(file) {
const response = await fetchajaxauth("POST", "/api/share/add", {
aid: this.aid,
Expand All @@ -775,7 +760,6 @@ const VueMainApp = {
throw new HttpError(response.status, response.data);
}
file.shared = true; // Vue.set
this.shared.push(file);
},

async fetchsharedel(file) {
Expand All @@ -791,26 +775,6 @@ const VueMainApp = {
// update folder settings
if (response.data.deleted) { // on ok
file.shared = false; // Vue.set
for (let i = 0; i < this.shared.length;) {
if (this.shared[i].puid === file.puid) {
this.shared.splice(i, 1);
} else {
i++;
}
}
}
},

updateshared() {
for (const file of this.flist) {
let sf = false;
for (const shr of this.shared) {
if (shr.puid === file.puid) {
sf = true;
break;
}
}
file.shared = sf; // Vue.set
}
},

Expand Down Expand Up @@ -937,9 +901,6 @@ const VueMainApp = {
eventHub.emit('ajax', +1);
try {
await this.fetchfolder({ aid: this.aid, path: this.curpuid ?? this.curpath });
if (this.isadmin && this.curpuid !== PUID.shares) {
await this.fetchshared(); // get shares
}
} catch (e) {
ajaxfail(e);
} finally {
Expand Down Expand Up @@ -1204,9 +1165,6 @@ const VueMainApp = {

// open route and push history step
await this.fetchfolder(hist);
if (this.isadmin && hist.puid !== PUID.shares) {
await this.fetchshared(); // get shares
}
this.pushhist(hist);
} catch (e) {
ajaxfail(e);
Expand Down
2 changes: 1 addition & 1 deletion frontend/devmode/relmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is included for release mode linkage

const buildvers = "0.8.4";
const builddate = "2022.11.26";
const builddate = "2023.01.04";
const devmode = false;

const traceajax = () => undefined;
Expand Down
58 changes: 34 additions & 24 deletions gps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"io/fs"
"math"
"net/http"

"golang.org/x/sync/errgroup"
)

// Haversine uses formula to calculate the great-circle distance between
Expand Down Expand Up @@ -194,14 +192,8 @@ func gpsscanAPI(w http.ResponseWriter, r *http.Request) {
return
}

var wg errgroup.Group
var session = xormStorage.NewSession()
defer func() {
go func() {
wg.Wait()
session.Close()
}()
}()
defer session.Close()

var prf *Profile
if prf = prflist.ByID(arg.AID); prf == nil {
Expand All @@ -213,6 +205,7 @@ func gpsscanAPI(w http.ResponseWriter, r *http.Request) {
return
}

var ests []ExifStore
for _, puid := range arg.List {
var puid = puid // localize
if syspath, ok := PathStorePath(session, puid); ok {
Expand All @@ -225,33 +218,50 @@ func gpsscanAPI(w http.ResponseWriter, r *http.Request) {
ret.List = append(ret.List, gst)
} else {
// check memory cache
if ok = exifcache.Has(puid); ok {
if exifcache.Has(puid) {
continue // there are tags without GPS
}
// try to extract from file
var ep ExifProp
if err := ep.Extract(syspath); err != nil {
continue
}
if ok = !ep.IsZero(); ok {
wg.Go(func() (err error) {
return ExifStoreSet(session, &ExifStore{ // update database
Puid: puid,
Prop: ep,
})
})
// try to get from database
var est ExifStore
est.Puid = puid
if ok, _ = session.Get(&est); ok { // skip errors
exifcache.Push(puid, est.Prop) // update cache
if est.Prop.IsZero() {
continue
}
} else {
// try to extract from file
if err := est.Prop.Extract(syspath); err != nil {
continue
}
if est.Prop.IsZero() {
continue
}
// set to memory cache
exifcache.Push(puid, est.Prop)
// prepare to set to database
ests = append(ests, est)
}
if ep.Latitude != 0 || ep.Longitude != 0 {
if est.Prop.Latitude != 0 || est.Prop.Longitude != 0 {
var gst Store[GpsInfo]
gst.Puid = puid
gst.Prop.FromProp(&ep)
gst.Prop.FromProp(&est.Prop)
ret.List = append(ret.List, gst)
// set to GPS cache
gpscache.Store(puid, gst.Prop)
}
}
}
}
}

if len(ests) > 0 {
go SqlSession(func(session *Session) (res any, err error) {
_, err = session.Insert(&ests)
return
})
}

WriteOK(w, r, &ret)
}

Expand Down
11 changes: 7 additions & 4 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ func propAPI(w http.ResponseWriter, r *http.Request) {
var ret struct {
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"`

Path string `json:"path" yaml:"path" xml:"path"`
Name string `json:"shrname" yaml:"shrname" xml:"shrname"`
Prop any `json:"prop" yaml:"prop" xml:"prop"`
Path string `json:"path" yaml:"path" xml:"path"`
Name string `json:"shrname" yaml:"shrname" xml:"shrname"`
Prop FileKit `json:"prop" yaml:"prop" xml:"prop"`
}

// get arguments
Expand Down Expand Up @@ -638,7 +638,8 @@ func propAPI(w http.ResponseWriter, r *http.Request) {
WriteError500(w, r, err, AECpropbadstat)
return
}
ret.Prop = MakeProp(session, syspath, fi)
ret.Prop.Setup(session, syspath, fi)
ret.Prop.Shared = prf.IsShared(syspath)

WriteOK(w, r, &ret)
}
Expand Down Expand Up @@ -702,6 +703,7 @@ func ispathAPI(w http.ResponseWriter, r *http.Request, auth *Profile) {

var fk FileKit
fk.Setup(session, syspath, fi)
fk.Shared = prf.IsShared(syspath)
WriteOK(w, r, &fk)
}

Expand Down Expand Up @@ -864,6 +866,7 @@ func drvaddAPI(w http.ResponseWriter, r *http.Request, auth *Profile) {

var fk FileKit
fk.PUID = puid
fk.Shared = prf.IsShared(syspath)
fk.Name = path.Base(syspath)
fk.Type = FTdrv
fk.Size = fi.Size()
Expand Down
Loading

0 comments on commit c1b1bd7

Please sign in to comment.