From 2027b2139c2c99611d294f740784599ddc0b7de7 Mon Sep 17 00:00:00 2001 From: zicla Date: Tue, 11 Dec 2018 01:36:53 +0800 Subject: [PATCH] Fix the Bug in IE browser. --- rest/matter_controller.go | 21 +++++++++++++++++++-- rest/matter_service.go | 1 + rest/router.go | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/rest/matter_controller.go b/rest/matter_controller.go index 3a56fe8..1162cb2 100644 --- a/rest/matter_controller.go +++ b/rest/matter_controller.go @@ -274,7 +274,18 @@ func (this *MatterController) Upload(writer http.ResponseWriter, request *http.R this.PanicError(err) defer file.Close() - matter := this.matterService.Upload(file, user, puuid, handler.Filename, privacy, alien) + //对于IE浏览器,filename可能包含了路径。 + fileName := handler.Filename + pos := strings.LastIndex(fileName, "\\") + if pos != -1 { + fileName = fileName[pos+1:] + } + pos = strings.LastIndex(fileName, "/") + if pos != -1 { + fileName = fileName[pos+1:] + } + + matter := this.matterService.Upload(file, user, puuid, fileName, privacy, alien) return this.Success(matter) } @@ -333,7 +344,7 @@ func (this *MatterController) Delete(writer http.ResponseWriter, request *http.R this.PanicBadRequest("文件的uuid必填") } - matter := this.matterDao.FindByUuid(uuid) + matter := this.matterDao.CheckByUuid(uuid) //判断文件的所属人是否正确 user := this.checkUser(writer, request) @@ -360,6 +371,12 @@ func (this *MatterController) DeleteBatch(writer http.ResponseWriter, request *h matter := this.matterDao.FindByUuid(uuid) + //如果matter已经是nil了,直接跳过 + if matter == nil { + this.logger.Warn("%s 对应的文件记录已经不存在了", uuid) + continue + } + //判断文件的所属人是否正确 user := this.checkUser(writer, request) if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid { diff --git a/rest/matter_service.go b/rest/matter_service.go index 8029deb..a6a9802 100644 --- a/rest/matter_service.go +++ b/rest/matter_service.go @@ -124,6 +124,7 @@ func (this *MatterService) Upload(file multipart.File, user *User, puuid string, panic("文件名不能超过200") } + //获取文件应该存放在的物理路径的绝对路径和相对路径。 absolutePath, relativePath := GetUserFilePath(user.Username, false) absolutePath = absolutePath + "/" + filename diff --git a/rest/router.go b/rest/router.go index e099bf7..c852627 100644 --- a/rest/router.go +++ b/rest/router.go @@ -122,6 +122,12 @@ func (this *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request) path := request.URL.Path if strings.HasPrefix(path, "/api") { + //对于IE浏览器,会自动缓存,因此设置不缓存Header. + writer.Header().Set("Pragma", "No-cache") + writer.Header().Set("Cache-Control", "no-cache") + writer.Header().Set("Expires", "0") + + if CONFIG.Installed { //已安装的模式