mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-04 18:50:42 -06:00
Repackage webdav files
This commit is contained in:
@@ -6,15 +6,6 @@ import (
|
||||
)
|
||||
|
||||
const keyFileSystem = "filesystem"
|
||||
const keyUserID = "userID"
|
||||
|
||||
func GetUserID(c *gin.Context) int32 {
|
||||
val, ok := c.Get(keyUserID)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
return val.(int32)
|
||||
}
|
||||
|
||||
func GetFileSystem(c *gin.Context) core.FileSystem {
|
||||
val, ok := c.Get(keyFileSystem)
|
||||
|
||||
@@ -38,7 +38,6 @@ func CreateBearerAuthHandler(a *app.App) func(c *gin.Context) {
|
||||
logrus.Warn(err)
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
} else {
|
||||
c.Set(keyUserID, userID)
|
||||
c.Set(keyFileSystem, fs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shroff/phylum/server/internal/api"
|
||||
"github.com/shroff/phylum/server/internal/app"
|
||||
webdav "github.com/shroff/phylum/server/internal/handler_webdav"
|
||||
"github.com/shroff/phylum/server/internal/webdav"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package auth
|
||||
package webdav
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -8,7 +8,9 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func CreateBasicAuthHandler(app *app.App) func(c *gin.Context) {
|
||||
const keyFileSystem = "filesystem"
|
||||
|
||||
func createBasicAuthHandler(app *app.App) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var userID int32
|
||||
if username, pass, ok := c.Request.BasicAuth(); ok {
|
||||
@@ -23,7 +25,6 @@ func CreateBasicAuthHandler(app *app.App) func(c *gin.Context) {
|
||||
logrus.Warn(err)
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
} else {
|
||||
c.Set(keyUserID, userID)
|
||||
c.Set(keyFileSystem, fs)
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,14 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/shroff/phylum/server/internal/api/auth"
|
||||
"github.com/shroff/phylum/server/internal/app"
|
||||
"github.com/shroff/phylum/server/internal/app/core"
|
||||
"github.com/shroff/phylum/server/internal/webdav"
|
||||
webdav "github.com/shroff/phylum/server/internal/webdav/impl"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ func SetupHandler(r *gin.RouterGroup, app *app.App) {
|
||||
app: app,
|
||||
prefix: r.BasePath(),
|
||||
}
|
||||
r.Use(auth.CreateBasicAuthHandler(app))
|
||||
r.Use(createBasicAuthHandler(app))
|
||||
r.Handle("OPTIONS", "/*path", handler.HandleRequest)
|
||||
r.Handle("GET", "/*path", handler.HandleRequest)
|
||||
r.Handle("PUT", "/*path", handler.HandleRequest)
|
||||
@@ -42,9 +42,14 @@ func SetupHandler(r *gin.RouterGroup, app *app.App) {
|
||||
}
|
||||
|
||||
func (h *handler) HandleRequest(c *gin.Context) {
|
||||
fs, ok := c.Get(keyFileSystem)
|
||||
if !ok {
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
webdavHandler := webdav.Handler{
|
||||
Prefix: h.prefix,
|
||||
FileSystem: adapter{fs: auth.GetFileSystem(c)},
|
||||
FileSystem: adapter{fs: fs.(core.FileSystem)},
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
webdavHandler.ServeHTTP(c.Writer, c.Request)
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
// In the long term, this package should use the standard library's version
|
||||
// only, and the internal fork deleted, once
|
||||
// https://github.com/golang/go/issues/13400 is resolved.
|
||||
ixml "github.com/shroff/phylum/server/internal/xml"
|
||||
ixml "github.com/shroff/phylum/server/internal/webdav/xml"
|
||||
)
|
||||
|
||||
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
ixml "github.com/shroff/phylum/server/internal/xml"
|
||||
ixml "github.com/shroff/phylum/server/internal/webdav/xml"
|
||||
)
|
||||
|
||||
func TestReadLockInfo(t *testing.T) {
|
||||
Reference in New Issue
Block a user