2017-08-19 11:35:44 +00:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/asdine/storm"
|
2017-08-20 07:49:09 +00:00
|
|
|
"github.com/asdine/storm/q"
|
2017-08-19 11:35:44 +00:00
|
|
|
fm "github.com/hacdias/filemanager"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ShareStore struct {
|
|
|
|
DB *storm.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ShareStore) Get(hash string) (*fm.ShareLink, error) {
|
|
|
|
var v *fm.ShareLink
|
|
|
|
err := s.DB.One("Hash", hash, &v)
|
2017-08-20 07:42:38 +00:00
|
|
|
if err == storm.ErrNotFound {
|
|
|
|
return v, fm.ErrNotExist
|
|
|
|
}
|
|
|
|
|
2017-08-19 11:35:44 +00:00
|
|
|
return v, err
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:49:09 +00:00
|
|
|
func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) {
|
|
|
|
var v *fm.ShareLink
|
|
|
|
err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v)
|
|
|
|
if err == storm.ErrNotFound {
|
|
|
|
return v, fm.ErrNotExist
|
|
|
|
}
|
|
|
|
|
|
|
|
return v, err
|
|
|
|
}
|
|
|
|
|
2017-08-19 11:35:44 +00:00
|
|
|
func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) {
|
|
|
|
var v []*fm.ShareLink
|
|
|
|
err := s.DB.Find("Path", hash, &v)
|
2017-08-20 07:42:38 +00:00
|
|
|
if err == storm.ErrNotFound {
|
|
|
|
return v, fm.ErrNotExist
|
|
|
|
}
|
|
|
|
|
2017-08-19 11:35:44 +00:00
|
|
|
return v, err
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:42:38 +00:00
|
|
|
func (s ShareStore) Gets() ([]*fm.ShareLink, error) {
|
2017-08-19 11:35:44 +00:00
|
|
|
var v []*fm.ShareLink
|
|
|
|
err := s.DB.All(&v)
|
|
|
|
return v, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ShareStore) Save(l *fm.ShareLink) error {
|
|
|
|
return s.DB.Save(l)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ShareStore) Delete(hash string) error {
|
|
|
|
return s.DB.DeleteStruct(&fm.ShareLink{Hash: hash})
|
|
|
|
}
|