🧑‍💻 Kernel serve WebDAV service on path /webdav/ (#12412)

* 🎨 Add a WebDAV service to the kernel

* 🎨 Add more writable WebDAV methods
This commit is contained in:
Yingyi / 颖逸 2024-09-08 10:00:09 +08:00 committed by GitHub
parent f88296c4d2
commit 9cff5cc235
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 65 additions and 5 deletions

View file

@ -441,7 +441,7 @@ func ExportData() (zipPath string, err error) {
util.PushEndlessProgress(Conf.Language(65))
defer util.ClearPushProgress(100)
name := util.FilterFileName(filepath.Base(util.WorkspaceDir)) + "-" + util.CurrentTimeSecondsStr()
name := util.FilterFileName(util.WorkspaceName) + "-" + util.CurrentTimeSecondsStr()
exportFolder := filepath.Join(util.TempDir, "export", name)
zipPath, err = exportData(exportFolder)
if err != nil {

View file

@ -250,6 +250,16 @@ func CheckAuth(c *gin.Context) {
return
}
// 通过 BasicAuth (header: Authorization)
if username, password, ok := c.Request.BasicAuth(); ok {
// 使用访问授权码作为密码
if util.WorkspaceName == username && Conf.AccessAuthCode == password {
c.Set(RoleContextKey, RoleAdministrator)
c.Next()
return
}
}
// 通过 API token (header: Authorization)
if authHeader := c.GetHeader("Authorization"); "" != authHeader {
var token string
@ -289,7 +299,15 @@ func CheckAuth(c *gin.Context) {
return
}
if "/check-auth" == c.Request.URL.Path { // 跳过访问授权页
// WebDAV BasicAuth Authenticate
if strings.HasPrefix(c.Request.RequestURI, "/webdav") {
c.Header("WWW-Authenticate", "Basic realm=Authorization Required")
c.AbortWithStatus(http.StatusUnauthorized)
return
}
// 跳过访问授权页
if "/check-auth" == c.Request.URL.Path {
c.Next()
return
}