Finish the Get method for webdav.
This commit is contained in:
parent
8461218d63
commit
18dc7f7e2c
@ -11,9 +11,6 @@ const (
|
|||||||
//用户身份的cookie字段名
|
//用户身份的cookie字段名
|
||||||
COOKIE_AUTH_KEY = "_ak"
|
COOKIE_AUTH_KEY = "_ak"
|
||||||
|
|
||||||
//用户身份的Authorization字段名
|
|
||||||
AUTHORIZATION_KEY = "Authorization"
|
|
||||||
|
|
||||||
|
|
||||||
//数据库表前缀 tank200表示当前应用版本是tank:2.0.x版,数据库结构发生变化必然是中型升级
|
//数据库表前缀 tank200表示当前应用版本是tank:2.0.x版,数据库结构发生变化必然是中型升级
|
||||||
TABLE_PREFIX = "tank20_"
|
TABLE_PREFIX = "tank20_"
|
||||||
|
@ -121,21 +121,9 @@ func (this *DavController) HandleRoutes(writer http.ResponseWriter, request *htt
|
|||||||
//完成系统安装
|
//完成系统安装
|
||||||
func (this *DavController) Index(writer http.ResponseWriter, request *http.Request, subPath string) {
|
func (this *DavController) Index(writer http.ResponseWriter, request *http.Request, subPath string) {
|
||||||
|
|
||||||
this.logger.Info("--------- URI: %s SUB_PATH: %s ---------", request.RequestURI, subPath)
|
|
||||||
|
|
||||||
//获取请求者
|
|
||||||
user := this.CheckCurrentUser(writer, request)
|
|
||||||
|
|
||||||
method := request.Method
|
|
||||||
if method == "PROPFIND" {
|
|
||||||
|
|
||||||
this.davService.HandlePropfind(writer, request, user, subPath)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/*打印所有HEADER以及请求参数*/
|
/*打印所有HEADER以及请求参数*/
|
||||||
|
|
||||||
fmt.Printf("\n------ 请求: %s ------\n", request.URL)
|
fmt.Printf("\n------ 请求: %s -- %s ------\n", request.URL, subPath)
|
||||||
|
|
||||||
fmt.Printf("\n------Method:------\n")
|
fmt.Printf("\n------Method:------\n")
|
||||||
fmt.Println(request.Method)
|
fmt.Println(request.Method)
|
||||||
@ -159,7 +147,21 @@ func (this *DavController) Index(writer http.ResponseWriter, request *http.Reque
|
|||||||
|
|
||||||
fmt.Println("------------------")
|
fmt.Println("------------------")
|
||||||
|
|
||||||
this.PanicBadRequest("该方法还不支持。")
|
//获取请求者
|
||||||
|
user := this.CheckCurrentUser(writer, request)
|
||||||
|
|
||||||
|
method := request.Method
|
||||||
|
if method == "PROPFIND" {
|
||||||
|
//列出文件夹或者目录详情
|
||||||
|
this.davService.HandlePropfind(writer, request, user, subPath)
|
||||||
|
|
||||||
|
} else if method == "GET" {
|
||||||
|
//请求文件详情(下载)
|
||||||
|
this.davService.HandleGet(writer, request, user, subPath)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
this.PanicBadRequest("该方法还不支持。%s", method)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
type DavService struct {
|
type DavService struct {
|
||||||
Bean
|
Bean
|
||||||
matterDao *MatterDao
|
matterDao *MatterDao
|
||||||
|
matterService *MatterService
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
@ -29,6 +30,12 @@ func (this *DavService) Init() {
|
|||||||
if b, ok := b.(*MatterDao); ok {
|
if b, ok := b.(*MatterDao); ok {
|
||||||
this.matterDao = b
|
this.matterDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b = CONTEXT.GetBean(this.matterService)
|
||||||
|
if b, ok := b.(*MatterService); ok {
|
||||||
|
this.matterService = b
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Header头中的Depth值,暂不支持 infinity
|
//获取Header头中的Depth值,暂不支持 infinity
|
||||||
@ -139,10 +146,10 @@ func (this *DavService) Propstats(matter *Matter, propfind dav.Propfind) []dav.P
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理 方法
|
//列出文件夹或者目录详情
|
||||||
func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http.Request, user *User, subPath string) {
|
func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http.Request, user *User, subPath string) {
|
||||||
|
|
||||||
fmt.Printf("列出文件/文件夹 %s\n", subPath)
|
fmt.Printf("PROPFIND %s\n", subPath)
|
||||||
|
|
||||||
//获取请求的层数。暂不支持 infinity
|
//获取请求的层数。暂不支持 infinity
|
||||||
depth := this.ParseDepth(request)
|
depth := this.ParseDepth(request)
|
||||||
@ -164,12 +171,9 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
|||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
matters = []*Matter{matter}
|
matters = []*Matter{matter}
|
||||||
} else {
|
} else {
|
||||||
|
// len(matters) == 0 表示该文件夹下面是空文件夹
|
||||||
matters = this.matterDao.List(matter.Uuid, user.Uuid, nil)
|
matters = this.matterDao.List(matter.Uuid, user.Uuid, nil)
|
||||||
|
|
||||||
if len(matters) == 0 {
|
|
||||||
this.PanicNotFound("%s不存在", subPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
//将当前的matter添加到头部
|
//将当前的matter添加到头部
|
||||||
matters = append([]*Matter{matter}, matters...)
|
matters = append([]*Matter{matter}, matters...)
|
||||||
}
|
}
|
||||||
@ -179,7 +183,7 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
|||||||
|
|
||||||
for _, matter := range matters {
|
for _, matter := range matters {
|
||||||
|
|
||||||
fmt.Printf("开始分析 %s\n", matter.Path)
|
fmt.Printf("处理Matter %s\n", matter.Path)
|
||||||
|
|
||||||
propstats := this.Propstats(matter, propfind)
|
propstats := this.Propstats(matter, propfind)
|
||||||
path := fmt.Sprintf("%s%s", WEBDAV_PREFFIX, matter.Path)
|
path := fmt.Sprintf("%s%s", WEBDAV_PREFFIX, matter.Path)
|
||||||
@ -196,3 +200,28 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
|||||||
fmt.Printf("%v %v \n", subPath, propfind.Prop)
|
fmt.Printf("%v %v \n", subPath, propfind.Prop)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//请求文件详情(下载)
|
||||||
|
func (this *DavService) HandleGet(writer http.ResponseWriter, request *http.Request, user *User, subPath string) {
|
||||||
|
|
||||||
|
fmt.Printf("GET %s\n", subPath)
|
||||||
|
|
||||||
|
//寻找符合条件的matter.
|
||||||
|
var matter *Matter
|
||||||
|
//如果是空或者/就是请求根目录
|
||||||
|
if subPath == "" || subPath == "/" {
|
||||||
|
matter = NewRootMatter(user)
|
||||||
|
} else {
|
||||||
|
matter = this.matterDao.checkByUserUuidAndPath(user.Uuid, subPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果是文件夹,相当于是 Propfind
|
||||||
|
if matter.Dir {
|
||||||
|
this.HandlePropfind(writer, request, user, subPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//下载一个文件。
|
||||||
|
this.matterService.DownloadFile(writer, request, matter.AbsolutePath(), matter.Name, false)
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -505,7 +505,7 @@ func (this *MatterService) DownloadFile(
|
|||||||
this.PanicError(e)
|
this.PanicError(e)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//如果是图片或者文本或者视频就直接打开。其余的一律以下载形式返回。
|
//根据参数添加content-disposition。该Header会让浏览器自动下载,而不是预览。
|
||||||
if withContentDisposition {
|
if withContentDisposition {
|
||||||
fileName := url.QueryEscape(filename)
|
fileName := url.QueryEscape(filename)
|
||||||
writer.Header().Set("content-disposition", "attachment; filename=\""+fileName+"\"")
|
writer.Header().Set("content-disposition", "attachment; filename=\""+fileName+"\"")
|
||||||
|
Loading…
Reference in New Issue
Block a user