Ready to add the preview feature.
This commit is contained in:
@ -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)
|
||||
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user