diff --git a/rest/alien_controller.go b/rest/alien_controller.go index f5f3d32..5385fcb 100644 --- a/rest/alien_controller.go +++ b/rest/alien_controller.go @@ -169,7 +169,7 @@ func (this *AlienController) FetchUploadToken(writer http.ResponseWriter, reques if privacyStr == "" { panic(`文件公有性必填`) } else { - if privacyStr == "true" { + if privacyStr == TRUE { privacy = true } else if privacyStr == "false" { privacy = false @@ -343,9 +343,9 @@ func (this *AlienController) CrawlDirect(writer http.ResponseWriter, request *ht if privacyStr == "" { panic(`文件公有性必填`) } else { - if privacyStr == "true" { + if privacyStr == TRUE { privacy = true - } else if privacyStr == "false" { + } else if privacyStr == FALSE { privacy = false } else { panic(`文件公有性不符合规范`) diff --git a/rest/base_model.go b/rest/base_model.go index 61c28e4..5dfbe47 100644 --- a/rest/base_model.go +++ b/rest/base_model.go @@ -6,6 +6,11 @@ import ( "time" ) +const ( + TRUE = "true" + FALSE = "false" +) + type Time time.Time type IBase interface { diff --git a/rest/matter_controller.go b/rest/matter_controller.go index d0f0618..d37eb5a 100644 --- a/rest/matter_controller.go +++ b/rest/matter_controller.go @@ -6,7 +6,6 @@ import ( "regexp" "strconv" "strings" - "time" ) type MatterController struct { @@ -249,52 +248,36 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req func (this *MatterController) Upload(writer http.ResponseWriter, request *http.Request) *WebResult { userUuid := request.FormValue("userUuid") + puuid := request.FormValue("puuid") + privacyStr := request.FormValue("privacy") + file, handler, err := request.FormFile("file") + this.PanicError(err) + defer func() { + err := file.Close() + this.PanicError(err) + }() + user := this.checkUser(writer, request) + //管理员可以传到指定用户的目录下。 if user.Role != USER_ROLE_ADMINISTRATOR { userUuid = user.Uuid } user = this.userDao.CheckByUuid(userUuid) - alienStr := request.FormValue("alien") - alien := false - puuid := "" - - if alienStr == "true" { - alien = true - - //如果是应用文件的话,统一放在同一个地方。 - puuid = this.matterService.GetDirUuid(userUuid, fmt.Sprintf("/应用数据/%s", time.Now().Local().Format("20060102150405"))) - + if puuid == "" { + this.PanicBadRequest("puuid必填") } else { - puuid = request.FormValue("puuid") - if puuid == "" { - this.PanicBadRequest("puuid必填") - } else { - if puuid != MATTER_ROOT { - //找出上一级的文件夹。 - this.matterDao.CheckByUuidAndUserUuid(puuid, userUuid) - - } + if puuid != MATTER_ROOT { + //验证puuid是否存在 + this.matterDao.CheckByUuidAndUserUuid(puuid, userUuid) } } - privacy := false - privacyStr := request.FormValue("privacy") - if privacyStr == "true" { - privacy = true - } + privacy := privacyStr == TRUE - err := request.ParseMultipartForm(32 << 20) + err = request.ParseMultipartForm(32 << 20) this.PanicError(err) - file, handler, err := request.FormFile("file") - this.PanicError(err) - - defer func() { - err := file.Close() - this.PanicError(err) - }() - //对于IE浏览器,filename可能包含了路径。 fileName := handler.Filename pos := strings.LastIndex(fileName, "\\") @@ -306,7 +289,7 @@ func (this *MatterController) Upload(writer http.ResponseWriter, request *http.R fileName = fileName[pos+1:] } - matter := this.matterService.Upload(file, user, puuid, fileName, privacy, alien) + matter := this.matterService.Upload(file, user, puuid, fileName, privacy, false) return this.Success(matter) } @@ -338,7 +321,7 @@ func (this *MatterController) Crawl(writer http.ResponseWriter, request *http.Re privacy := false privacyStr := request.FormValue("privacy") - if privacyStr == "true" { + if privacyStr == TRUE { privacy = true } @@ -464,7 +447,7 @@ func (this *MatterController) ChangePrivacy(writer http.ResponseWriter, request uuid := request.FormValue("uuid") privacyStr := request.FormValue("privacy") privacy := false - if privacyStr == "true" { + if privacyStr == TRUE { privacy = true } //找出该文件或者文件夹 diff --git a/rest/matter_dao.go b/rest/matter_dao.go index 07f7fad..42e91d4 100644 --- a/rest/matter_dao.go +++ b/rest/matter_dao.go @@ -161,15 +161,15 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin wp = wp.And(&WherePair{Query: "name LIKE ?", Args: []interface{}{"%" + name + "%"}}) } - if dir == "true" { + if dir == TRUE { wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{1}}) - } else if dir == "false" { + } else if dir == FALSE { wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{0}}) } - if alien == "true" { + if alien == TRUE { wp = wp.And(&WherePair{Query: "alien = ?", Args: []interface{}{1}}) - } else if alien == "false" { + } else if alien == FALSE { wp = wp.And(&WherePair{Query: "alien = ?", Args: []interface{}{0}}) } diff --git a/rest/matter_model.go b/rest/matter_model.go index 435bf54..c36fd01 100644 --- a/rest/matter_model.go +++ b/rest/matter_model.go @@ -2,6 +2,7 @@ package rest const ( MATTER_ROOT = "root" + MATTER_CACHE = "cache" ) /** diff --git a/rest/preference_controller.go b/rest/preference_controller.go index 2f22277..a1b046c 100644 --- a/rest/preference_controller.go +++ b/rest/preference_controller.go @@ -68,9 +68,9 @@ func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http preference.FaviconUrl = faviconUrl preference.FooterLine1 = footerLine1 preference.FooterLine2 = footerLine2 - if showAlienStr == "true" { + if showAlienStr == TRUE { preference.ShowAlien = true - } else if showAlienStr == "false" { + } else if showAlienStr == FALSE { preference.ShowAlien = false } diff --git a/rest/util_path.go b/rest/util_path.go index a6d2648..5618394 100644 --- a/rest/util_path.go +++ b/rest/util_path.go @@ -158,7 +158,7 @@ func GetUserFileDir(username string, cache bool) (absolutePath string, relativeP if cache { //如果是缓存文件夹,那么统一放在cache这个文件夹下面 - firstDir := "cache" + firstDir := MATTER_CACHE now := time.Now() datePath := now.Format("2006-01-02") @@ -169,7 +169,7 @@ func GetUserFileDir(username string, cache bool) (absolutePath string, relativeP relativePath = fmt.Sprintf("/%s/%s/%s/%d", username, firstDir, datePath, timestamp) } else { - firstDir := "root" + firstDir := MATTER_ROOT absolutePath = fmt.Sprintf("%s/%s/%s", filePath, username, firstDir) relativePath = fmt.Sprintf("/%s/%s", username, firstDir) }