Feat: re-save shared folder to user's space

This commit is contained in:
HFO4
2020-01-31 11:27:52 +08:00
parent b1a9943b0c
commit f5d79b1f94
10 changed files with 51 additions and 60 deletions

View File

@@ -133,9 +133,9 @@ func (service *SingleFileService) CreateDocPreviewSession(ctx context.Context, c
fs.SetTargetFile(&[]model.File{*file})
}
// 如果上下文中已有Folder对象则重设目标
// 重设根目录
if folder, ok := ctx.Value(fsctx.FolderModelCtx).(*model.Folder); ok {
fs.SetTargetDir(&[]model.Folder{*folder})
fs.Root = folder
}
// 获取文件临时下载地址
@@ -233,9 +233,9 @@ func (service *SingleFileService) PreviewContent(ctx context.Context, c *gin.Con
fs.SetTargetFile(&[]model.File{*file})
}
// 如果上下文中已有Folder对象则重设目标
// 如果上下文中已有Folder对象则重设根目录
if folder, ok := ctx.Value(fsctx.FolderModelCtx).(*model.Folder); ok {
fs.SetTargetDir(&[]model.Folder{*folder})
fs.Root = folder
}
// 获取文件预览响应

View File

@@ -50,8 +50,8 @@ func (service *ShareGetService) Get(c *gin.Context) serializer.Response {
share.Viewed()
}
// 如果已经下载过,不需要付积分
if share.WasDownloadedBy(user, c) {
// 如果已经下载过或者是自己的分享,不需要付积分
if share.UserID == user.ID || share.WasDownloadedBy(user, c) {
share.Score = 0
}
@@ -81,6 +81,11 @@ func (service *ShareService) CreateDownloadSession(c *gin.Context) serializer.Re
return serializer.Err(serializer.CodePolicyNotAllowed, "源文件不存在", err)
}
// 重设根目录
if share.IsDir {
fs.Root = &fs.DirTarget[0]
}
// 取得下载地址
downloadURL, err := fs.GetDownloadURL(context.Background(), service.Path, "download_timeout")
if err != nil {
@@ -189,8 +194,8 @@ func (service *ShareService) List(c *gin.Context) serializer.Response {
defer cancel()
// 重设根目录
fs.SetTargetDir(&[]model.Folder{*share.GetSource().(*model.Folder)})
fs.DirTarget[0].Name = "/"
fs.Root = share.GetSource().(*model.Folder)
fs.Root.Name = "/"
// 分享Key上下文
ctx = context.WithValue(ctx, fsctx.ShareKeyCtx, hashid.HashID(share.ID, hashid.ShareID))