mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
98bea91edf
Former-commit-id: ea1761b1e1bd9ff6eb80e06ff378d8263de86064 [formerly a4cefe6cf2f1da416ad34175bcea96ac5262d766] [formerly cc4c6afca638a66e223e64a6bffde563a48b1990 [formerly c6e6b08305
]]
Former-commit-id: 56c1574b23fefd33b41d848f47201a24e75d9e6b [formerly b326f699ef7dde08a4e81b4a3a7db22902270634]
Former-commit-id: 078a180adea8d3f3f02177caf78cbeea22145d4c
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package bolt
|
|
|
|
import (
|
|
"github.com/asdine/storm"
|
|
"github.com/asdine/storm/q"
|
|
fm "github.com/hacdias/filemanager"
|
|
)
|
|
|
|
// 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) (*fm.ShareLink, error) {
|
|
var v *fm.ShareLink
|
|
err := s.DB.One("Hash", hash, &v)
|
|
if err == storm.ErrNotFound {
|
|
return v, fm.ErrNotExist
|
|
}
|
|
|
|
return v, err
|
|
}
|
|
|
|
// GetPermanent gets the permanent link from a path.
|
|
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
|
|
}
|
|
|
|
// GetByPath gets all the links for a specific path.
|
|
func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) {
|
|
var v []*fm.ShareLink
|
|
err := s.DB.Find("Path", hash, &v)
|
|
if err == storm.ErrNotFound {
|
|
return v, fm.ErrNotExist
|
|
}
|
|
|
|
return v, err
|
|
}
|
|
|
|
// Gets retrieves all the shareable links.
|
|
func (s ShareStore) Gets() ([]*fm.ShareLink, error) {
|
|
var v []*fm.ShareLink
|
|
err := s.DB.All(&v)
|
|
return v, err
|
|
}
|
|
|
|
// Save stores a Share Link on the database.
|
|
func (s ShareStore) Save(l *fm.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(&fm.ShareLink{Hash: hash})
|
|
}
|