mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
ea434ffc04
Former-commit-id: 9548d370497e13d436abbc670cf40d360badab9f [formerly f29ba9c4dcf9962c3a5045629526296cd2b43ad8] [formerly 3f89c094c1b3330c8d6f1b2379d6309567d12210 [formerly 92fda0070c
]]
Former-commit-id: 4ad64211019e0236f0eaa6e041a8793e899954fe [formerly 6bf71ffba205b563ff6cd0c7487d9a328c757686]
Former-commit-id: 4c7afe072fc3e2a225ca5a7dbf3f3beb66b44058
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package bolt
|
|
|
|
import (
|
|
"github.com/asdine/storm"
|
|
"github.com/asdine/storm/q"
|
|
"github.com/filebrowser/filebrowser/v2/errors"
|
|
"github.com/filebrowser/filebrowser/v2/share"
|
|
)
|
|
|
|
type shareBackend struct {
|
|
db *storm.DB
|
|
}
|
|
|
|
func (s shareBackend) GetByHash(hash string) (*share.Link, error) {
|
|
var v share.Link
|
|
err := s.db.One("Hash", hash, &v)
|
|
if err == storm.ErrNotFound {
|
|
return nil, errors.ErrNotExist
|
|
}
|
|
|
|
return &v, err
|
|
}
|
|
|
|
func (s shareBackend) GetPermanent(path string, id uint) (*share.Link, error) {
|
|
var v share.Link
|
|
err := s.db.Select(q.Eq("Path", path), q.Eq("Expire", 0), q.Eq("UserID", id)).First(&v)
|
|
if err == storm.ErrNotFound {
|
|
return nil, errors.ErrNotExist
|
|
}
|
|
|
|
return &v, err
|
|
}
|
|
|
|
func (s shareBackend) Gets(path string, id uint) ([]*share.Link, error) {
|
|
var v []*share.Link
|
|
err := s.db.Select(q.Eq("Path", path), q.Eq("UserID", id)).Find(&v)
|
|
if err == storm.ErrNotFound {
|
|
return v, errors.ErrNotExist
|
|
}
|
|
|
|
return v, err
|
|
}
|
|
|
|
func (s shareBackend) Save(l *share.Link) error {
|
|
return s.db.Save(l)
|
|
}
|
|
|
|
func (s shareBackend) Delete(hash string) error {
|
|
return s.db.DeleteStruct(&share.Link{Hash: hash})
|
|
}
|