mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
c18ca4702d
Former-commit-id: 57732db98608e0b8fbe0e18f6d77d69b7cdc8807 [formerly 647558cec7e30388a3dc80c002bf2787f27edbf7] [formerly 03295cda86a4ce43a734c4617d7d4429ffeb7570 [formerly 1aa68b0dd0
]]
Former-commit-id: 52bc1fdecc89456f7dc32f5ce64a40727070d06c [formerly 8a1a04c67bba6988b448f9a4c612ba62aeaf7e62]
Former-commit-id: 9b4565efca09847c31f6f856eae1aa488461046d
67 lines
1.5 KiB
Go
67 lines
1.5 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 nil, 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 nil, 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)
|
|
if err == storm.ErrNotFound {
|
|
return v, fm.ErrNotExist
|
|
}
|
|
|
|
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})
|
|
}
|