From 8cede9c087471e41fa14f78af6165a787141f891 Mon Sep 17 00:00:00 2001 From: zicla Date: Mon, 26 Nov 2018 18:12:42 +0800 Subject: [PATCH] Ready to add the preview feature. --- rest/image_cache_controller.go | 20 ++++++++++---------- rest/image_cache_dao.go | 2 +- rest/matter_service.go | 15 +++++++-------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/rest/image_cache_controller.go b/rest/image_cache_controller.go index 0a430df..2bb7493 100644 --- a/rest/image_cache_controller.go +++ b/rest/image_cache_controller.go @@ -43,12 +43,12 @@ func (this *ImageCacheController) RegisterRoutes() map[string]func(writer http.R return routeMap } -//查看某个文件的详情。 +//查看某个图片缓存的详情。 func (this *ImageCacheController) Detail(writer http.ResponseWriter, request *http.Request) *WebResult { uuid := request.FormValue("uuid") if uuid == "" { - return this.Error("文件的uuid必填") + return this.Error("图片缓存的uuid必填") } imageCache := this.imageCacheService.Detail(uuid) @@ -57,7 +57,7 @@ func (this *ImageCacheController) Detail(writer http.ResponseWriter, request *ht user := this.checkUser(writer, request) if user.Role != USER_ROLE_ADMINISTRATOR { if imageCache.UserUuid != user.Uuid { - panic("没有权限查看该文件") + panic("没有权限查看该图片缓存") } } @@ -65,7 +65,7 @@ func (this *ImageCacheController) Detail(writer http.ResponseWriter, request *ht } -//按照分页的方式获取某个文件夹下文件和子文件夹的列表,通常情况下只有一页。 +//按照分页的方式获取某个图片缓存夹下图片缓存和子图片缓存夹的列表,通常情况下只有一页。 func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http.Request) *WebResult { //如果是根目录,那么就传入root. @@ -110,17 +110,17 @@ func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http return this.Success(pager) } -//删除一个文件 +//删除一个图片缓存 func (this *ImageCacheController) Delete(writer http.ResponseWriter, request *http.Request) *WebResult { uuid := request.FormValue("uuid") if uuid == "" { - return this.Error("文件的uuid必填") + return this.Error("图片缓存的uuid必填") } imageCache := this.imageCacheDao.FindByUuid(uuid) - //判断文件的所属人是否正确 + //判断图片缓存的所属人是否正确 user := this.checkUser(writer, request) if user.Role != USER_ROLE_ADMINISTRATOR && imageCache.UserUuid != user.Uuid { return this.Error(CODE_WRAPPER_UNAUTHORIZED) @@ -131,12 +131,12 @@ func (this *ImageCacheController) Delete(writer http.ResponseWriter, request *ht return this.Success("删除成功!") } -//删除一系列文件。 +//删除一系列图片缓存。 func (this *ImageCacheController) DeleteBatch(writer http.ResponseWriter, request *http.Request) *WebResult { uuids := request.FormValue("uuids") if uuids == "" { - return this.Error("文件的uuids必填") + return this.Error("图片缓存的uuids必填") } uuidArray := strings.Split(uuids, ",") @@ -145,7 +145,7 @@ func (this *ImageCacheController) DeleteBatch(writer http.ResponseWriter, reques imageCache := this.imageCacheDao.FindByUuid(uuid) - //判断文件的所属人是否正确 + //判断图片缓存的所属人是否正确 user := this.checkUser(writer, request) if user.Role != USER_ROLE_ADMINISTRATOR && imageCache.UserUuid != user.Uuid { return this.Error(CODE_WRAPPER_UNAUTHORIZED) diff --git a/rest/image_cache_dao.go b/rest/image_cache_dao.go index 7380d71..2fa3b90 100644 --- a/rest/image_cache_dao.go +++ b/rest/image_cache_dao.go @@ -140,7 +140,7 @@ func (this *ImageCacheDao) Delete(imageCache *ImageCache) { err := os.Remove(CONFIG.MatterPath + imageCache.Path) if err != nil { - LogError(fmt.Sprintf("删除磁盘上的文件出错,不做任何处理")) + LogError(fmt.Sprintf("删除磁盘上的文件出错,不做任何处理 %s", err.Error())) } } diff --git a/rest/matter_service.go b/rest/matter_service.go index 1f9c156..a2b1e63 100644 --- a/rest/matter_service.go +++ b/rest/matter_service.go @@ -8,7 +8,6 @@ import ( "mime/multipart" "net/http" "net/textproto" - "net/url" "os" "path/filepath" "regexp" @@ -439,13 +438,13 @@ func (this *MatterService) DownloadFile(writer http.ResponseWriter, request *htt defer diskFile.Close() //如果是图片或者文本或者视频就直接打开。其余的一律以下载形式返回。 - fileName := url.QueryEscape(filename) - mimeType := GetMimeType(fileName) - if strings.Index(mimeType, "image") != 0 && - strings.Index(mimeType, "text") != 0 && - strings.Index(mimeType, "video") != 0 { - writer.Header().Set("content-disposition", "attachment; filename=\""+fileName+"\"") - } + //fileName := url.QueryEscape(filename) + //mimeType := GetMimeType(fileName) + //if strings.Index(mimeType, "image") != 0 && + // strings.Index(mimeType, "text") != 0 && + // strings.Index(mimeType, "video") != 0 { + // writer.Header().Set("content-disposition", "attachment; filename=\""+fileName+"\"") + //} //显示文件大小。 fileInfo, err := diskFile.Stat()