More updates :)
Former-commit-id: cc9953eaa75e9c68abc19b40cf1c4391f1c5fe24 [formerly b553106eb6a4f00474c7c79f74c02ae475e9601c] [formerly 39ca855c5e0788008f5c671164fb6e404a31aaa0 [formerly 76de8e5940]]
Former-commit-id: 0c1a5f9cc633e40506f54d9da1420ae7c183bc88 [formerly 061569610df0c6e41830bf27516ef567c3a83c55]
Former-commit-id: b400af585254eba659078ea1f5f48609930c4ea6
			
			
				pull/726/head
			
			
		
							parent
							
								
									44ab20964c
								
							
						
					
					
						commit
						600723c224
					
				|  | @ -2,6 +2,7 @@ package bolt | |||
| 
 | ||||
| import ( | ||||
| 	"github.com/asdine/storm" | ||||
| 	"github.com/asdine/storm/q" | ||||
| 	fm "github.com/hacdias/filemanager" | ||||
| ) | ||||
| 
 | ||||
|  | @ -19,6 +20,16 @@ func (s ShareStore) Get(hash string) (*fm.ShareLink, error) { | |||
| 	return v, err | ||||
| } | ||||
| 
 | ||||
| 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 | ||||
| } | ||||
| 
 | ||||
| func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) { | ||||
| 	var v []*fm.ShareLink | ||||
| 	err := s.DB.Find("Path", hash, &v) | ||||
|  |  | |||
|  | @ -461,6 +461,7 @@ type ConfigStore interface { | |||
| // ShareStore is the interface to manage share links.
 | ||||
| type ShareStore interface { | ||||
| 	Get(hash string) (*ShareLink, error) | ||||
| 	GetPermanent(path string) (*ShareLink, error) | ||||
| 	GetByPath(path string) ([]*ShareLink, error) | ||||
| 	Gets() ([]*ShareLink, error) | ||||
| 	Save(s *ShareLink) error | ||||
|  |  | |||
|  | @ -13,8 +13,8 @@ import ( | |||
| 	fm "github.com/hacdias/filemanager" | ||||
| ) | ||||
| 
 | ||||
| // ServeHTTP returns a function compatible with http.HandleFunc.
 | ||||
| func ServeHTTP(m *fm.FileManager) http.Handler { | ||||
| // Handler returns a function compatible with http.HandleFunc.
 | ||||
| func Handler(m *fm.FileManager) http.Handler { | ||||
| 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||||
| 		code, err := serve(&fm.Context{ | ||||
| 			FileManager: m, | ||||
|  | @ -235,6 +235,7 @@ func renderFile(c *fm.Context, w http.ResponseWriter, file string, contentType s | |||
| 	return 0, nil | ||||
| } | ||||
| 
 | ||||
| // 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 { | ||||
|  |  | |||
|  | @ -9,7 +9,6 @@ import ( | |||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/asdine/storm" | ||||
| 	"github.com/asdine/storm/q" | ||||
| 	fm "github.com/hacdias/filemanager" | ||||
| ) | ||||
| 
 | ||||
|  | @ -52,12 +51,13 @@ func shareGetHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int | |||
| func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, error) { | ||||
| 	path := filepath.Join(string(c.User.FileSystem), r.URL.Path) | ||||
| 
 | ||||
| 	var s fm.ShareLink | ||||
| 	var s *fm.ShareLink | ||||
| 	expire := r.URL.Query().Get("expires") | ||||
| 	unit := r.URL.Query().Get("unit") | ||||
| 
 | ||||
| 	if expire == "" { | ||||
| 		err := c.db.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&s) | ||||
| 		var err error | ||||
| 		s, err = c.Store.Share.GetPermanent(path) | ||||
| 		if err == nil { | ||||
| 			w.Write([]byte(c.RootURL() + "/share/" + s.Hash)) | ||||
| 			return 0, nil | ||||
|  | @ -71,7 +71,7 @@ func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in | |||
| 
 | ||||
| 	str := hex.EncodeToString(bytes) | ||||
| 
 | ||||
| 	s = fm.ShareLink{ | ||||
| 	s = &fm.ShareLink{ | ||||
| 		Path:    path, | ||||
| 		Hash:    str, | ||||
| 		Expires: expire != "", | ||||
|  | @ -98,7 +98,7 @@ func sharePostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in | |||
| 		s.ExpireDate = time.Now().Add(add) | ||||
| 	} | ||||
| 
 | ||||
| 	if err := c.Store.Share.Save(&s); err != nil { | ||||
| 	if err := c.Store.Share.Save(s); err != nil { | ||||
| 		return http.StatusInternalServerError, err | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Henrique Dias
						Henrique Dias