Finish the UI of share.
This commit is contained in:
parent
d75c4a222e
commit
cfd32089ff
@ -50,6 +50,11 @@ func (this *MatterController) Init() {
|
|||||||
this.shareDao = b
|
this.shareDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b = core.CONTEXT.GetBean(this.bridgeDao)
|
||||||
|
if b, ok := b.(*BridgeDao); ok {
|
||||||
|
this.bridgeDao = b
|
||||||
|
}
|
||||||
|
|
||||||
b = core.CONTEXT.GetBean(this.imageCacheService)
|
b = core.CONTEXT.GetBean(this.imageCacheService)
|
||||||
if b, ok := b.(*ImageCacheService); ok {
|
if b, ok := b.(*ImageCacheService); ok {
|
||||||
this.imageCacheService = b
|
this.imageCacheService = b
|
||||||
@ -132,7 +137,7 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
|||||||
panic(result.BadRequest("puuid必填!"))
|
panic(result.BadRequest("puuid必填!"))
|
||||||
}
|
}
|
||||||
dirMatter := this.matterDao.CheckByUuid(puuid)
|
dirMatter := this.matterDao.CheckByUuid(puuid)
|
||||||
if dirMatter.Dir {
|
if !dirMatter.Dir {
|
||||||
panic(result.BadRequest("puuid 对应的不是文件夹"))
|
panic(result.BadRequest("puuid 对应的不是文件夹"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,11 @@ import (
|
|||||||
|
|
||||||
type ShareController struct {
|
type ShareController struct {
|
||||||
BaseController
|
BaseController
|
||||||
shareDao *ShareDao
|
shareDao *ShareDao
|
||||||
bridgeDao *BridgeDao
|
bridgeDao *BridgeDao
|
||||||
matterDao *MatterDao
|
matterDao *MatterDao
|
||||||
shareService *ShareService
|
matterService *MatterService
|
||||||
|
shareService *ShareService
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
@ -39,6 +40,11 @@ func (this *ShareController) Init() {
|
|||||||
this.matterDao = b
|
this.matterDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b = core.CONTEXT.GetBean(this.matterService)
|
||||||
|
if b, ok := b.(*MatterService); ok {
|
||||||
|
this.matterService = b
|
||||||
|
}
|
||||||
|
|
||||||
b = core.CONTEXT.GetBean(this.shareService)
|
b = core.CONTEXT.GetBean(this.shareService)
|
||||||
if b, ok := b.(*ShareService); ok {
|
if b, ok := b.(*ShareService); ok {
|
||||||
this.shareService = b
|
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
|
shareType = SHARE_TYPE_MIX
|
||||||
name = name + "等"
|
name = matters[0].Name + "," + matters[1].Name + " 等"
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建share记录
|
//创建share记录
|
||||||
@ -142,6 +148,7 @@ func (this *ShareController) Create(writer http.ResponseWriter, request *http.Re
|
|||||||
Name: name,
|
Name: name,
|
||||||
ShareType: shareType,
|
ShareType: shareType,
|
||||||
UserUuid: user.Uuid,
|
UserUuid: user.Uuid,
|
||||||
|
Username: user.Username,
|
||||||
DownloadTimes: 0,
|
DownloadTimes: 0,
|
||||||
Code: util.RandomString4(),
|
Code: util.RandomString4(),
|
||||||
ExpireInfinity: expireInfinity,
|
ExpireInfinity: expireInfinity,
|
||||||
@ -302,23 +309,70 @@ func (this *ShareController) Browse(writer http.ResponseWriter, request *http.Re
|
|||||||
share := this.CheckShare(writer, request)
|
share := this.CheckShare(writer, request)
|
||||||
bridges := this.bridgeDao.ListByShareUuid(share.Uuid)
|
bridges := this.bridgeDao.ListByShareUuid(share.Uuid)
|
||||||
|
|
||||||
//获取对应的 matter.
|
//当前查看的puuid。 puuid=root表示查看分享的根目录,其余表示查看某个文件夹下的文件。
|
||||||
var matters []*Matter
|
puuid := request.FormValue("puuid")
|
||||||
if len(bridges) != 0 {
|
rootUuid := request.FormValue("rootUuid")
|
||||||
uuids := make([]string, 0)
|
|
||||||
for _, bridge := range bridges {
|
if puuid == "" {
|
||||||
uuids = append(uuids, bridge.MatterUuid)
|
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{
|
} else {
|
||||||
{
|
|
||||||
Key: "dir",
|
//如果当前查看的目录就是根目录,那么无需再验证
|
||||||
Value: DIRECTION_DESC,
|
if puuid == rootUuid {
|
||||||
},
|
dirMatter := this.matterDao.CheckByUuid(puuid)
|
||||||
}
|
share.DirMatter = dirMatter
|
||||||
matters = this.matterDao.ListByUuids(uuids, sortArray)
|
} 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)
|
return this.Success(share)
|
||||||
|
@ -25,11 +25,13 @@ type Share struct {
|
|||||||
Base
|
Base
|
||||||
Name string `json:"name" gorm:"type:varchar(255)"`
|
Name string `json:"name" gorm:"type:varchar(255)"`
|
||||||
ShareType string `json:"shareType" gorm:"type:varchar(45)"`
|
ShareType string `json:"shareType" gorm:"type:varchar(45)"`
|
||||||
|
Username string `json:"username" gorm:"type:varchar(45)"`
|
||||||
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
|
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
|
||||||
DownloadTimes int64 `json:"downloadTimes" gorm:"type:bigint(20) not null;default:0"`
|
DownloadTimes int64 `json:"downloadTimes" gorm:"type:bigint(20) not null;default:0"`
|
||||||
Code string `json:"code" gorm:"type:varchar(45) not null"`
|
Code string `json:"code" gorm:"type:varchar(45) not null"`
|
||||||
ExpireInfinity bool `json:"expireInfinity" gorm:"type:tinyint(1) not null;default:0"`
|
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'"`
|
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:"-"`
|
Matters []*Matter `json:"matters" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,24 @@ func (this *TankRouter) GlobalPanicHandler(writer http.ResponseWriter, request *
|
|||||||
file = "???"
|
file = "???"
|
||||||
line = 0
|
line = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//全局未知异常
|
||||||
|
if strings.HasSuffix(file, "runtime/panic.go") {
|
||||||
|
_, file, line, ok = runtime.Caller(4)
|
||||||
|
if !ok {
|
||||||
|
file = "???"
|
||||||
|
line = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//全局方便的异常拦截
|
||||||
|
if strings.HasSuffix(file, "util/util_framework.go") {
|
||||||
|
_, file, line, ok = runtime.Caller(4)
|
||||||
|
if !ok {
|
||||||
|
file = "???"
|
||||||
|
line = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
core.LOGGER.Error("panic on %s:%d %v", util.GetFilenameOfPath(file), line, err)
|
core.LOGGER.Error("panic on %s:%d %v", util.GetFilenameOfPath(file), line, err)
|
||||||
|
|
||||||
var webResult *result.WebResult = nil
|
var webResult *result.WebResult = nil
|
||||||
|
@ -54,9 +54,11 @@ func RandomString4() string {
|
|||||||
//0和o,l和1难以区分,剔除掉
|
//0和o,l和1难以区分,剔除掉
|
||||||
var letterRunes = []rune("abcdefghijkmnpqrstuvwxyz23456789")
|
var letterRunes = []rune("abcdefghijkmnpqrstuvwxyz23456789")
|
||||||
|
|
||||||
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
|
||||||
b := make([]rune, 4)
|
b := make([]rune, 4)
|
||||||
for i := range b {
|
for i := range b {
|
||||||
b[i] = letterRunes[rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(letterRunes))]
|
b[i] = letterRunes[r.Intn(len(letterRunes))]
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(b)
|
return string(b)
|
||||||
|
@ -13,6 +13,9 @@ import (
|
|||||||
//将srcPath压缩到destPath。
|
//将srcPath压缩到destPath。
|
||||||
func Zip(srcPath string, destPath string) {
|
func Zip(srcPath string, destPath string) {
|
||||||
|
|
||||||
|
//统一处理\\成/
|
||||||
|
srcPath = strings.Replace(srcPath, "\\", "/", -1)
|
||||||
|
|
||||||
if PathExists(destPath) {
|
if PathExists(destPath) {
|
||||||
panic(result.BadRequest("%s 已经存在了", destPath))
|
panic(result.BadRequest("%s 已经存在了", destPath))
|
||||||
}
|
}
|
||||||
@ -34,13 +37,17 @@ func Zip(srcPath string, destPath string) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
prefix := ""
|
//上一个文件夹路径
|
||||||
|
baseDirPath := GetDirOfPath(srcPath) + "/"
|
||||||
// 下面来将文件写入 zipWriter ,因为有可能会有很多个目录及文件,所以递归处理
|
// 下面来将文件写入 zipWriter ,因为有可能会有很多个目录及文件,所以递归处理
|
||||||
err = filepath.Walk(srcPath, func(path string, fileInfo os.FileInfo, errBack error) (err error) {
|
err = filepath.Walk(srcPath, func(path string, fileInfo os.FileInfo, errBack error) (err error) {
|
||||||
if errBack != nil {
|
if errBack != nil {
|
||||||
return errBack
|
return errBack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//统一处理\\成/
|
||||||
|
path = strings.Replace(path, "\\", "/", -1)
|
||||||
|
|
||||||
// 通过文件信息,创建 zip 的文件信息
|
// 通过文件信息,创建 zip 的文件信息
|
||||||
fileHeader, err := zip.FileInfoHeader(fileInfo)
|
fileHeader, err := zip.FileInfoHeader(fileInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,14 +55,11 @@ func Zip(srcPath string, destPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 替换文件信息中的文件名
|
// 替换文件信息中的文件名
|
||||||
fileHeader.Name = strings.TrimPrefix(prefix+"/"+fileInfo.Name(), "/")
|
fileHeader.Name = strings.TrimPrefix(path, baseDirPath)
|
||||||
|
|
||||||
// 目录加上/
|
// 目录前要加上/
|
||||||
if fileInfo.IsDir() {
|
if fileInfo.IsDir() {
|
||||||
fileHeader.Name += "/"
|
fileHeader.Name += "/"
|
||||||
|
|
||||||
//前缀变化
|
|
||||||
prefix = prefix + "/" + fileInfo.Name()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 写入文件信息,并返回一个 Write 结构
|
// 写入文件信息,并返回一个 Write 结构
|
||||||
|
Loading…
Reference in New Issue
Block a user