Try to fix the xml things.
This commit is contained in:
@ -564,7 +564,9 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
|
||||
if info.IsDir() {
|
||||
href += "/"
|
||||
}
|
||||
return multiStatusWriter.write(makePropstatResponse(href, propstats))
|
||||
|
||||
propstatResponse := makePropstatResponse(href, propstats)
|
||||
return multiStatusWriter.write(propstatResponse)
|
||||
}
|
||||
|
||||
walkErr := walkFS(ctx, this.FileSystem, depth, reqPath, fileInfo, walkFn)
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
ixml "golang.org/x/net/webdav/internal/xml"
|
||||
ixml "tank/rest/dav/internal/xml"
|
||||
)
|
||||
|
||||
func TestReadLockInfo(t *testing.T) {
|
||||
|
@ -10,8 +10,10 @@ import (
|
||||
*
|
||||
* WebDav协议文档
|
||||
* https://tools.ietf.org/html/rfc4918
|
||||
* http://www.webdav.org/specs/rfc4918.html
|
||||
*
|
||||
*/
|
||||
|
||||
type DavController struct {
|
||||
BaseController
|
||||
uploadTokenDao *UploadTokenDao
|
||||
@ -90,17 +92,24 @@ func (this *DavController) HandleRoutes(writer http.ResponseWriter, request *htt
|
||||
return nil, false
|
||||
}
|
||||
|
||||
|
||||
//完成系统安装
|
||||
func (this *DavController) Index(writer http.ResponseWriter, request *http.Request, subPath string) {
|
||||
|
||||
this.logger.Info("请求访问来了:%s %s", request.RequestURI, subPath)
|
||||
|
||||
handler := &dav.Handler{
|
||||
FileSystem: dav.Dir("D:/Group/Golang/src/webdav/tmp"),
|
||||
LockSystem: dav.NewMemLS(),
|
||||
method := request.Method
|
||||
if method == "PROPFIND1" {
|
||||
|
||||
this.davService.HandlePropfind(writer, request, subPath)
|
||||
|
||||
} else {
|
||||
|
||||
handler := &dav.Handler{
|
||||
FileSystem: dav.Dir("D:/Group/Golang/src/webdav/tmp"),
|
||||
LockSystem: dav.NewMemLS(),
|
||||
}
|
||||
|
||||
handler.ServeHTTP(writer, request)
|
||||
}
|
||||
|
||||
handler.ServeHTTP(writer, request)
|
||||
|
||||
}
|
||||
|
33
rest/dav_model.go
Normal file
33
rest/dav_model.go
Normal file
@ -0,0 +1,33 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
/**
|
||||
*
|
||||
* WebDav协议文档
|
||||
* https://tools.ietf.org/html/rfc4918
|
||||
* http://www.webdav.org/specs/rfc4918.html
|
||||
*
|
||||
*/
|
||||
|
||||
const (
|
||||
//有多少层展示多少层
|
||||
INFINITE_DEPTH = -1
|
||||
)
|
||||
|
||||
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propfind
|
||||
//PROPFIND方法请求时POST BODY入参
|
||||
type Propfind struct {
|
||||
XMLName xml.Name `xml:"D:propfind"`
|
||||
XmlNS string `xml:"xmlns:D,attr"`
|
||||
|
||||
Allprop *struct{} `xml:"D:allprop"`
|
||||
Propname *struct{} `xml:"D:propname"`
|
||||
Prop PropfindProps `xml:"D:prop"`
|
||||
Include PropfindProps `xml:"D:include"`
|
||||
}
|
||||
|
||||
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for propfind)
|
||||
type PropfindProps []xml.Name
|
@ -1,6 +1,18 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
/**
|
||||
*
|
||||
* WebDav协议文档
|
||||
* https://tools.ietf.org/html/rfc4918
|
||||
*
|
||||
*/
|
||||
//@Service
|
||||
type DavService struct {
|
||||
Bean
|
||||
@ -17,3 +29,53 @@ func (this *DavService) Init() {
|
||||
this.matterDao = b
|
||||
}
|
||||
}
|
||||
|
||||
//从request中读取深度
|
||||
func (this *DavService) readDepth(request *http.Request) int {
|
||||
|
||||
depth := INFINITE_DEPTH
|
||||
if hdr := request.Header.Get("Depth"); hdr != "" {
|
||||
if hdr == "0" {
|
||||
depth = 0
|
||||
} else if hdr == "1" {
|
||||
depth = 1
|
||||
} else if hdr == "infinity" {
|
||||
depth = INFINITE_DEPTH
|
||||
} else {
|
||||
panic("Depth格式错误!")
|
||||
}
|
||||
}
|
||||
return depth
|
||||
}
|
||||
|
||||
//处理 方法
|
||||
func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http.Request, subPath string) {
|
||||
|
||||
//获取请求者
|
||||
user := this.checkUser(writer, request)
|
||||
|
||||
//读取希望访问的深度。
|
||||
depth := this.readDepth(request)
|
||||
|
||||
//找寻请求的目录
|
||||
matter := this.matterDao.checkByUserUuidAndPath(user.Uuid, subPath)
|
||||
|
||||
//TODO: 读取请求参数。按照用户的参数请求返回内容。
|
||||
propfind := &Propfind{}
|
||||
body, err := ioutil.ReadAll(request.Body)
|
||||
this.PanicError(err)
|
||||
|
||||
//从xml中解析内容到struct
|
||||
err = xml.Unmarshal(body, &propfind)
|
||||
this.PanicError(err)
|
||||
|
||||
//从struct还原到xml
|
||||
output, err := xml.MarshalIndent(propfind, " ", " ")
|
||||
this.PanicError(err)
|
||||
fmt.Println(string(output))
|
||||
|
||||
|
||||
|
||||
fmt.Printf("%v %v \n", depth, matter.Name)
|
||||
|
||||
}
|
||||
|
@ -283,6 +283,26 @@ func (this *MatterDao) SizeBetweenTime(startTime time.Time, endTime time.Time) i
|
||||
return size
|
||||
}
|
||||
|
||||
//根据userUuid和path来查找
|
||||
func (this *MatterDao) checkByUserUuidAndPath(userUuid string, path string) *Matter {
|
||||
|
||||
var wp = &WherePair{Query: "user_uuid = ? AND path = ?", Args: []interface{}{userUuid, path}}
|
||||
|
||||
var matter = &Matter{}
|
||||
db := CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter)
|
||||
|
||||
|
||||
if db.Error != nil {
|
||||
if db.Error.Error() == DB_ERROR_NOT_FOUND {
|
||||
this.PanicNotFound("%s 不存在", path)
|
||||
} else {
|
||||
this.PanicError(db.Error)
|
||||
}
|
||||
}
|
||||
|
||||
return matter
|
||||
}
|
||||
|
||||
//执行清理操作
|
||||
func (this *MatterDao) Cleanup() {
|
||||
this.logger.Info("[MatterDao]执行清理:清除数据库中所有Matter记录。删除磁盘中所有Matter文件。")
|
||||
|
Reference in New Issue
Block a user