Add the download dir max size in the preference.
This commit is contained in:
parent
177ee3a6fb
commit
120d9a55c8
@ -118,7 +118,7 @@ func (this *AlienService) PreviewOrDownload(
|
|||||||
this.logger.Info("准备下载文件夹 %s", matter.Name)
|
this.logger.Info("准备下载文件夹 %s", matter.Name)
|
||||||
|
|
||||||
//目标地点
|
//目标地点
|
||||||
this.matterService.AtomicDownloadDirectory(writer, request, matter)
|
this.matterService.DownloadDirectory(writer, request, matter)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -109,7 +109,6 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
|||||||
userUuid := request.FormValue("userUuid")
|
userUuid := request.FormValue("userUuid")
|
||||||
name := request.FormValue("name")
|
name := request.FormValue("name")
|
||||||
dir := request.FormValue("dir")
|
dir := request.FormValue("dir")
|
||||||
alien := request.FormValue("alien")
|
|
||||||
orderDir := request.FormValue("orderDir")
|
orderDir := request.FormValue("orderDir")
|
||||||
orderSize := request.FormValue("orderSize")
|
orderSize := request.FormValue("orderSize")
|
||||||
orderName := request.FormValue("orderName")
|
orderName := request.FormValue("orderName")
|
||||||
@ -170,7 +169,7 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pager := this.matterDao.Page(page, pageSize, puuid, userUuid, name, dir, alien, extensions, sortArray)
|
pager := this.matterDao.Page(page, pageSize, puuid, userUuid, name, dir, extensions, sortArray)
|
||||||
|
|
||||||
return this.Success(pager)
|
return this.Success(pager)
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ func (this *MatterDao) List(puuid string, userUuid string, sortArray []builder.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取某个文件夹下所有的文件和子文件
|
//获取某个文件夹下所有的文件和子文件
|
||||||
func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid string, name string, dir string, alien string, extensions []string, sortArray []builder.OrderPair) *Pager {
|
func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid string, name string, dir string, extensions []string, sortArray []builder.OrderPair) *Pager {
|
||||||
|
|
||||||
var wp = &builder.WherePair{}
|
var wp = &builder.WherePair{}
|
||||||
|
|
||||||
@ -243,12 +243,6 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin
|
|||||||
wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{0}})
|
wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{0}})
|
||||||
}
|
}
|
||||||
|
|
||||||
if alien == TRUE {
|
|
||||||
wp = wp.And(&builder.WherePair{Query: "alien = ?", Args: []interface{}{1}})
|
|
||||||
} else if alien == FALSE {
|
|
||||||
wp = wp.And(&builder.WherePair{Query: "alien = ?", Args: []interface{}{0}})
|
|
||||||
}
|
|
||||||
|
|
||||||
var conditionDB *gorm.DB
|
var conditionDB *gorm.DB
|
||||||
if extensions != nil && len(extensions) > 0 {
|
if extensions != nil && len(extensions) > 0 {
|
||||||
var orWp = &builder.WherePair{}
|
var orWp = &builder.WherePair{}
|
||||||
|
@ -27,6 +27,7 @@ type MatterService struct {
|
|||||||
userService *UserService
|
userService *UserService
|
||||||
imageCacheDao *ImageCacheDao
|
imageCacheDao *ImageCacheDao
|
||||||
imageCacheService *ImageCacheService
|
imageCacheService *ImageCacheService
|
||||||
|
preferenceService *PreferenceService
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
@ -59,6 +60,11 @@ func (this *MatterService) Init() {
|
|||||||
this.imageCacheService = b
|
this.imageCacheService = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b = core.CONTEXT.GetBean(this.preferenceService)
|
||||||
|
if b, ok := b.(*PreferenceService); ok {
|
||||||
|
this.preferenceService = b
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//文件下载。支持分片下载
|
//文件下载。支持分片下载
|
||||||
@ -73,7 +79,7 @@ func (this *MatterService) DownloadFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//下载文件夹
|
//下载文件夹
|
||||||
func (this *MatterService) AtomicDownloadDirectory(
|
func (this *MatterService) DownloadDirectory(
|
||||||
writer http.ResponseWriter,
|
writer http.ResponseWriter,
|
||||||
request *http.Request,
|
request *http.Request,
|
||||||
matter *Matter) {
|
matter *Matter) {
|
||||||
@ -86,15 +92,17 @@ func (this *MatterService) AtomicDownloadDirectory(
|
|||||||
panic(result.BadRequest("matter 只能是文件夹"))
|
panic(result.BadRequest("matter 只能是文件夹"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//操作锁
|
|
||||||
this.userService.MatterLock(matter.UserUuid)
|
|
||||||
defer this.userService.MatterUnlock(matter.UserUuid)
|
|
||||||
|
|
||||||
//验证文件夹中文件总大小。
|
//验证文件夹中文件总大小。
|
||||||
sumSize := this.matterDao.SumSizeByUserUuidAndPath(matter.UserUuid, matter.Path)
|
sumSize := this.matterDao.SumSizeByUserUuidAndPath(matter.UserUuid, matter.Path)
|
||||||
this.logger.Info("文件夹 %s 大小为 %s", matter.Name, util.HumanFileSize(sumSize))
|
this.logger.Info("文件夹 %s 大小为 %s", matter.Name, util.HumanFileSize(sumSize))
|
||||||
|
|
||||||
//TODO: 文件夹下载的大小限制
|
//判断用户自身上传大小的限制
|
||||||
|
preference := this.preferenceService.Fetch()
|
||||||
|
if preference.DownloadDirMaxSize >= 0 {
|
||||||
|
if sumSize > preference.DownloadDirMaxSize {
|
||||||
|
panic(result.BadRequest("文件夹大小%s超出下载限制%s ", util.HumanFileSize(sumSize), util.HumanFileSize(preference.DownloadDirMaxSize)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//准备zip放置的目录。
|
//准备zip放置的目录。
|
||||||
destZipDirPath := fmt.Sprintf("%s/%d", GetUserZipRootDir(matter.Username), time.Now().UnixNano()/1e6)
|
destZipDirPath := fmt.Sprintf("%s/%d", GetUserZipRootDir(matter.Username), time.Now().UnixNano()/1e6)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/eyebluecn/tank/code/tool/result"
|
"github.com/eyebluecn/tank/code/tool/result"
|
||||||
"github.com/eyebluecn/tank/code/tool/util"
|
"github.com/eyebluecn/tank/code/tool/util"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PreferenceController struct {
|
type PreferenceController struct {
|
||||||
@ -39,7 +40,7 @@ func (this *PreferenceController) RegisterRoutes() map[string]func(writer http.R
|
|||||||
routeMap["/api/preference/ping"] = this.Wrap(this.Ping, USER_ROLE_GUEST)
|
routeMap["/api/preference/ping"] = this.Wrap(this.Ping, USER_ROLE_GUEST)
|
||||||
routeMap["/api/preference/fetch"] = this.Wrap(this.Fetch, USER_ROLE_GUEST)
|
routeMap["/api/preference/fetch"] = this.Wrap(this.Fetch, USER_ROLE_GUEST)
|
||||||
routeMap["/api/preference/edit"] = this.Wrap(this.Edit, USER_ROLE_ADMINISTRATOR)
|
routeMap["/api/preference/edit"] = this.Wrap(this.Edit, USER_ROLE_ADMINISTRATOR)
|
||||||
routeMap["/api/preference/system_cleanup"] = this.Wrap(this.SystemCleanup, USER_ROLE_ADMINISTRATOR)
|
routeMap["/api/preference/system/cleanup"] = this.Wrap(this.SystemCleanup, USER_ROLE_ADMINISTRATOR)
|
||||||
|
|
||||||
return routeMap
|
return routeMap
|
||||||
}
|
}
|
||||||
@ -70,21 +71,27 @@ func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http
|
|||||||
|
|
||||||
logoUrl := request.FormValue("logoUrl")
|
logoUrl := request.FormValue("logoUrl")
|
||||||
faviconUrl := request.FormValue("faviconUrl")
|
faviconUrl := request.FormValue("faviconUrl")
|
||||||
footerLine1 := request.FormValue("footerLine1")
|
copyright := request.FormValue("copyright")
|
||||||
footerLine2 := request.FormValue("footerLine2")
|
record := request.FormValue("record")
|
||||||
showAlienStr := request.FormValue("showAlien")
|
downloadDirMaxSizeStr := request.FormValue("downloadDirMaxSize")
|
||||||
|
|
||||||
|
var downloadDirMaxSize int64 = 0
|
||||||
|
if downloadDirMaxSizeStr == "" {
|
||||||
|
panic("文件下载最大限制必填!")
|
||||||
|
} else {
|
||||||
|
intDownloadDirMaxSize, err := strconv.Atoi(downloadDirMaxSizeStr)
|
||||||
|
this.PanicError(err)
|
||||||
|
|
||||||
|
downloadDirMaxSize = int64(intDownloadDirMaxSize)
|
||||||
|
}
|
||||||
|
|
||||||
preference := this.preferenceDao.Fetch()
|
preference := this.preferenceDao.Fetch()
|
||||||
preference.Name = name
|
preference.Name = name
|
||||||
preference.LogoUrl = logoUrl
|
preference.LogoUrl = logoUrl
|
||||||
preference.FaviconUrl = faviconUrl
|
preference.FaviconUrl = faviconUrl
|
||||||
preference.FooterLine1 = footerLine1
|
preference.Copyright = copyright
|
||||||
preference.FooterLine2 = footerLine2
|
preference.Record = record
|
||||||
if showAlienStr == TRUE {
|
preference.DownloadDirMaxSize = downloadDirMaxSize
|
||||||
preference.ShowAlien = true
|
|
||||||
} else if showAlienStr == FALSE {
|
|
||||||
preference.ShowAlien = false
|
|
||||||
}
|
|
||||||
|
|
||||||
preference = this.preferenceDao.Save(preference)
|
preference = this.preferenceDao.Save(preference)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func (this *PreferenceDao) Fetch() *Preference {
|
|||||||
|
|
||||||
if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
|
if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
|
||||||
preference.Name = "蓝眼云盘"
|
preference.Name = "蓝眼云盘"
|
||||||
preference.ShowAlien = true
|
|
||||||
this.Create(preference)
|
this.Create(preference)
|
||||||
return preference
|
return preference
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,12 +4,12 @@ import "github.com/eyebluecn/tank/code/core"
|
|||||||
|
|
||||||
type Preference struct {
|
type Preference struct {
|
||||||
Base
|
Base
|
||||||
Name string `json:"name" gorm:"type:varchar(45)"`
|
Name string `json:"name" gorm:"type:varchar(45)"`
|
||||||
LogoUrl string `json:"logoUrl" gorm:"type:varchar(255)"`
|
LogoUrl string `json:"logoUrl" gorm:"type:varchar(255)"`
|
||||||
FaviconUrl string `json:"faviconUrl" gorm:"type:varchar(255)"`
|
FaviconUrl string `json:"faviconUrl" gorm:"type:varchar(255)"`
|
||||||
FooterLine1 string `json:"footerLine1" gorm:"type:varchar(1024)"`
|
Copyright string `json:"copyright" gorm:"type:varchar(1024)"`
|
||||||
FooterLine2 string `json:"footerLine2" gorm:"type:varchar(1024)"`
|
Record string `json:"record" gorm:"type:varchar(1024)"`
|
||||||
ShowAlien bool `json:"showAlien" gorm:"type:tinyint(1) not null;default:1"`
|
DownloadDirMaxSize int64 `json:"downloadDirMaxSize" gorm:"type:bigint(20) not null;default:-1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// set File's table name to be `profiles`
|
// set File's table name to be `profiles`
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//将srcPath压缩到destPath。
|
||||||
func Zip(srcPath string, destPath string) {
|
func Zip(srcPath string, destPath string) {
|
||||||
|
|
||||||
if PathExists(destPath) {
|
if PathExists(destPath) {
|
||||||
@ -40,8 +41,6 @@ func Zip(srcPath string, destPath string) {
|
|||||||
return errBack
|
return errBack
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println("遍历文件: " + path)
|
|
||||||
|
|
||||||
// 通过文件信息,创建 zip 的文件信息
|
// 通过文件信息,创建 zip 的文件信息
|
||||||
fileHeader, err := zip.FileInfoHeader(fileInfo)
|
fileHeader, err := zip.FileInfoHeader(fileInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,7 +48,7 @@ func Zip(srcPath string, destPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 替换文件信息中的文件名
|
// 替换文件信息中的文件名
|
||||||
fileHeader.Name = strings.TrimPrefix(prefix+"/"+fileInfo.Name(), string(filepath.Separator))
|
fileHeader.Name = strings.TrimPrefix(prefix+"/"+fileInfo.Name(), "/")
|
||||||
|
|
||||||
// 目录加上/
|
// 目录加上/
|
||||||
if fileInfo.IsDir() {
|
if fileInfo.IsDir() {
|
||||||
@ -59,8 +58,6 @@ func Zip(srcPath string, destPath string) {
|
|||||||
prefix = prefix + "/" + fileInfo.Name()
|
prefix = prefix + "/" + fileInfo.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println("头部情况: " + fileHeader.Name)
|
|
||||||
|
|
||||||
// 写入文件信息,并返回一个 Write 结构
|
// 写入文件信息,并返回一个 Write 结构
|
||||||
writer, err := zipWriter.CreateHeader(fileHeader)
|
writer, err := zipWriter.CreateHeader(fileHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -89,9 +86,6 @@ func Zip(srcPath string, destPath string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输出压缩的内容
|
|
||||||
//fmt.Printf("成功压缩文件: %s, 共写入了 %d 个字符的数据\n", path, n)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
PanicError(err)
|
PanicError(err)
|
Loading…
Reference in New Issue
Block a user