Finish the migrate program.
This commit is contained in:
parent
cf847d44d7
commit
7f225bb18e
@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/favicon.ico><title>tank-front-tmp</title><link href=/css/app.a576a8d2.css rel=preload as=style><link href=/css/chunk-vendors.cb22afd2.css rel=preload as=style><link href=/js/app.4452d0c8.js rel=preload as=script><link href=/js/chunk-vendors.220ccae9.js rel=preload as=script><link href=/css/chunk-vendors.cb22afd2.css rel=stylesheet><link href=/css/app.a576a8d2.css rel=stylesheet></head><body><noscript><strong>We're sorry but tank-front-tmp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.220ccae9.js></script><script src=/js/app.4452d0c8.js></script></body></html>
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/favicon.ico><title>tank-front-tmp</title><link href=/css/app.a576a8d2.css rel=preload as=style><link href=/css/chunk-vendors.cb22afd2.css rel=preload as=style><link href=/js/app.ce972e7b.js rel=preload as=script><link href=/js/chunk-vendors.220ccae9.js rel=preload as=script><link href=/css/chunk-vendors.cb22afd2.css rel=stylesheet><link href=/css/app.a576a8d2.css rel=stylesheet></head><body><noscript><strong>We're sorry but tank-front-tmp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.220ccae9.js></script><script src=/js/app.ce972e7b.js></script></body></html>
|
File diff suppressed because one or more lines are too long
11
build/html/js/app.ce972e7b.js
Normal file
11
build/html/js/app.ce972e7b.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -166,7 +166,7 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
|
||||
matters = []*Matter{matter}
|
||||
} else {
|
||||
// len(matters) == 0 means empty directory
|
||||
matters = this.matterDao.ListByPuuidAndUserUuid(matter.Uuid, user.Uuid, nil)
|
||||
matters = this.matterDao.FindByPuuidAndUserUuid(matter.Uuid, user.Uuid, nil)
|
||||
|
||||
//add this matter to head.
|
||||
matters = append([]*Matter{matter}, matters...)
|
||||
|
@ -456,7 +456,7 @@ func (this *MatterController) Zip(writer http.ResponseWriter, request *http.Requ
|
||||
|
||||
uuidArray := strings.Split(uuids, ",")
|
||||
|
||||
matters := this.matterDao.ListByUuids(uuidArray, nil)
|
||||
matters := this.matterDao.FindByUuids(uuidArray, nil)
|
||||
|
||||
if matters == nil || len(matters) == 0 {
|
||||
panic(result.BadRequest("matters cannot be nil."))
|
||||
|
@ -120,6 +120,30 @@ func (this *MatterDao) FindByUserUuidAndPuuidAndNameAndDirTrue(userUuid string,
|
||||
return matter
|
||||
}
|
||||
|
||||
func (this *MatterDao) FindByUserUuidAndPuuidAndDirTrue(userUuid string, puuid string) []*Matter {
|
||||
|
||||
var wp = &builder.WherePair{}
|
||||
|
||||
if userUuid != "" {
|
||||
wp = wp.And(&builder.WherePair{Query: "user_uuid = ?", Args: []interface{}{userUuid}})
|
||||
}
|
||||
|
||||
if puuid != "" {
|
||||
wp = wp.And(&builder.WherePair{Query: "puuid = ?", Args: []interface{}{puuid}})
|
||||
}
|
||||
|
||||
wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{1}})
|
||||
|
||||
var matters []*Matter
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where(wp.Query, wp.Args...).First(&matters)
|
||||
|
||||
if db.Error != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return matters
|
||||
}
|
||||
|
||||
func (this *MatterDao) CheckByUuidAndUserUuid(uuid string, userUuid string) *Matter {
|
||||
|
||||
var matter = &Matter{}
|
||||
@ -193,20 +217,11 @@ func (this *MatterDao) FindByUserUuidAndPuuidAndDirAndName(userUuid string, puui
|
||||
return matter
|
||||
}
|
||||
|
||||
func (this *MatterDao) ListByUserUuidAndPuuidAndDirAndName(userUuid string, puuid string, dir bool, name string) []*Matter {
|
||||
|
||||
func (this *MatterDao) FindByPuuidAndUserUuid(puuid string, userUuid string, sortArray []builder.OrderPair) []*Matter {
|
||||
var matters []*Matter
|
||||
|
||||
db := core.CONTEXT.GetDB().
|
||||
Where(Matter{UserUuid: userUuid, Puuid: puuid, Dir: dir, Name: name}).
|
||||
Find(&matters)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
return matters
|
||||
}
|
||||
|
||||
func (this *MatterDao) ListByPuuidAndUserUuid(puuid string, userUuid string, sortArray []builder.OrderPair) []*Matter {
|
||||
var matters []*Matter
|
||||
var wp = &builder.WherePair{}
|
||||
wp = wp.And(&builder.WherePair{Query: "puuid = ? AND user_uuid = ?", Args: []interface{}{puuid, userUuid}})
|
||||
|
||||
if sortArray == nil {
|
||||
|
||||
@ -222,13 +237,13 @@ func (this *MatterDao) ListByPuuidAndUserUuid(puuid string, userUuid string, sor
|
||||
}
|
||||
}
|
||||
|
||||
db := core.CONTEXT.GetDB().Where(Matter{UserUuid: userUuid, Puuid: puuid}).Order(this.GetSortString(sortArray)).Find(&matters)
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where(wp.Query, wp.Args...).Order(this.GetSortString(sortArray)).Find(&matters)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
return matters
|
||||
}
|
||||
|
||||
func (this *MatterDao) ListByUuids(uuids []string, sortArray []builder.OrderPair) []*Matter {
|
||||
func (this *MatterDao) FindByUuids(uuids []string, sortArray []builder.OrderPair) []*Matter {
|
||||
var matters []*Matter
|
||||
|
||||
db := core.CONTEXT.GetDB().Where(uuids).Order(this.GetSortString(sortArray)).Find(&matters)
|
||||
@ -236,8 +251,7 @@ func (this *MatterDao) ListByUuids(uuids []string, sortArray []builder.OrderPair
|
||||
|
||||
return matters
|
||||
}
|
||||
|
||||
func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid string, name string, dir string, extensions []string, sortArray []builder.OrderPair) *Pager {
|
||||
func (this *MatterDao) PlainPage(page int, pageSize int, puuid string, userUuid string, name string, dir string, extensions []string, sortArray []builder.OrderPair) (int, []*Matter) {
|
||||
|
||||
var wp = &builder.WherePair{}
|
||||
|
||||
@ -279,6 +293,12 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin
|
||||
var matters []*Matter
|
||||
db = conditionDB.Order(this.GetSortString(sortArray)).Offset(page * pageSize).Limit(pageSize).Find(&matters)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
return count, matters
|
||||
}
|
||||
func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid string, name string, dir string, extensions []string, sortArray []builder.OrderPair) *Pager {
|
||||
|
||||
count, matters := this.PlainPage(page, pageSize, puuid, userUuid, name, dir, extensions, sortArray)
|
||||
pager := NewPager(page, pageSize, count, matters)
|
||||
|
||||
return pager
|
||||
@ -337,7 +357,7 @@ func (this *MatterDao) Delete(matter *Matter) {
|
||||
|
||||
// recursive if dir
|
||||
if matter.Dir {
|
||||
matters := this.ListByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
matters := this.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
|
||||
for _, f := range matters {
|
||||
this.Delete(f)
|
||||
@ -461,6 +481,17 @@ func (this *MatterDao) CountByUserUuidAndPath(userUuid string, path string) int6
|
||||
|
||||
}
|
||||
|
||||
//统计总共有多少条。
|
||||
func (this *MatterDao) Count() int64 {
|
||||
|
||||
var count int64
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Count(&count)
|
||||
core.PanicError(db.Error)
|
||||
|
||||
return count
|
||||
|
||||
}
|
||||
|
||||
//System cleanup.
|
||||
func (this *MatterDao) Cleanup() {
|
||||
this.logger.Info("[MatterDao] clean up. Delete all Matter record in db and on disk.")
|
||||
|
@ -393,6 +393,50 @@ func (this *MatterService) ComputeRouteSize(matterUuid string, user *User) {
|
||||
this.ComputeRouteSize(matter.Puuid, user)
|
||||
}
|
||||
|
||||
// compute all dir's size.
|
||||
func (this *MatterService) ComputeAllDirSize(user *User) {
|
||||
|
||||
this.logger.Info("Compute all dir's size for user %s %s", user.Uuid, user.Username)
|
||||
|
||||
rootMatter := NewRootMatter(user)
|
||||
this.ComputeDirSize(rootMatter, user)
|
||||
}
|
||||
|
||||
// compute a dir's size.
|
||||
func (this *MatterService) ComputeDirSize(dirMatter *Matter, user *User) {
|
||||
|
||||
this.logger.Info("Compute dir's size %s %s", dirMatter.Uuid, dirMatter.Name)
|
||||
|
||||
//update sub dir first
|
||||
childrenDirMatters := this.matterDao.FindByUserUuidAndPuuidAndDirTrue(user.Uuid, dirMatter.Uuid)
|
||||
for _, childrenDirMatter := range childrenDirMatters {
|
||||
this.ComputeDirSize(childrenDirMatter, user)
|
||||
}
|
||||
|
||||
//if to root directory, then update to user's info.
|
||||
if dirMatter.Uuid == MATTER_ROOT {
|
||||
|
||||
size := this.matterDao.SizeByPuuidAndUserUuid(MATTER_ROOT, user.Uuid)
|
||||
|
||||
db := core.CONTEXT.GetDB().Model(&User{}).Where("uuid = ?", user.Uuid).Update("total_size", size)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
//update user total size info in cache.
|
||||
user.TotalSize = size
|
||||
} else {
|
||||
|
||||
//compute self.
|
||||
size := this.matterDao.SizeByPuuidAndUserUuid(dirMatter.Uuid, user.Uuid)
|
||||
|
||||
//when changed, we update
|
||||
if dirMatter.Size != size {
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", dirMatter.Uuid).Update("size", size)
|
||||
this.PanicError(db.Error)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//inner create directory.
|
||||
func (this *MatterService) createDirectory(request *http.Request, dirMatter *Matter, name string, user *User) *Matter {
|
||||
|
||||
@ -515,7 +559,7 @@ func (this *MatterService) move(request *http.Request, srcMatter *Matter, destDi
|
||||
srcMatter = this.matterDao.Save(srcMatter)
|
||||
|
||||
//reCompute the path.
|
||||
matters := this.matterDao.ListByPuuidAndUserUuid(srcMatter.Uuid, srcMatter.UserUuid, nil)
|
||||
matters := this.matterDao.FindByPuuidAndUserUuid(srcMatter.Uuid, srcMatter.UserUuid, nil)
|
||||
for _, m := range matters {
|
||||
this.adjustPath(m, srcMatter)
|
||||
}
|
||||
@ -638,7 +682,7 @@ func (this *MatterService) copy(request *http.Request, srcMatter *Matter, destDi
|
||||
newMatter = this.matterDao.Create(newMatter)
|
||||
|
||||
//copy children
|
||||
matters := this.matterDao.ListByPuuidAndUserUuid(srcMatter.Uuid, srcMatter.UserUuid, nil)
|
||||
matters := this.matterDao.FindByPuuidAndUserUuid(srcMatter.Uuid, srcMatter.UserUuid, nil)
|
||||
for _, m := range matters {
|
||||
this.copy(request, m, newMatter, m.Name)
|
||||
}
|
||||
@ -729,7 +773,7 @@ func (this *MatterService) AtomicRename(request *http.Request, matter *Matter, n
|
||||
matter = this.matterDao.Save(matter)
|
||||
|
||||
//调整该文件夹下文件的Path.
|
||||
matters := this.matterDao.ListByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
matters := this.matterDao.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
for _, m := range matters {
|
||||
this.adjustPath(m, matter)
|
||||
}
|
||||
@ -917,7 +961,7 @@ func (this *MatterService) WrapChildrenDetail(request *http.Request, matter *Mat
|
||||
|
||||
if matter.Dir {
|
||||
|
||||
children := this.matterDao.ListByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
children := this.matterDao.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
matter.Children = children
|
||||
|
||||
for _, child := range matter.Children {
|
||||
@ -967,7 +1011,7 @@ func (this *MatterService) adjustPath(matter *Matter, parentMatter *Matter) {
|
||||
matter = this.matterDao.Save(matter)
|
||||
|
||||
//adjust children.
|
||||
matters := this.matterDao.ListByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
matters := this.matterDao.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
for _, m := range matters {
|
||||
this.adjustPath(m, matter)
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
type PreferenceController struct {
|
||||
BaseController
|
||||
preferenceDao *PreferenceDao
|
||||
matterDao *MatterDao
|
||||
preferenceService *PreferenceService
|
||||
migrating bool
|
||||
}
|
||||
|
||||
func (this *PreferenceController) Init() {
|
||||
@ -23,6 +23,10 @@ func (this *PreferenceController) Init() {
|
||||
this.preferenceDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.matterDao)
|
||||
if b, ok := b.(*MatterDao); ok {
|
||||
this.matterDao = b
|
||||
}
|
||||
b = core.CONTEXT.GetBean(this.preferenceService)
|
||||
if b, ok := b.(*PreferenceService); ok {
|
||||
this.preferenceService = b
|
||||
@ -125,44 +129,6 @@ func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http
|
||||
return this.Success(preference)
|
||||
}
|
||||
|
||||
//migrate 2.0's db data and file data to 3.0
|
||||
func (this *PreferenceController) Migrate20to30(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
this.logger.Info("start migrating from 2.0 to 3.0")
|
||||
|
||||
if this.migrating {
|
||||
panic(result.BadRequest("migrating work is processing"))
|
||||
} else {
|
||||
this.migrating = true
|
||||
}
|
||||
defer func() {
|
||||
this.migrating = false
|
||||
}()
|
||||
|
||||
migrateDashboardSql := "INSERT INTO `tank`.`tank30_download_token` ( `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `matter_uuid`, `expire_time`, `ip` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `matter_uuid`, `expire_time`, `ip` FROM `tank`.`tank20_download_token`)"
|
||||
this.logger.Info(migrateDashboardSql)
|
||||
core.CONTEXT.GetDB().Exec(migrateDashboardSql)
|
||||
|
||||
migrateDownloadTokenSql := "INSERT INTO `tank`.`tank30_dashboard` ( `uuid`, `sort`, `update_time`, `create_time`, `invoke_num`, `total_invoke_num`, `uv`, `total_uv`, `matter_num`, `total_matter_num`, `file_size`, `total_file_size`, `avg_cost`, `dt` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `invoke_num`, `total_invoke_num`, `uv`, `total_uv`, `matter_num`, `total_matter_num`, `file_size`, `total_file_size`, `avg_cost`, `dt` FROM `tank`.`tank20_dashboard` )"
|
||||
this.logger.Info(migrateDownloadTokenSql)
|
||||
core.CONTEXT.GetDB().Exec(migrateDownloadTokenSql)
|
||||
|
||||
migrateMatterSql := "INSERT INTO `tank`.`tank30_matter` ( `uuid`, `sort`, `update_time`, `create_time`, `puuid`, `user_uuid`, `username`, `dir`, `name`, `md5`, `size`, `privacy`, `path`, `times` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `puuid`, `user_uuid`, '', `dir`, `name`, `md5`, `size`, `privacy`, `path`, `times` FROM `tank`.`tank20_matter` ) "
|
||||
this.logger.Info(migrateMatterSql)
|
||||
core.CONTEXT.GetDB().Exec(migrateMatterSql)
|
||||
|
||||
migrateUploadTokenSql := "INSERT INTO `tank`.`tank30_upload_token` ( `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `folder_uuid`, `matter_uuid`, `expire_time`, `filename`, `privacy`, `size`, `ip` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `folder_uuid`, `matter_uuid`, `expire_time`, `filename`, `privacy`, `size`, `ip` FROM `tank`.`tank20_upload_token` ) "
|
||||
this.logger.Info(migrateUploadTokenSql)
|
||||
core.CONTEXT.GetDB().Exec(migrateUploadTokenSql)
|
||||
|
||||
//username in tank2.0 add _20.
|
||||
migrateUserSql := "INSERT INTO `tank`.`tank30_user` ( `uuid`, `sort`, `update_time`, `create_time`, `role`, `username`, `password`, `avatar_url`, `last_ip`, `last_time`, `size_limit`, `total_size_limit`, `total_size`, `status` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `role`, CONCAT(`username`,'_20') as `username`, `password`, `avatar_url`, `last_ip`, `last_time`, `size_limit`, -1, 0, `status` FROM `tank`.`tank20_user` )"
|
||||
this.logger.Info(migrateUserSql)
|
||||
core.CONTEXT.GetDB().Exec(migrateUserSql)
|
||||
|
||||
return this.Success("OK")
|
||||
}
|
||||
|
||||
//cleanup system data.
|
||||
func (this *PreferenceController) SystemCleanup(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
@ -178,3 +144,12 @@ func (this *PreferenceController) SystemCleanup(writer http.ResponseWriter, requ
|
||||
|
||||
return this.Success("OK")
|
||||
}
|
||||
|
||||
//migrate 2.0's db data and file data to 3.0
|
||||
func (this *PreferenceController) Migrate20to30(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
this.logger.Info("start migrating from 2.0 to 3.0")
|
||||
|
||||
this.preferenceService.Migrate20to30(writer, request)
|
||||
return this.Success("OK")
|
||||
}
|
||||
|
@ -1,12 +1,26 @@
|
||||
package rest
|
||||
|
||||
import "github.com/eyebluecn/tank/code/core"
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
"github.com/eyebluecn/tank/code/tool/i18n"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//@Service
|
||||
type PreferenceService struct {
|
||||
BaseBean
|
||||
preferenceDao *PreferenceDao
|
||||
preference *Preference
|
||||
matterDao *MatterDao
|
||||
matterService *MatterService
|
||||
userDao *UserDao
|
||||
migrating bool
|
||||
}
|
||||
|
||||
func (this *PreferenceService) Init() {
|
||||
@ -17,6 +31,21 @@ func (this *PreferenceService) Init() {
|
||||
this.preferenceDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.matterDao)
|
||||
if b, ok := b.(*MatterDao); ok {
|
||||
this.matterDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.matterService)
|
||||
if b, ok := b.(*MatterService); ok {
|
||||
this.matterService = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.userDao)
|
||||
if b, ok := b.(*UserDao); ok {
|
||||
this.userDao = b
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (this *PreferenceService) Fetch() *Preference {
|
||||
@ -42,3 +71,191 @@ func (this *PreferenceService) Cleanup() {
|
||||
|
||||
this.Reset()
|
||||
}
|
||||
|
||||
//migrate 2.0's db data and file data to 3.0
|
||||
func (this *PreferenceService) Migrate20to30(writer http.ResponseWriter, request *http.Request) {
|
||||
|
||||
matterPath := request.FormValue("matterPath")
|
||||
|
||||
if matterPath == "" {
|
||||
panic(result.BadRequest("matterPath required"))
|
||||
}
|
||||
|
||||
this.logger.Info("start migrating from 2.0 to 3.0")
|
||||
|
||||
//lock
|
||||
if this.migrating {
|
||||
panic(result.BadRequest("migrating work is processing"))
|
||||
} else {
|
||||
this.migrating = true
|
||||
}
|
||||
defer func() {
|
||||
this.migrating = false
|
||||
}()
|
||||
|
||||
//delete all users with _20
|
||||
this.userDao.DeleteUsers20()
|
||||
|
||||
migrateDashboardSql := "INSERT INTO `tank`.`tank30_download_token` ( `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `matter_uuid`, `expire_time`, `ip` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `matter_uuid`, `expire_time`, `ip` FROM `tank`.`tank20_download_token`)"
|
||||
this.logger.Info(migrateDashboardSql)
|
||||
db := core.CONTEXT.GetDB().Exec(migrateDashboardSql)
|
||||
if db.Error != nil {
|
||||
this.logger.Error("%v", db.Error)
|
||||
}
|
||||
|
||||
migrateDownloadTokenSql := "INSERT INTO `tank`.`tank30_dashboard` ( `uuid`, `sort`, `update_time`, `create_time`, `invoke_num`, `total_invoke_num`, `uv`, `total_uv`, `matter_num`, `total_matter_num`, `file_size`, `total_file_size`, `avg_cost`, `dt` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `invoke_num`, `total_invoke_num`, `uv`, `total_uv`, `matter_num`, `total_matter_num`, `file_size`, `total_file_size`, `avg_cost`, `dt` FROM `tank`.`tank20_dashboard` )"
|
||||
this.logger.Info(migrateDownloadTokenSql)
|
||||
db = core.CONTEXT.GetDB().Exec(migrateDownloadTokenSql)
|
||||
if db.Error != nil {
|
||||
this.logger.Error("%v", db.Error)
|
||||
}
|
||||
|
||||
migrateMatterSql := "INSERT INTO `tank`.`tank30_matter` ( `uuid`, `sort`, `update_time`, `create_time`, `puuid`, `user_uuid`, `username`, `dir`, `name`, `md5`, `size`, `privacy`, `path`, `times` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `puuid`, `user_uuid`, '', `dir`, `name`, `md5`, `size`, `privacy`, `path`, `times` FROM `tank`.`tank20_matter` ) "
|
||||
this.logger.Info(migrateMatterSql)
|
||||
db = core.CONTEXT.GetDB().Exec(migrateMatterSql)
|
||||
if db.Error != nil {
|
||||
this.logger.Error("%v", db.Error)
|
||||
}
|
||||
|
||||
migrateUploadTokenSql := "INSERT INTO `tank`.`tank30_upload_token` ( `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `folder_uuid`, `matter_uuid`, `expire_time`, `filename`, `privacy`, `size`, `ip` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `user_uuid`, `folder_uuid`, `matter_uuid`, `expire_time`, `filename`, `privacy`, `size`, `ip` FROM `tank`.`tank20_upload_token` ) "
|
||||
this.logger.Info(migrateUploadTokenSql)
|
||||
db = core.CONTEXT.GetDB().Exec(migrateUploadTokenSql)
|
||||
if db.Error != nil {
|
||||
this.logger.Error("%v", db.Error)
|
||||
}
|
||||
|
||||
//username in tank2.0 add _20.
|
||||
migrateUserSql := "INSERT INTO `tank`.`tank30_user` ( `uuid`, `sort`, `update_time`, `create_time`, `role`, `username`, `password`, `avatar_url`, `last_ip`, `last_time`, `size_limit`, `total_size_limit`, `total_size`, `status` ) ( SELECT `uuid`, `sort`, `update_time`, `create_time`, `role`, CONCAT(`username`,'_20') as `username`, `password`, `avatar_url`, `last_ip`, `last_time`, `size_limit`, -1, 0, `status` FROM `tank`.`tank20_user` )"
|
||||
this.logger.Info(migrateUserSql)
|
||||
db = core.CONTEXT.GetDB().Exec(migrateUserSql)
|
||||
if db.Error != nil {
|
||||
this.logger.Error("%v", db.Error)
|
||||
}
|
||||
|
||||
//find all 2.0 users.
|
||||
users := this.userDao.FindUsers20()
|
||||
for _, user := range users {
|
||||
this.logger.Info("start handling matters for user %s %s", user.Uuid, user.Username)
|
||||
rootMatter := NewRootMatter(user)
|
||||
firstLevelMatters := this.matterDao.FindByPuuidAndUserUuid(MATTER_ROOT, user.Uuid, nil)
|
||||
for _, firstLevelMatter := range firstLevelMatters {
|
||||
this.HandleMatter20(request, matterPath, rootMatter, firstLevelMatter, user)
|
||||
}
|
||||
|
||||
//adjust all the size.
|
||||
this.matterService.ComputeAllDirSize(user)
|
||||
}
|
||||
}
|
||||
|
||||
//handle matter from 2.0
|
||||
func (this *PreferenceService) HandleMatter20(request *http.Request, matterPath string, dirMatter *Matter, matter *Matter, user *User) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
this.logger.Warn("HandleMatter20 occur error %v when handle matter %s %s. Ignore the error and continue. \r\n", err, matter.Uuid, matter.Name)
|
||||
}
|
||||
}()
|
||||
|
||||
this.logger.Info("start handling matter %s", matter.Name)
|
||||
|
||||
if matter == nil {
|
||||
panic(result.BadRequest("matter cannot be nil."))
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
panic(result.BadRequest("user cannot be nil."))
|
||||
}
|
||||
|
||||
if dirMatter == nil {
|
||||
panic(result.BadRequest("dirMatter cannot be nil"))
|
||||
}
|
||||
|
||||
if !dirMatter.Dir {
|
||||
panic(result.BadRequest("dirMatter must be directory"))
|
||||
}
|
||||
|
||||
if dirMatter.UserUuid != user.Uuid {
|
||||
|
||||
panic(result.BadRequest("file's user not the same"))
|
||||
}
|
||||
|
||||
name := matter.Name
|
||||
filename := name
|
||||
if name == "" {
|
||||
panic(result.BadRequest("name cannot be blank"))
|
||||
}
|
||||
|
||||
if len(name) > MATTER_NAME_MAX_LENGTH {
|
||||
|
||||
panic(result.BadRequestI18n(request, i18n.MatterNameLengthExceedLimit, len(name), MATTER_NAME_MAX_LENGTH))
|
||||
|
||||
}
|
||||
|
||||
//if directory. Create it.
|
||||
if matter.Dir {
|
||||
|
||||
if m, _ := regexp.MatchString(MATTER_NAME_PATTERN, name); m {
|
||||
panic(result.BadRequestI18n(request, i18n.MatterNameContainSpecialChars))
|
||||
}
|
||||
|
||||
parts := strings.Split(dirMatter.Path, "/")
|
||||
|
||||
if len(parts) > MATTER_NAME_MAX_DEPTH {
|
||||
panic(result.BadRequestI18n(request, i18n.MatterDepthExceedLimit, len(parts), MATTER_NAME_MAX_DEPTH))
|
||||
}
|
||||
|
||||
absolutePath := GetUserMatterRootDir(user.Username) + dirMatter.Path + "/" + name
|
||||
|
||||
relativePath := dirMatter.Path + "/" + name
|
||||
|
||||
//crate directory on disk.
|
||||
dirPath := util.MakeDirAll(absolutePath)
|
||||
this.logger.Info("Create Directory: %s", dirPath)
|
||||
|
||||
//change matter info.
|
||||
matter.Username = user.Username
|
||||
matter.Path = relativePath
|
||||
|
||||
matter = this.matterDao.Save(matter)
|
||||
|
||||
//handle its children.
|
||||
children := this.matterDao.FindByPuuidAndUserUuid(matter.Uuid, user.Uuid, nil)
|
||||
for _, child := range children {
|
||||
this.HandleMatter20(request, matterPath, matter, child, user)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
//if file. copy and adjust it.
|
||||
|
||||
dirAbsolutePath := dirMatter.AbsolutePath()
|
||||
dirRelativePath := dirMatter.Path
|
||||
|
||||
fileAbsolutePath := dirAbsolutePath + "/" + filename
|
||||
fileRelativePath := dirRelativePath + "/" + filename
|
||||
|
||||
util.MakeDirAll(dirAbsolutePath)
|
||||
|
||||
//if exist, panic it.
|
||||
exist := util.PathExists(fileAbsolutePath)
|
||||
if exist {
|
||||
this.logger.Error("%s exits, overwrite it.", fileAbsolutePath)
|
||||
removeError := os.Remove(fileAbsolutePath)
|
||||
this.PanicError(removeError)
|
||||
}
|
||||
|
||||
srcAbsolutePath := fmt.Sprintf("%s%s", matterPath, matter.Path)
|
||||
|
||||
//find the 2.0 disk file.
|
||||
fileSize := util.CopyFile(srcAbsolutePath, fileAbsolutePath)
|
||||
|
||||
this.logger.Info("copy %s %v ", filename, util.HumanFileSize(fileSize))
|
||||
|
||||
//update info.
|
||||
matter.Path = fileRelativePath
|
||||
matter.Username = user.Username
|
||||
|
||||
matter = this.matterDao.Save(matter)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ func (this *ShareController) Browse(writer http.ResponseWriter, request *http.Re
|
||||
Value: DIRECTION_DESC,
|
||||
},
|
||||
}
|
||||
matters = this.matterDao.ListByUuids(uuids, sortArray)
|
||||
matters = this.matterDao.FindByUuids(uuids, sortArray)
|
||||
|
||||
share.Matters = matters
|
||||
}
|
||||
@ -358,7 +358,7 @@ func (this *ShareController) Zip(writer http.ResponseWriter, request *http.Reque
|
||||
for _, bridge := range bridges {
|
||||
matterUuids = append(matterUuids, bridge.MatterUuid)
|
||||
}
|
||||
matters := this.matterDao.ListByUuids(matterUuids, nil)
|
||||
matters := this.matterDao.FindByUuids(matterUuids, nil)
|
||||
this.matterService.DownloadZip(writer, request, matters)
|
||||
|
||||
} else {
|
||||
|
@ -130,6 +130,25 @@ func (this *UserDao) Save(user *User) *User {
|
||||
return user
|
||||
}
|
||||
|
||||
//find all 2.0 users.
|
||||
func (this *UserDao) FindUsers20() []*User {
|
||||
var users []*User
|
||||
var wp = &builder.WherePair{}
|
||||
wp = wp.And(&builder.WherePair{Query: "username like ?", Args: []interface{}{"%_20"}})
|
||||
|
||||
db := core.CONTEXT.GetDB().Model(&User{}).Where(wp.Query, wp.Args...).Find(&users)
|
||||
this.PanicError(db.Error)
|
||||
return users
|
||||
}
|
||||
|
||||
func (this *UserDao) DeleteUsers20() {
|
||||
var wp = &builder.WherePair{}
|
||||
wp = wp.And(&builder.WherePair{Query: "username like ?", Args: []interface{}{"%_20"}})
|
||||
|
||||
db := core.CONTEXT.GetDB().Where(wp.Query, wp.Args...).Delete(User{})
|
||||
this.PanicError(db.Error)
|
||||
}
|
||||
|
||||
//System cleanup.
|
||||
func (this *UserDao) Cleanup() {
|
||||
this.logger.Info("[UserDao] clean up. Delete all User")
|
||||
|
@ -195,12 +195,11 @@ func (this *TankRouter) ServeHTTP(writer http.ResponseWriter, request *http.Requ
|
||||
//static file.
|
||||
dir := util.GetHtmlPath()
|
||||
|
||||
requestURI := request.RequestURI
|
||||
if requestURI == "" || request.RequestURI == "/" {
|
||||
requestURI = "index.html"
|
||||
if path == "" || path == "/" {
|
||||
path = "index.html"
|
||||
}
|
||||
|
||||
filePath := dir + requestURI
|
||||
filePath := dir + path
|
||||
exists := util.PathExists(filePath)
|
||||
if !exists {
|
||||
filePath = dir + "/index.html"
|
||||
|
Loading…
Reference in New Issue
Block a user