pull/219/head
Henrique Dias 2017-08-21 07:33:16 +01:00
parent d53b5ef445
commit 1aa68b0dd0
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
4 changed files with 14 additions and 13 deletions

View File

@ -13,24 +13,24 @@ type ShareStore struct {
// Get gets a Share Link from an hash.
func (s ShareStore) Get(hash string) (*fm.ShareLink, error) {
var v *fm.ShareLink
var v fm.ShareLink
err := s.DB.One("Hash", hash, &v)
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.
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)
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.
@ -48,6 +48,10 @@ func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) {
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
}

View File

@ -17,7 +17,6 @@ import (
"github.com/hacdias/fileutils"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
"github.com/spf13/viper"
)
var databases = map[string]*storm.DB{}
@ -205,7 +204,7 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro
}
m := &filemanager.FileManager{
NoAuth: viper.GetBool("NoAuth"),
NoAuth: noAuth,
BaseURL: "",
PrefixURL: "",
DefaultUser: u,

View File

@ -9,7 +9,6 @@ import (
"strings"
"time"
"github.com/asdine/storm"
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.
func sharePage(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) {
s, err := c.Store.Share.Get(r.URL.Path)
if err == storm.ErrNotFound {
if err == fm.ErrNotExist {
return renderFile(
c, w,
c.Assets.MustString("static/share/404.html"),

View File

@ -8,7 +8,6 @@ import (
"strings"
"time"
"github.com/asdine/storm"
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) {
path := filepath.Join(c.User.Scope, r.URL.Path)
s, err := c.Store.Share.GetByPath(path)
if err == storm.ErrNotFound {
if err == fm.ErrNotExist {
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) {
s, err := c.Store.Share.Get(strings.TrimPrefix(r.URL.Path, "/"))
if err == storm.ErrNotFound {
if err == fm.ErrNotExist {
return http.StatusNotFound, nil
}