You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudreve/routers/controllers/webdav.go

43 lines
922 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package controllers
import (
model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/filesystem"
"github.com/HFO4/cloudreve/pkg/util"
"github.com/HFO4/cloudreve/pkg/webdav"
"github.com/gin-gonic/gin"
)
var handler *webdav.Handler
func init() {
handler = &webdav.Handler{
Prefix: "/dav",
LockSystem: make(map[uint]webdav.LockSystem),
}
}
// ServeWebDAV 处理WebDAV相关请求
func ServeWebDAV(c *gin.Context) {
fs, err := filesystem.NewFileSystemFromContext(c)
if err != nil {
util.Log().Warning("无法为WebDAV初始化文件系统%s", err)
return
}
if webdavCtx, ok := c.Get("webdav"); ok {
application := webdavCtx.(*model.Webdav)
// 重定根目录
if application.Root != "/" {
if exist, root := fs.IsPathExist(application.Root); exist {
root.Position = ""
root.Name = "/"
fs.Root = root
}
}
}
handler.ServeHTTP(c.Writer, c.Request, fs)
}