Finish the image cache preview things.
This commit is contained in:
parent
c371d9d5bd
commit
28b4227215
@ -125,10 +125,10 @@ func (this *AlienService) PreviewOrDownload(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//直接使用缓存中的信息
|
//直接使用缓存中的信息
|
||||||
this.matterService.DownloadFile(writer, request, CONFIG.MatterPath+imageCache.Path, matter.Name, withContentDisposition)
|
this.matterService.DownloadFile(writer, request, GetUserCacheRootDir(imageCache.Username)+imageCache.Path, imageCache.Name, withContentDisposition)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.matterService.DownloadFile(writer, request, CONFIG.MatterPath+matter.Path, matter.Name, withContentDisposition)
|
this.matterService.DownloadFile(writer, request, GetUserFileRootDir(matter.Username)+matter.Path, matter.Name, withContentDisposition)
|
||||||
}
|
}
|
||||||
|
|
||||||
//文件下载次数加一,为了加快访问速度,异步进行
|
//文件下载次数加一,为了加快访问速度,异步进行
|
||||||
|
@ -5,7 +5,9 @@ package rest
|
|||||||
*/
|
*/
|
||||||
type ImageCache struct {
|
type ImageCache struct {
|
||||||
Base
|
Base
|
||||||
|
Name string `json:"name" gorm:"type:varchar(255) not null"`
|
||||||
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
|
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
|
||||||
|
Username string `json:"username" gorm:"type:varchar(45) not null"`
|
||||||
MatterUuid string `json:"matterUuid" gorm:"type:char(36);index:idx_mu"`
|
MatterUuid string `json:"matterUuid" gorm:"type:char(36);index:idx_mu"`
|
||||||
Mode string `json:"mode" gorm:"type:varchar(512)"`
|
Mode string `json:"mode" gorm:"type:varchar(512)"`
|
||||||
Md5 string `json:"md5" gorm:"type:varchar(45)"`
|
Md5 string `json:"md5" gorm:"type:varchar(45)"`
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -194,11 +195,17 @@ func (this *ImageCacheService) cacheImage(writer http.ResponseWriter, request *h
|
|||||||
user := this.userDao.FindByUuid(matter.UserUuid)
|
user := this.userDao.FindByUuid(matter.UserUuid)
|
||||||
|
|
||||||
//resize图片
|
//resize图片
|
||||||
dstImage := this.ResizeImage(request, GetUserCacheRootDir(user.Username)+matter.Path)
|
dstImage := this.ResizeImage(request, GetUserFileRootDir(user.Username)+matter.Path)
|
||||||
|
|
||||||
cacheImagePath := GetSimpleFileName(matter.Path) + "_" + mode + extension
|
cacheImageName := GetSimpleFileName(matter.Name) + "_" + mode + extension
|
||||||
|
cacheImageRelativePath := GetSimpleFileName(matter.Path) + "_" + mode + extension
|
||||||
|
cacheImageAbsolutePath := GetUserCacheRootDir(user.Username) + GetSimpleFileName(matter.Path) + "_" + mode + extension
|
||||||
|
|
||||||
fileWriter, err := os.Create(cacheImagePath)
|
//创建目录。
|
||||||
|
dir := filepath.Dir(cacheImageAbsolutePath)
|
||||||
|
MakeDirAll(dir)
|
||||||
|
|
||||||
|
fileWriter, err := os.Create(cacheImageAbsolutePath)
|
||||||
this.PanicError(err)
|
this.PanicError(err)
|
||||||
defer func() {
|
defer func() {
|
||||||
e := fileWriter.Close()
|
e := fileWriter.Close()
|
||||||
@ -215,11 +222,13 @@ func (this *ImageCacheService) cacheImage(writer http.ResponseWriter, request *h
|
|||||||
|
|
||||||
//相关信息写到缓存中去
|
//相关信息写到缓存中去
|
||||||
imageCache := &ImageCache{
|
imageCache := &ImageCache{
|
||||||
|
Name: cacheImageName,
|
||||||
UserUuid: matter.UserUuid,
|
UserUuid: matter.UserUuid,
|
||||||
|
Username: user.Username,
|
||||||
MatterUuid: matter.Uuid,
|
MatterUuid: matter.Uuid,
|
||||||
Mode: mode,
|
Mode: mode,
|
||||||
Size: fileInfo.Size(),
|
Size: fileInfo.Size(),
|
||||||
Path: cacheImagePath,
|
Path: cacheImageRelativePath,
|
||||||
}
|
}
|
||||||
this.imageCacheDao.Create(imageCache)
|
this.imageCacheDao.Create(imageCache)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user