Keep doing the webdav
This commit is contained in:
parent
4611735283
commit
0d5300abda
@ -214,7 +214,7 @@ func props(ctx context.Context, fs FileSystem, ls LockSystem, name string, pname
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Propnames returns the property names defined for resource name.
|
// Propnames returns the property names defined for resource name.
|
||||||
func propnames(ctx context.Context, fs FileSystem, ls LockSystem, name string) ([]xml.Name, error) {
|
func Propnames(ctx context.Context, fs FileSystem, ls LockSystem, name string) ([]xml.Name, error) {
|
||||||
f, err := fs.OpenFile(ctx, name, os.O_RDONLY, 0)
|
f, err := fs.OpenFile(ctx, name, os.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -255,7 +255,7 @@ func propnames(ctx context.Context, fs FileSystem, ls LockSystem, name string) (
|
|||||||
//
|
//
|
||||||
// See http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND
|
// See http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND
|
||||||
func allprop(ctx context.Context, fs FileSystem, ls LockSystem, name string, include []xml.Name) ([]Propstat, error) {
|
func allprop(ctx context.Context, fs FileSystem, ls LockSystem, name string, include []xml.Name) ([]Propstat, error) {
|
||||||
pnames, err := propnames(ctx, fs, ls, name)
|
pnames, err := Propnames(ctx, fs, ls, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -522,7 +522,7 @@ func TestMemPS(t *testing.T) {
|
|||||||
var propstats []Propstat
|
var propstats []Propstat
|
||||||
switch op.op {
|
switch op.op {
|
||||||
case "propname":
|
case "propname":
|
||||||
pnames, err := propnames(ctx, fs, ls, op.name)
|
pnames, err := Propnames(ctx, fs, ls, op.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: got error %v, want nil", desc, err)
|
t.Errorf("%s: got error %v, want nil", desc, err)
|
||||||
continue
|
continue
|
||||||
|
@ -543,7 +543,7 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
|
|||||||
reqPath, info.Name(), info.IsDir(), info.Mode(), info.ModTime(), info.Size())
|
reqPath, info.Name(), info.IsDir(), info.Mode(), info.ModTime(), info.Size())
|
||||||
var propstats []Propstat
|
var propstats []Propstat
|
||||||
if pf.Propname != nil {
|
if pf.Propname != nil {
|
||||||
pnames, err := propnames(ctx, this.FileSystem, this.LockSystem, reqPath)
|
pnames, err := Propnames(ctx, this.FileSystem, this.LockSystem, reqPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -570,7 +570,7 @@ func (this *Handler) handlePropfind(writer http.ResponseWriter, request *http.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
walkErr := walkFS(ctx, this.FileSystem, depth, reqPath, fileInfo, walkFn)
|
walkErr := walkFS(ctx, this.FileSystem, depth, reqPath, fileInfo, walkFn)
|
||||||
closeErr := multiStatusWriter.close()
|
closeErr := multiStatusWriter.Close()
|
||||||
if walkErr != nil {
|
if walkErr != nil {
|
||||||
return http.StatusInternalServerError, walkErr
|
return http.StatusInternalServerError, walkErr
|
||||||
}
|
}
|
||||||
@ -609,7 +609,7 @@ func (this *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) (st
|
|||||||
}
|
}
|
||||||
mw := MultiStatusWriter{Writer: w}
|
mw := MultiStatusWriter{Writer: w}
|
||||||
writeErr := mw.Write(makePropstatResponse(r.URL.Path, pstats))
|
writeErr := mw.Write(makePropstatResponse(r.URL.Path, pstats))
|
||||||
closeErr := mw.close()
|
closeErr := mw.Close()
|
||||||
if writeErr != nil {
|
if writeErr != nil {
|
||||||
return http.StatusInternalServerError, writeErr
|
return http.StatusInternalServerError, writeErr
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ func (this *MultiStatusWriter) writeHeader() error {
|
|||||||
// an error if the multistatus response could not be completed. If both the
|
// an error if the multistatus response could not be completed. If both the
|
||||||
// return value and field Encoder of w are nil, then no multistatus response has
|
// return value and field Encoder of w are nil, then no multistatus response has
|
||||||
// been written.
|
// been written.
|
||||||
func (this *MultiStatusWriter) close() error {
|
func (this *MultiStatusWriter) Close() error {
|
||||||
if this.Encoder == nil {
|
if this.Encoder == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -582,7 +582,7 @@ loop:
|
|||||||
continue loop
|
continue loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := w.close(); err != tc.wantErr {
|
if err := w.Close(); err != tc.wantErr {
|
||||||
t.Errorf("%s: got close error %v, want %v",
|
t.Errorf("%s: got close error %v, want %v",
|
||||||
tc.desc, err, tc.wantErr)
|
tc.desc, err, tc.wantErr)
|
||||||
continue
|
continue
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package rest
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -50,9 +51,18 @@ func (this *DavService) makePropstatResponse(href string, pstats []dav.Propstat)
|
|||||||
return &resp
|
return &resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//从一个matter中获取其propnames,每个propname都是一个xml标签。
|
||||||
|
func (this *DavService) PropNames(matter *Matter) []xml.Name {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//处理 方法
|
//处理 方法
|
||||||
func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http.Request, subPath string) {
|
func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http.Request, subPath string) {
|
||||||
|
|
||||||
|
fmt.Printf("列出文件/文件夹 %s\n", subPath)
|
||||||
|
|
||||||
//获取请求者
|
//获取请求者
|
||||||
user := this.checkUser(writer, request)
|
user := this.checkUser(writer, request)
|
||||||
|
|
||||||
@ -63,10 +73,26 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
|||||||
propfind, _, err := dav.ReadPropfind(request.Body)
|
propfind, _, err := dav.ReadPropfind(request.Body)
|
||||||
this.PanicError(err)
|
this.PanicError(err)
|
||||||
|
|
||||||
|
//寻找符合条件的matter.
|
||||||
|
matters := this.matterDao.ListByUserUuidAndPath(user.Uuid, subPath)
|
||||||
|
if len(matters) == 0 {
|
||||||
|
this.PanicNotFound("%s不存在", subPath)
|
||||||
|
}
|
||||||
|
|
||||||
//准备一个输出结果的Writer
|
//准备一个输出结果的Writer
|
||||||
multiStatusWriter := dav.MultiStatusWriter{Writer: writer}
|
multiStatusWriter := dav.MultiStatusWriter{Writer: writer}
|
||||||
|
|
||||||
|
for _, matter := range matters {
|
||||||
|
|
||||||
|
fmt.Printf("开始分析 %s\n", matter.Name)
|
||||||
|
|
||||||
var propstats []dav.Propstat
|
var propstats []dav.Propstat
|
||||||
|
var props = make([]dav.Property, 0)
|
||||||
|
props = append(props, dav.Property{
|
||||||
|
XMLName: xml.Name{Space: "DAV:"},
|
||||||
|
})
|
||||||
propstats = append(propstats, dav.Propstat{
|
propstats = append(propstats, dav.Propstat{
|
||||||
|
Props: props,
|
||||||
ResponseDescription: "有点问题",
|
ResponseDescription: "有点问题",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -74,6 +100,11 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
|||||||
|
|
||||||
err = multiStatusWriter.Write(response)
|
err = multiStatusWriter.Write(response)
|
||||||
this.PanicError(err)
|
this.PanicError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//闭合
|
||||||
|
err = multiStatusWriter.Close()
|
||||||
|
this.PanicError(err)
|
||||||
|
|
||||||
fmt.Printf("%v %v \n", matter.Name, propfind.Prop)
|
fmt.Printf("%v %v \n", matter.Name, propfind.Prop)
|
||||||
|
|
||||||
|
@ -132,6 +132,31 @@ func (this *MatterDao) ListByUserUuidAndPuuidAndDirAndName(userUuid string, puui
|
|||||||
return matters
|
return matters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取某个用户的某个文件夹下的某个名字的文件(或文件夹)列表
|
||||||
|
func (this *MatterDao) ListByUserUuidAndPath(userUuid string, path string) []*Matter {
|
||||||
|
|
||||||
|
var wp = &WherePair{}
|
||||||
|
|
||||||
|
if userUuid == "" {
|
||||||
|
this.PanicBadRequest("userUuid必填!")
|
||||||
|
}
|
||||||
|
|
||||||
|
if path == "" {
|
||||||
|
this.PanicBadRequest("path必填!")
|
||||||
|
}
|
||||||
|
|
||||||
|
wp = wp.And(&WherePair{Query: "user_uuid = ?", Args: []interface{}{userUuid}})
|
||||||
|
|
||||||
|
wp = wp.And(&WherePair{Query: "path = ?", Args: []interface{}{path}})
|
||||||
|
|
||||||
|
var matters []*Matter
|
||||||
|
db := CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).Find(&matters)
|
||||||
|
|
||||||
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
|
return matters
|
||||||
|
}
|
||||||
|
|
||||||
//获取某个文件夹下所有的文件和子文件
|
//获取某个文件夹下所有的文件和子文件
|
||||||
func (this *MatterDao) List(puuid string, userUuid string, sortArray []OrderPair) []*Matter {
|
func (this *MatterDao) List(puuid string, userUuid string, sortArray []OrderPair) []*Matter {
|
||||||
var matters []*Matter
|
var matters []*Matter
|
||||||
@ -291,7 +316,6 @@ func (this *MatterDao) checkByUserUuidAndPath(userUuid string, path string) *Mat
|
|||||||
var matter = &Matter{}
|
var matter = &Matter{}
|
||||||
db := CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter)
|
db := CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter)
|
||||||
|
|
||||||
|
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
if db.Error.Error() == DB_ERROR_NOT_FOUND {
|
if db.Error.Error() == DB_ERROR_NOT_FOUND {
|
||||||
this.PanicNotFound("%s 不存在", path)
|
this.PanicNotFound("%s 不存在", path)
|
||||||
|
Loading…
Reference in New Issue
Block a user