feat(webdav): add read-only option (#1629)

This commit is contained in:
WeidiDeng
2023-02-07 19:43:28 +08:00
committed by GitHub
parent ffbafca994
commit a93ea2cfa0
4 changed files with 43 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/cloudreve/Cloudreve/v3/pkg/webdav"
"github.com/cloudreve/Cloudreve/v3/service/setting"
"github.com/gin-gonic/gin"
"net/http"
"sync"
)
@@ -39,6 +40,15 @@ func ServeWebDAV(c *gin.Context) {
fs.Root = root
}
}
// 检查是否只读
if application.Readonly {
switch c.Request.Method {
case "DELETE", "PUT", "MKCOL", "COPY", "MOVE":
c.Status(http.StatusForbidden)
return
}
}
}
handler.ServeHTTP(c.Writer, c.Request, fs)
@@ -66,6 +76,17 @@ func DeleteWebDAVAccounts(c *gin.Context) {
}
}
// UpdateWebDAVAccountsReadonly 更改WebDAV账户只读性
func UpdateWebDAVAccountsReadonly(c *gin.Context) {
var service setting.WebDAVAccountUpdateReadonlyService
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Update(c, CurrentUser(c))
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
// CreateWebDAVAccounts 创建WebDAV账户
func CreateWebDAVAccounts(c *gin.Context) {
var service setting.WebDAVAccountCreateService