Fix the upload alien issue.

This commit is contained in:
zicla 2019-04-02 02:49:31 +08:00
parent 2fb512a176
commit a8cc42b915
7 changed files with 37 additions and 48 deletions

View File

@ -169,7 +169,7 @@ func (this *AlienController) FetchUploadToken(writer http.ResponseWriter, reques
if privacyStr == "" { if privacyStr == "" {
panic(`文件公有性必填`) panic(`文件公有性必填`)
} else { } else {
if privacyStr == "true" { if privacyStr == TRUE {
privacy = true privacy = true
} else if privacyStr == "false" { } else if privacyStr == "false" {
privacy = false privacy = false
@ -343,9 +343,9 @@ func (this *AlienController) CrawlDirect(writer http.ResponseWriter, request *ht
if privacyStr == "" { if privacyStr == "" {
panic(`文件公有性必填`) panic(`文件公有性必填`)
} else { } else {
if privacyStr == "true" { if privacyStr == TRUE {
privacy = true privacy = true
} else if privacyStr == "false" { } else if privacyStr == FALSE {
privacy = false privacy = false
} else { } else {
panic(`文件公有性不符合规范`) panic(`文件公有性不符合规范`)

View File

@ -6,6 +6,11 @@ import (
"time" "time"
) )
const (
TRUE = "true"
FALSE = "false"
)
type Time time.Time type Time time.Time
type IBase interface { type IBase interface {

View File

@ -6,7 +6,6 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"time"
) )
type MatterController struct { 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 { func (this *MatterController) Upload(writer http.ResponseWriter, request *http.Request) *WebResult {
userUuid := request.FormValue("userUuid") 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) user := this.checkUser(writer, request)
//管理员可以传到指定用户的目录下。
if user.Role != USER_ROLE_ADMINISTRATOR { if user.Role != USER_ROLE_ADMINISTRATOR {
userUuid = user.Uuid userUuid = user.Uuid
} }
user = this.userDao.CheckByUuid(userUuid) 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")))
} else {
puuid = request.FormValue("puuid")
if puuid == "" { if puuid == "" {
this.PanicBadRequest("puuid必填") this.PanicBadRequest("puuid必填")
} else { } else {
if puuid != MATTER_ROOT { if puuid != MATTER_ROOT {
//找出上一级的文件夹。 //验证puuid是否存在
this.matterDao.CheckByUuidAndUserUuid(puuid, userUuid) this.matterDao.CheckByUuidAndUserUuid(puuid, userUuid)
}
} }
} }
privacy := false privacy := privacyStr == TRUE
privacyStr := request.FormValue("privacy")
if privacyStr == "true" {
privacy = true
}
err := request.ParseMultipartForm(32 << 20) err = request.ParseMultipartForm(32 << 20)
this.PanicError(err) this.PanicError(err)
file, handler, err := request.FormFile("file")
this.PanicError(err)
defer func() {
err := file.Close()
this.PanicError(err)
}()
//对于IE浏览器filename可能包含了路径。 //对于IE浏览器filename可能包含了路径。
fileName := handler.Filename fileName := handler.Filename
pos := strings.LastIndex(fileName, "\\") pos := strings.LastIndex(fileName, "\\")
@ -306,7 +289,7 @@ func (this *MatterController) Upload(writer http.ResponseWriter, request *http.R
fileName = fileName[pos+1:] 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) return this.Success(matter)
} }
@ -338,7 +321,7 @@ func (this *MatterController) Crawl(writer http.ResponseWriter, request *http.Re
privacy := false privacy := false
privacyStr := request.FormValue("privacy") privacyStr := request.FormValue("privacy")
if privacyStr == "true" { if privacyStr == TRUE {
privacy = true privacy = true
} }
@ -464,7 +447,7 @@ func (this *MatterController) ChangePrivacy(writer http.ResponseWriter, request
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
privacyStr := request.FormValue("privacy") privacyStr := request.FormValue("privacy")
privacy := false privacy := false
if privacyStr == "true" { if privacyStr == TRUE {
privacy = true privacy = true
} }
//找出该文件或者文件夹 //找出该文件或者文件夹

View File

@ -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 + "%"}}) 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}}) 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}}) wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{0}})
} }
if alien == "true" { if alien == TRUE {
wp = wp.And(&WherePair{Query: "alien = ?", Args: []interface{}{1}}) 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}}) wp = wp.And(&WherePair{Query: "alien = ?", Args: []interface{}{0}})
} }

View File

@ -2,6 +2,7 @@ package rest
const ( const (
MATTER_ROOT = "root" MATTER_ROOT = "root"
MATTER_CACHE = "cache"
) )
/** /**

View File

@ -68,9 +68,9 @@ func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http
preference.FaviconUrl = faviconUrl preference.FaviconUrl = faviconUrl
preference.FooterLine1 = footerLine1 preference.FooterLine1 = footerLine1
preference.FooterLine2 = footerLine2 preference.FooterLine2 = footerLine2
if showAlienStr == "true" { if showAlienStr == TRUE {
preference.ShowAlien = true preference.ShowAlien = true
} else if showAlienStr == "false" { } else if showAlienStr == FALSE {
preference.ShowAlien = false preference.ShowAlien = false
} }

View File

@ -158,7 +158,7 @@ func GetUserFileDir(username string, cache bool) (absolutePath string, relativeP
if cache { if cache {
//如果是缓存文件夹那么统一放在cache这个文件夹下面 //如果是缓存文件夹那么统一放在cache这个文件夹下面
firstDir := "cache" firstDir := MATTER_CACHE
now := time.Now() now := time.Now()
datePath := now.Format("2006-01-02") 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) relativePath = fmt.Sprintf("/%s/%s/%s/%d", username, firstDir, datePath, timestamp)
} else { } else {
firstDir := "root" firstDir := MATTER_ROOT
absolutePath = fmt.Sprintf("%s/%s/%s", filePath, username, firstDir) absolutePath = fmt.Sprintf("%s/%s/%s", filePath, username, firstDir)
relativePath = fmt.Sprintf("/%s/%s", username, firstDir) relativePath = fmt.Sprintf("/%s/%s", username, firstDir)
} }