mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
Fix #213
Former-commit-id: 57732db98608e0b8fbe0e18f6d77d69b7cdc8807 [formerly 647558cec7e30388a3dc80c002bf2787f27edbf7] [formerly 03295cda86a4ce43a734c4617d7d4429ffeb7570 [formerly 1aa68b0dd0
]]
Former-commit-id: 52bc1fdecc89456f7dc32f5ce64a40727070d06c [formerly 8a1a04c67bba6988b448f9a4c612ba62aeaf7e62]
Former-commit-id: 9b4565efca09847c31f6f856eae1aa488461046d
This commit is contained in:
parent
73b1094602
commit
c18ca4702d
@ -13,24 +13,24 @@ type ShareStore struct {
|
|||||||
|
|
||||||
// Get gets a Share Link from an hash.
|
// Get gets a Share Link from an hash.
|
||||||
func (s ShareStore) Get(hash string) (*fm.ShareLink, error) {
|
func (s ShareStore) Get(hash string) (*fm.ShareLink, error) {
|
||||||
var v *fm.ShareLink
|
var v fm.ShareLink
|
||||||
err := s.DB.One("Hash", hash, &v)
|
err := s.DB.One("Hash", hash, &v)
|
||||||
if err == storm.ErrNotFound {
|
if err == storm.ErrNotFound {
|
||||||
return v, fm.ErrNotExist
|
return nil, fm.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
return v, err
|
return &v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPermanent gets the permanent link from a path.
|
// GetPermanent gets the permanent link from a path.
|
||||||
func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) {
|
func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) {
|
||||||
var v *fm.ShareLink
|
var v fm.ShareLink
|
||||||
err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v)
|
err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v)
|
||||||
if err == storm.ErrNotFound {
|
if err == storm.ErrNotFound {
|
||||||
return v, fm.ErrNotExist
|
return nil, fm.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
return v, err
|
return &v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByPath gets all the links for a specific path.
|
// GetByPath gets all the links for a specific path.
|
||||||
@ -48,6 +48,10 @@ func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) {
|
|||||||
func (s ShareStore) Gets() ([]*fm.ShareLink, error) {
|
func (s ShareStore) Gets() ([]*fm.ShareLink, error) {
|
||||||
var v []*fm.ShareLink
|
var v []*fm.ShareLink
|
||||||
err := s.DB.All(&v)
|
err := s.DB.All(&v)
|
||||||
|
if err == storm.ErrNotFound {
|
||||||
|
return v, fm.ErrNotExist
|
||||||
|
}
|
||||||
|
|
||||||
return v, err
|
return v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/hacdias/fileutils"
|
"github.com/hacdias/fileutils"
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
"github.com/mholt/caddy/caddyhttp/httpserver"
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var databases = map[string]*storm.DB{}
|
var databases = map[string]*storm.DB{}
|
||||||
@ -205,7 +204,7 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
m := &filemanager.FileManager{
|
m := &filemanager.FileManager{
|
||||||
NoAuth: viper.GetBool("NoAuth"),
|
NoAuth: noAuth,
|
||||||
BaseURL: "",
|
BaseURL: "",
|
||||||
PrefixURL: "",
|
PrefixURL: "",
|
||||||
DefaultUser: u,
|
DefaultUser: u,
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/asdine/storm"
|
|
||||||
fm "github.com/hacdias/filemanager"
|
fm "github.com/hacdias/filemanager"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -242,7 +241,7 @@ func renderFile(c *fm.Context, w http.ResponseWriter, file string, contentType s
|
|||||||
// sharePage build the share page.
|
// sharePage build the share page.
|
||||||
func sharePage(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
|
func sharePage(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
s, err := c.Store.Share.Get(r.URL.Path)
|
s, err := c.Store.Share.Get(r.URL.Path)
|
||||||
if err == storm.ErrNotFound {
|
if err == fm.ErrNotExist {
|
||||||
return renderFile(
|
return renderFile(
|
||||||
c, w,
|
c, w,
|
||||||
c.Assets.MustString("static/share/404.html"),
|
c.Assets.MustString("static/share/404.html"),
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/asdine/storm"
|
|
||||||
fm "github.com/hacdias/filemanager"
|
fm "github.com/hacdias/filemanager"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +29,7 @@ func shareHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, e
|
|||||||
func shareGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
|
func shareGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
path := filepath.Join(c.User.Scope, r.URL.Path)
|
path := filepath.Join(c.User.Scope, r.URL.Path)
|
||||||
s, err := c.Store.Share.GetByPath(path)
|
s, err := c.Store.Share.GetByPath(path)
|
||||||
if err == storm.ErrNotFound {
|
if err == fm.ErrNotExist {
|
||||||
return http.StatusNotFound, nil
|
return http.StatusNotFound, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in
|
|||||||
|
|
||||||
func shareDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
|
func shareDeleteHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
s, err := c.Store.Share.Get(strings.TrimPrefix(r.URL.Path, "/"))
|
s, err := c.Store.Share.Get(strings.TrimPrefix(r.URL.Path, "/"))
|
||||||
if err == storm.ErrNotFound {
|
if err == fm.ErrNotExist {
|
||||||
return http.StatusNotFound, nil
|
return http.StatusNotFound, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user