Finish the UI of share.
This commit is contained in:
@ -50,6 +50,11 @@ func (this *MatterController) Init() {
|
||||
this.shareDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.bridgeDao)
|
||||
if b, ok := b.(*BridgeDao); ok {
|
||||
this.bridgeDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.imageCacheService)
|
||||
if b, ok := b.(*ImageCacheService); ok {
|
||||
this.imageCacheService = b
|
||||
@ -132,7 +137,7 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
||||
panic(result.BadRequest("puuid必填!"))
|
||||
}
|
||||
dirMatter := this.matterDao.CheckByUuid(puuid)
|
||||
if dirMatter.Dir {
|
||||
if !dirMatter.Dir {
|
||||
panic(result.BadRequest("puuid 对应的不是文件夹"))
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,11 @@ import (
|
||||
|
||||
type ShareController struct {
|
||||
BaseController
|
||||
shareDao *ShareDao
|
||||
bridgeDao *BridgeDao
|
||||
matterDao *MatterDao
|
||||
shareService *ShareService
|
||||
shareDao *ShareDao
|
||||
bridgeDao *BridgeDao
|
||||
matterDao *MatterDao
|
||||
matterService *MatterService
|
||||
shareService *ShareService
|
||||
}
|
||||
|
||||
//初始化方法
|
||||
@ -39,6 +40,11 @@ func (this *ShareController) Init() {
|
||||
this.matterDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.matterService)
|
||||
if b, ok := b.(*MatterService); ok {
|
||||
this.matterService = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.shareService)
|
||||
if b, ok := b.(*ShareService); ok {
|
||||
this.shareService = b
|
||||
@ -132,9 +138,9 @@ func (this *ShareController) Create(writer http.ResponseWriter, request *http.Re
|
||||
|
||||
}
|
||||
|
||||
if len(uuidArray) > 1 {
|
||||
if len(matters) > 1 {
|
||||
shareType = SHARE_TYPE_MIX
|
||||
name = name + "等"
|
||||
name = matters[0].Name + "," + matters[1].Name + " 等"
|
||||
}
|
||||
|
||||
//创建share记录
|
||||
@ -142,6 +148,7 @@ func (this *ShareController) Create(writer http.ResponseWriter, request *http.Re
|
||||
Name: name,
|
||||
ShareType: shareType,
|
||||
UserUuid: user.Uuid,
|
||||
Username: user.Username,
|
||||
DownloadTimes: 0,
|
||||
Code: util.RandomString4(),
|
||||
ExpireInfinity: expireInfinity,
|
||||
@ -302,23 +309,70 @@ func (this *ShareController) Browse(writer http.ResponseWriter, request *http.Re
|
||||
share := this.CheckShare(writer, request)
|
||||
bridges := this.bridgeDao.ListByShareUuid(share.Uuid)
|
||||
|
||||
//获取对应的 matter.
|
||||
var matters []*Matter
|
||||
if len(bridges) != 0 {
|
||||
uuids := make([]string, 0)
|
||||
for _, bridge := range bridges {
|
||||
uuids = append(uuids, bridge.MatterUuid)
|
||||
//当前查看的puuid。 puuid=root表示查看分享的根目录,其余表示查看某个文件夹下的文件。
|
||||
puuid := request.FormValue("puuid")
|
||||
rootUuid := request.FormValue("rootUuid")
|
||||
|
||||
if puuid == "" {
|
||||
puuid = MATTER_ROOT
|
||||
}
|
||||
//分享的跟目录
|
||||
if puuid == MATTER_ROOT {
|
||||
|
||||
//获取对应的 matter.
|
||||
var matters []*Matter
|
||||
if len(bridges) != 0 {
|
||||
uuids := make([]string, 0)
|
||||
for _, bridge := range bridges {
|
||||
uuids = append(uuids, bridge.MatterUuid)
|
||||
}
|
||||
|
||||
sortArray := []builder.OrderPair{
|
||||
{
|
||||
Key: "dir",
|
||||
Value: DIRECTION_DESC,
|
||||
},
|
||||
}
|
||||
matters = this.matterDao.ListByUuids(uuids, sortArray)
|
||||
|
||||
share.Matters = matters
|
||||
}
|
||||
|
||||
sortArray := []builder.OrderPair{
|
||||
{
|
||||
Key: "dir",
|
||||
Value: DIRECTION_DESC,
|
||||
},
|
||||
}
|
||||
matters = this.matterDao.ListByUuids(uuids, sortArray)
|
||||
} else {
|
||||
|
||||
//如果当前查看的目录就是根目录,那么无需再验证
|
||||
if puuid == rootUuid {
|
||||
dirMatter := this.matterDao.CheckByUuid(puuid)
|
||||
share.DirMatter = dirMatter
|
||||
} else {
|
||||
dirMatter := this.matterService.Detail(puuid)
|
||||
|
||||
//验证 shareRootMatter是否在被分享。
|
||||
shareRootMatter := this.matterDao.CheckByUuid(rootUuid)
|
||||
if !shareRootMatter.Dir {
|
||||
panic(result.BadRequest("只有文件夹可以浏览!"))
|
||||
}
|
||||
this.bridgeDao.CheckByShareUuidAndMatterUuid(share.Uuid, shareRootMatter.Uuid)
|
||||
|
||||
//到rootUuid的地方掐断。
|
||||
find := false
|
||||
parentMatter := dirMatter.Parent
|
||||
for parentMatter != nil {
|
||||
if parentMatter.Uuid == rootUuid {
|
||||
parentMatter.Parent = nil
|
||||
find = true
|
||||
break
|
||||
}
|
||||
parentMatter = parentMatter.Parent
|
||||
}
|
||||
|
||||
if !find {
|
||||
panic(result.BadRequest("rootUuid不是分享的根目录"))
|
||||
}
|
||||
|
||||
share.DirMatter = dirMatter
|
||||
}
|
||||
|
||||
share.Matters = matters
|
||||
}
|
||||
|
||||
return this.Success(share)
|
||||
|
@ -25,11 +25,13 @@ type Share struct {
|
||||
Base
|
||||
Name string `json:"name" gorm:"type:varchar(255)"`
|
||||
ShareType string `json:"shareType" gorm:"type:varchar(45)"`
|
||||
Username string `json:"username" gorm:"type:varchar(45)"`
|
||||
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
|
||||
DownloadTimes int64 `json:"downloadTimes" gorm:"type:bigint(20) not null;default:0"`
|
||||
Code string `json:"code" gorm:"type:varchar(45) not null"`
|
||||
ExpireInfinity bool `json:"expireInfinity" gorm:"type:tinyint(1) not null;default:0"`
|
||||
ExpireTime time.Time `json:"expireTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
|
||||
DirMatter *Matter `json:"dirMatter" gorm:"-"`
|
||||
Matters []*Matter `json:"matters" gorm:"-"`
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user