You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
Updates on auth and db
Former-commit-id: cdcfc50a4a7274482826520644019d54c37a7753 [formerly 376d2422063755c75d5b5c8e21bf8617ca3a9baf] [formerly ea860508c1603296e0439a583ca0573609be3511 [formerly 6312c60b2e]]
Former-commit-id: d64b8b836568b150853288a69f870662e92db1e0 [formerly b85b1a09bbf87c1b5f2af07659121ef51a74f05e]
Former-commit-id: ee164251a6143567da3f970e347ede0d6de1d350
This commit is contained in:
27
api.go
27
api.go
@@ -25,20 +25,19 @@ func cleanURL(path string) (string, string) {
|
||||
}
|
||||
|
||||
func serveAPI(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
if r.URL.Path == "/auth" {
|
||||
return getTokenHandler(c, w, r)
|
||||
if r.URL.Path == "/auth/get" {
|
||||
return authHandler(c, w, r)
|
||||
}
|
||||
|
||||
/* valid, user := validAuth(c, r)
|
||||
if r.URL.Path == "/auth/renew" {
|
||||
return renewAuthHandler(c, w, r)
|
||||
}
|
||||
|
||||
valid, _ := validateAuth(c, r)
|
||||
if !valid {
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
fmt.Println(user)
|
||||
c.us = user */
|
||||
|
||||
c.us = c.fm.User
|
||||
|
||||
var router string
|
||||
router, r.URL.Path = cleanURL(r.URL.Path)
|
||||
|
||||
@@ -175,7 +174,7 @@ func deleteHandler(c *requestContext, w http.ResponseWriter, r *http.Request) (i
|
||||
}
|
||||
|
||||
// Remove the file or folder.
|
||||
err := c.us.fileSystem.RemoveAll(context.TODO(), r.URL.Path)
|
||||
err := c.us.FileSystem.RemoveAll(context.TODO(), r.URL.Path)
|
||||
if err != nil {
|
||||
return errorToHTTP(err, true), err
|
||||
}
|
||||
@@ -185,11 +184,11 @@ func deleteHandler(c *requestContext, w http.ResponseWriter, r *http.Request) (i
|
||||
|
||||
func putHandler(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
if strings.HasSuffix(r.URL.Path, "/") {
|
||||
err := c.us.fileSystem.Mkdir(context.TODO(), r.URL.Path, 0666)
|
||||
err := c.us.FileSystem.Mkdir(context.TODO(), r.URL.Path, 0666)
|
||||
return errorToHTTP(err, false), err
|
||||
}
|
||||
|
||||
f, err := c.us.fileSystem.OpenFile(context.TODO(), r.URL.Path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
f, err := c.us.FileSystem.OpenFile(context.TODO(), r.URL.Path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
defer f.Close()
|
||||
|
||||
if err != nil {
|
||||
@@ -214,8 +213,12 @@ func putHandler(c *requestContext, w http.ResponseWriter, r *http.Request) (int,
|
||||
func postHandler(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
dst := r.Header.Get("Destination")
|
||||
src := r.URL.Path
|
||||
err := c.us.fileSystem.Rename(context.TODO(), src, dst)
|
||||
|
||||
if dst == "/" || src == "/" {
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
err := c.us.FileSystem.Rename(context.TODO(), src, dst)
|
||||
return errorToHTTP(err, true), err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user