diff --git a/code/rest/dashboard_service.go b/code/rest/dashboard_service.go index 04281bc..473a552 100644 --- a/code/rest/dashboard_service.go +++ b/code/rest/dashboard_service.go @@ -57,8 +57,6 @@ func (this *DashboardService) Bootstrap() { // handle the dashboard data. func (this *DashboardService) Etl() { - this.logger.Info("ETL dashboard data.") - startTime := util.FirstSecondOfDay(util.Yesterday()) endTime := util.LastSecondOfDay(util.Yesterday()) dt := util.ConvertTimeToDateString(startTime) diff --git a/code/rest/matter_dao.go b/code/rest/matter_dao.go index 6468b9a..453aba8 100644 --- a/code/rest/matter_dao.go +++ b/code/rest/matter_dao.go @@ -7,6 +7,7 @@ import ( "github.com/eyebluecn/tank/code/tool/util" "github.com/eyebluecn/tank/code/tool/uuid" "github.com/jinzhu/gorm" + "math" "os" "time" ) @@ -298,6 +299,31 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin return pager } +//handle matter page by page. +func (this *MatterDao) PageHandle(puuid string, userUuid string, name string, dir string, fun func(matter *Matter)) { + + //delete share and bridges. + pageSize := 1000 + sortArray := []builder.OrderPair{ + { + Key: "uuid", + Value: DIRECTION_ASC, + }, + } + count, _ := this.PlainPage(0, pageSize, puuid, userUuid, name, dir, nil, sortArray) + if count > 0 { + var totalPages = int(math.Ceil(float64(count) / float64(pageSize))) + + var page int + for page = 0; page < totalPages; page++ { + _, matters := this.PlainPage(0, pageSize, puuid, userUuid, name, dir, nil, sortArray) + for _, matter := range matters { + fun(matter) + } + } + } +} + func (this *MatterDao) Create(matter *Matter) *Matter { timeUUID, _ := uuid.NewV4() diff --git a/code/rest/matter_service.go b/code/rest/matter_service.go index fdc33f0..74d9df5 100644 --- a/code/rest/matter_service.go +++ b/code/rest/matter_service.go @@ -1049,3 +1049,29 @@ func (this *MatterService) adjustPath(matter *Matter, parentMatter *Matter) { } } + +//delete someone's EyeblueTank files according to physics files. +func (this *MatterService) DeleteByPhysics(user *User) { + + if user == nil { + panic(result.BadRequest("user cannot be nil.")) + } + + //scan user's file. + this.matterDao.PageHandle("", user.Uuid, "", "", func(matter *Matter) { + this.logger.Info("handle %s", matter.Name) + }) + +} + +//scan someone's physics files to EyeblueTank +func (this *MatterService) Scan(user *User) { + + if user == nil { + panic(result.BadRequest("user cannot be nil.")) + } + + rootDirPath := GetUserMatterRootDir(user.Username) + this.logger.Info("scan %s's root dir %s", user.Username, rootDirPath) + +} diff --git a/code/rest/preference_controller.go b/code/rest/preference_controller.go index f8d273c..e53a04e 100644 --- a/code/rest/preference_controller.go +++ b/code/rest/preference_controller.go @@ -5,6 +5,7 @@ import ( "github.com/eyebluecn/tank/code/tool/result" "github.com/eyebluecn/tank/code/tool/util" jsoniter "github.com/json-iterator/go" + "github.com/robfig/cron/v3" "net/http" "strconv" ) @@ -157,7 +158,19 @@ func (this *PreferenceController) EditScanConfig(writer http.ResponseWriter, req //validate the scan config. if scanConfig.Enable { //validate cron. + _, err := cron.ParseStandard(scanConfig.Cron) + this.PanicError(err) + //validate scope. + if scanConfig.Scope == SCAN_SCOPE_CUSTOM { + if len(scanConfig.Usernames) == 0 { + panic(result.BadRequest("scope cannot be null")) + } + } else if scanConfig.Scope == SCAN_SCOPE_ALL { + + } else { + panic(result.BadRequest("cannot recognize scope %s", scanConfig.Scope)) + } } preference = this.preferenceService.Save(preference) diff --git a/code/rest/preference_model.go b/code/rest/preference_model.go index 9b6ced6..ec66310 100644 --- a/code/rest/preference_model.go +++ b/code/rest/preference_model.go @@ -37,7 +37,7 @@ const ( type ScanConfig struct { //whether enable the scan task. Enable bool `json:"enable"` - //when to process the task. + //when to process the task. five fields. @every 1s Cron string `json:"cron"` //username Usernames []string `json:"usernames"` diff --git a/code/rest/share_service.go b/code/rest/share_service.go index 7a7a7c9..54e0074 100644 --- a/code/rest/share_service.go +++ b/code/rest/share_service.go @@ -118,17 +118,20 @@ func (this *ShareService) DeleteSharesByUser(request *http.Request, currentUser pageSize := 100 var sortArray []builder.OrderPair count, _ := this.shareDao.PlainPage(0, pageSize, currentUser.Uuid, sortArray) - var totalPages = int(math.Ceil(float64(count) / float64(pageSize))) + if count > 0 { + var totalPages = int(math.Ceil(float64(count) / float64(pageSize))) - var page int - for page = 0; page < totalPages; page++ { - _, shares := this.shareDao.PlainPage(0, pageSize, currentUser.Uuid, sortArray) - for _, share := range shares { - this.bridgeDao.DeleteByShareUuid(share.Uuid) + var page int + for page = 0; page < totalPages; page++ { + _, shares := this.shareDao.PlainPage(0, pageSize, currentUser.Uuid, sortArray) + for _, share := range shares { + this.bridgeDao.DeleteByShareUuid(share.Uuid) - //delete this share - this.shareDao.Delete(share) + //delete this share + this.shareDao.Delete(share) + } } + } } diff --git a/code/rest/user_controller.go b/code/rest/user_controller.go index 9af71c9..765b107 100644 --- a/code/rest/user_controller.go +++ b/code/rest/user_controller.go @@ -16,6 +16,7 @@ type UserController struct { BaseController preferenceService *PreferenceService userService *UserService + matterService *MatterService } func (this *UserController) Init() { @@ -31,6 +32,11 @@ func (this *UserController) Init() { this.userService = b } + b = core.CONTEXT.GetBean(this.matterService) + if b, ok := b.(*MatterService); ok { + this.matterService = b + } + } func (this *UserController) RegisterRoutes() map[string]func(writer http.ResponseWriter, request *http.Request) { @@ -50,6 +56,7 @@ func (this *UserController) RegisterRoutes() map[string]func(writer http.Respons routeMap["/api/user/page"] = this.Wrap(this.Page, USER_ROLE_ADMINISTRATOR) routeMap["/api/user/toggle/status"] = this.Wrap(this.ToggleStatus, USER_ROLE_ADMINISTRATOR) routeMap["/api/user/transfiguration"] = this.Wrap(this.Transfiguration, USER_ROLE_ADMINISTRATOR) + routeMap["/api/user/scan"] = this.Wrap(this.Scan, USER_ROLE_ADMINISTRATOR) routeMap["/api/user/delete"] = this.Wrap(this.Delete, USER_ROLE_ADMINISTRATOR) return routeMap @@ -432,6 +439,16 @@ func (this *UserController) Transfiguration(writer http.ResponseWriter, request return this.Success(session.Uuid) } +//scan user's physics files. create index into EyeblueTank +func (this *UserController) Scan(writer http.ResponseWriter, request *http.Request) *result.WebResult { + + uuid := request.FormValue("uuid") + currentUser := this.userDao.CheckByUuid(uuid) + this.matterService.Scan(currentUser) + + return this.Success("OK") +} + func (this *UserController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult { uuid := request.FormValue("uuid")