Finish the download archive feature.

This commit is contained in:
zicla
2019-05-01 19:53:20 +08:00
parent adf4b9ea5a
commit 5dd0fec953
26 changed files with 492 additions and 255 deletions

View File

@ -2,10 +2,7 @@ package rest
import (
"github.com/eyebluecn/tank/code/core"
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"net/http"
"strconv"
)
type FootprintController struct {
@ -36,93 +33,5 @@ func (this *FootprintController) RegisterRoutes() map[string]func(writer http.Re
routeMap := make(map[string]func(writer http.ResponseWriter, request *http.Request))
//每个Controller需要主动注册自己的路由。
routeMap["/api/footprint/delete"] = this.Wrap(this.Delete, USER_ROLE_USER)
routeMap["/api/footprint/detail"] = this.Wrap(this.Detail, USER_ROLE_USER)
routeMap["/api/footprint/page"] = this.Wrap(this.Page, USER_ROLE_USER)
return routeMap
}
//查看详情。
func (this *FootprintController) Detail(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid")
if uuid == "" {
panic(result.BadRequest("图片缓存的uuid必填"))
}
footprint := this.footprintService.Detail(uuid)
//验证当前之人是否有权限查看这么详细。
user := this.checkUser(writer, request)
if user.Role != USER_ROLE_ADMINISTRATOR {
if footprint.UserUuid != user.Uuid {
panic("没有权限查看该图片缓存")
}
}
return this.Success(footprint)
}
//按照分页的方式查询
func (this *FootprintController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//如果是根目录那么就传入root.
pageStr := request.FormValue("page")
pageSizeStr := request.FormValue("pageSize")
userUuid := request.FormValue("userUuid")
orderCreateTime := request.FormValue("orderCreateTime")
orderSize := request.FormValue("orderSize")
user := this.checkUser(writer, request)
if user.Role != USER_ROLE_ADMINISTRATOR {
userUuid = user.Uuid
}
var page int
if pageStr != "" {
page, _ = strconv.Atoi(pageStr)
}
pageSize := 200
if pageSizeStr != "" {
tmp, err := strconv.Atoi(pageSizeStr)
if err == nil {
pageSize = tmp
}
}
sortArray := []builder.OrderPair{
{
Key: "create_time",
Value: orderCreateTime,
},
{
Key: "size",
Value: orderSize,
},
}
pager := this.footprintDao.Page(page, pageSize, userUuid, sortArray)
return this.Success(pager)
}
//删除一条记录
func (this *FootprintController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid")
if uuid == "" {
panic(result.BadRequest("uuid必填"))
}
footprint := this.footprintDao.FindByUuid(uuid)
if footprint != nil {
this.footprintDao.Delete(footprint)
}
return this.Success("删除成功!")
}