Pass the litmus basic tests.
This commit is contained in:
@ -18,7 +18,7 @@ import (
|
||||
* WebDav document
|
||||
* https://tools.ietf.org/html/rfc4918
|
||||
* http://www.webdav.org/specs/rfc4918.html
|
||||
*
|
||||
* test machine: http://www.webdav.org/neon/litmus/
|
||||
*/
|
||||
|
||||
type DavController struct {
|
||||
@ -145,7 +145,7 @@ func (this *DavController) debug(writer http.ResponseWriter, request *http.Reque
|
||||
|
||||
bodyBytes, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
fmt.Println("读取body时出错" + err.Error())
|
||||
fmt.Println("occur error when reading body: " + err.Error())
|
||||
}
|
||||
fmt.Println(string(bodyBytes))
|
||||
|
||||
@ -162,7 +162,8 @@ func (this *DavController) debug(writer http.ResponseWriter, request *http.Reque
|
||||
|
||||
func (this *DavController) Index(writer http.ResponseWriter, request *http.Request, subPath string) {
|
||||
|
||||
//this.debug(writer, request, subPath)
|
||||
//when debugging. open it.
|
||||
this.debug(writer, request, subPath)
|
||||
|
||||
user := this.CheckCurrentUser(writer, request)
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/eyebluecn/tank/code/tool/dav/xml"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
@ -230,6 +231,9 @@ func (this *DavService) HandlePut(writer http.ResponseWriter, request *http.Requ
|
||||
|
||||
this.matterService.Upload(request, request.Body, user, dirMatter, filename, true)
|
||||
|
||||
//set the status code 201
|
||||
writer.WriteHeader(http.StatusCreated)
|
||||
|
||||
}
|
||||
|
||||
//delete file
|
||||
@ -247,10 +251,37 @@ func (this *DavService) HandleMkcol(writer http.ResponseWriter, request *http.Re
|
||||
|
||||
fmt.Printf("MKCOL %s\n", subPath)
|
||||
|
||||
//the body of MKCOL request MUST be empty. (RFC2518:8.3.1)
|
||||
bodyBytes, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
fmt.Println("occur error when reading body: " + err.Error())
|
||||
} else {
|
||||
if len(bodyBytes) != 0 {
|
||||
//throw conflict error
|
||||
panic(result.CustomWebResult(result.UNSUPPORTED_MEDIA_TYPE, fmt.Sprintf("%s MKCOL should NO body", subPath)))
|
||||
}
|
||||
}
|
||||
|
||||
thisDirName := util.GetFilenameOfPath(subPath)
|
||||
dirPath := util.GetDirOfPath(subPath)
|
||||
|
||||
dirMatter := this.matterDao.CheckWithRootByPath(dirPath, user)
|
||||
dirMatter := this.matterDao.FindWithRootByPath(dirPath, user)
|
||||
if dirMatter == nil {
|
||||
//throw conflict error
|
||||
panic(result.CustomWebResult(result.CONFLICT, fmt.Sprintf("%s not exist", dirPath)))
|
||||
}
|
||||
|
||||
//check whether col exists. (RFC2518:8.3.1)
|
||||
dbMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, true, thisDirName)
|
||||
if dbMatter != nil {
|
||||
panic(result.CustomWebResult(result.METHOD_NOT_ALLOWED, fmt.Sprintf("%s already exists", dirPath)))
|
||||
}
|
||||
|
||||
//check whether file exists. (RFC2518:8.3.1)
|
||||
fileMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, false, thisDirName)
|
||||
if fileMatter != nil {
|
||||
panic(result.CustomWebResult(result.METHOD_NOT_ALLOWED, fmt.Sprintf("%s file already exists", dirPath)))
|
||||
}
|
||||
|
||||
this.matterService.AtomicCreateDirectory(request, dirMatter, thisDirName, user)
|
||||
|
||||
|
@ -92,6 +92,24 @@ func (this *MatterDao) CheckWithRootByPath(path string, user *User) *Matter {
|
||||
return matter
|
||||
}
|
||||
|
||||
// find by path. if path=/, then return the Root Matter
|
||||
func (this *MatterDao) FindWithRootByPath(path string, user *User) *Matter {
|
||||
|
||||
var matter *Matter
|
||||
|
||||
if user == nil {
|
||||
panic(result.BadRequest("user cannot be null."))
|
||||
}
|
||||
|
||||
if path == "" || path == "/" {
|
||||
matter = NewRootMatter(user)
|
||||
} else {
|
||||
matter = this.findByUserUuidAndPath(user.Uuid, path)
|
||||
}
|
||||
|
||||
return matter
|
||||
}
|
||||
|
||||
func (this *MatterDao) FindByUserUuidAndPuuidAndNameAndDirTrue(userUuid string, puuid string, name string) *Matter {
|
||||
|
||||
var wp = &builder.WherePair{}
|
||||
@ -417,6 +435,7 @@ func (this *MatterDao) SizeBetweenTime(startTime time.Time, endTime time.Time) i
|
||||
return size
|
||||
}
|
||||
|
||||
//find by userUuid and path. if not found, return nil
|
||||
func (this *MatterDao) findByUserUuidAndPath(userUuid string, path string) *Matter {
|
||||
|
||||
var wp = &builder.WherePair{Query: "user_uuid = ? AND path = ?", Args: []interface{}{userUuid, path}}
|
||||
@ -435,6 +454,7 @@ func (this *MatterDao) findByUserUuidAndPath(userUuid string, path string) *Matt
|
||||
return matter
|
||||
}
|
||||
|
||||
//find by userUuid and path. if not found, panic
|
||||
func (this *MatterDao) checkByUserUuidAndPath(userUuid string, path string) *Matter {
|
||||
|
||||
if path == "" {
|
||||
|
Reference in New Issue
Block a user