mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
e278dbba65
* rename File Manager to File Browser
* rename fm to fb
Former-commit-id: 82cd461b7efa992114a6cb6a3bb7fbae53558f42 [formerly 18b0295100462d2c798177086ddc3f615c50ca71] [formerly 5927828ac67268438cc6de00fcaf9140a8620794 [formerly 7643b0c4e3
]]
Former-commit-id: 3661e0339db83f5e4e3afa9bcb1015401afb611d [formerly 50eb65db9848c8db82115913fb58399fc371d990]
Former-commit-id: 03e42a5b429a3f0a83c88799e086a4c51c5e031d
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package bolt
|
|
|
|
import (
|
|
"github.com/asdine/storm"
|
|
"github.com/asdine/storm/q"
|
|
fb "github.com/filebrowser/filebrowser"
|
|
)
|
|
|
|
// ShareStore is a shareable links store.
|
|
type ShareStore struct {
|
|
DB *storm.DB
|
|
}
|
|
|
|
// Get gets a Share Link from an hash.
|
|
func (s ShareStore) Get(hash string) (*fb.ShareLink, error) {
|
|
var v fb.ShareLink
|
|
err := s.DB.One("Hash", hash, &v)
|
|
if err == storm.ErrNotFound {
|
|
return nil, fb.ErrNotExist
|
|
}
|
|
|
|
return &v, err
|
|
}
|
|
|
|
// GetPermanent gets the permanent link from a path.
|
|
func (s ShareStore) GetPermanent(path string) (*fb.ShareLink, error) {
|
|
var v fb.ShareLink
|
|
err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v)
|
|
if err == storm.ErrNotFound {
|
|
return nil, fb.ErrNotExist
|
|
}
|
|
|
|
return &v, err
|
|
}
|
|
|
|
// GetByPath gets all the links for a specific path.
|
|
func (s ShareStore) GetByPath(hash string) ([]*fb.ShareLink, error) {
|
|
var v []*fb.ShareLink
|
|
err := s.DB.Find("Path", hash, &v)
|
|
if err == storm.ErrNotFound {
|
|
return v, fb.ErrNotExist
|
|
}
|
|
|
|
return v, err
|
|
}
|
|
|
|
// Gets retrieves all the shareable links.
|
|
func (s ShareStore) Gets() ([]*fb.ShareLink, error) {
|
|
var v []*fb.ShareLink
|
|
err := s.DB.All(&v)
|
|
if err == storm.ErrNotFound {
|
|
return v, fb.ErrNotExist
|
|
}
|
|
|
|
return v, err
|
|
}
|
|
|
|
// Save stores a Share Link on the database.
|
|
func (s ShareStore) Save(l *fb.ShareLink) error {
|
|
return s.DB.Save(l)
|
|
}
|
|
|
|
// Delete deletes a Share Link from the database.
|
|
func (s ShareStore) Delete(hash string) error {
|
|
return s.DB.DeleteStruct(&fb.ShareLink{Hash: hash})
|
|
}
|