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.
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ func TestMemPS(t *testing.T) {
|
||||
var propstats []Propstat
|
||||
switch op.op {
|
||||
case "propname":
|
||||
pnames, err := propnames(ctx, fs, ls, op.name)
|
||||
pnames, err := Propnames(ctx, fs, ls, op.name)
|
||||
if err != nil {
|
||||
t.Errorf("%s: got error %v, want nil", desc, err)
|
||||
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())
|
||||
var propstats []Propstat
|
||||
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 {
|
||||
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)
|
||||
closeErr := multiStatusWriter.close()
|
||||
closeErr := multiStatusWriter.Close()
|
||||
if walkErr != nil {
|
||||
return http.StatusInternalServerError, walkErr
|
||||
}
|
||||
@ -609,7 +609,7 @@ func (this *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) (st
|
||||
}
|
||||
mw := MultiStatusWriter{Writer: w}
|
||||
writeErr := mw.Write(makePropstatResponse(r.URL.Path, pstats))
|
||||
closeErr := mw.close()
|
||||
closeErr := mw.Close()
|
||||
if writeErr != nil {
|
||||
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
|
||||
// return value and field Encoder of w are nil, then no multistatus response has
|
||||
// been written.
|
||||
func (this *MultiStatusWriter) close() error {
|
||||
func (this *MultiStatusWriter) Close() error {
|
||||
if this.Encoder == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ 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",
|
||||
tc.desc, err, tc.wantErr)
|
||||
continue
|
||||
|
@ -1,6 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -50,9 +51,18 @@ func (this *DavService) makePropstatResponse(href string, pstats []dav.Propstat)
|
||||
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) {
|
||||
|
||||
fmt.Printf("列出文件/文件夹 %s\n", subPath)
|
||||
|
||||
//获取请求者
|
||||
user := this.checkUser(writer, request)
|
||||
|
||||
@ -63,10 +73,26 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
||||
propfind, _, err := dav.ReadPropfind(request.Body)
|
||||
this.PanicError(err)
|
||||
|
||||
//寻找符合条件的matter.
|
||||
matters := this.matterDao.ListByUserUuidAndPath(user.Uuid, subPath)
|
||||
if len(matters) == 0 {
|
||||
this.PanicNotFound("%s不存在", subPath)
|
||||
}
|
||||
|
||||
//准备一个输出结果的Writer
|
||||
multiStatusWriter := dav.MultiStatusWriter{Writer: writer}
|
||||
|
||||
for _, matter := range matters {
|
||||
|
||||
fmt.Printf("开始分析 %s\n", matter.Name)
|
||||
|
||||
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{
|
||||
Props: props,
|
||||
ResponseDescription: "有点问题",
|
||||
})
|
||||
|
||||
@ -74,6 +100,11 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
||||
|
||||
err = multiStatusWriter.Write(response)
|
||||
this.PanicError(err)
|
||||
}
|
||||
|
||||
//闭合
|
||||
err = multiStatusWriter.Close()
|
||||
this.PanicError(err)
|
||||
|
||||
fmt.Printf("%v %v \n", matter.Name, propfind.Prop)
|
||||
|
||||
|
@ -132,6 +132,31 @@ func (this *MatterDao) ListByUserUuidAndPuuidAndDirAndName(userUuid string, puui
|
||||
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 {
|
||||
var matters []*Matter
|
||||
@ -291,7 +316,6 @@ func (this *MatterDao) checkByUserUuidAndPath(userUuid string, path string) *Mat
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user