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

@@ -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))