mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Modify: change raw object ID to Hash ID in file service
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// ShareCreateService 创建新分享服务
|
||||
type ShareCreateService struct {
|
||||
SourceID uint `json:"id" binding:"required"`
|
||||
SourceID string `json:"id" binding:"required"`
|
||||
IsDir bool `json:"is_dir"`
|
||||
Password string `json:"password" binding:"max=255"`
|
||||
RemainDownloads int `json:"downloads"`
|
||||
@@ -30,15 +30,29 @@ func (service *ShareCreateService) Create(c *gin.Context) serializer.Response {
|
||||
return serializer.Err(serializer.CodeNoPermissionErr, "您无权创建分享链接", nil)
|
||||
}
|
||||
|
||||
// 源对象真实ID
|
||||
var (
|
||||
sourceID uint
|
||||
err error
|
||||
)
|
||||
if service.IsDir {
|
||||
sourceID, err = hashid.DecodeHashID(service.SourceID, hashid.FolderID)
|
||||
} else {
|
||||
sourceID, err = hashid.DecodeHashID(service.SourceID, hashid.FileID)
|
||||
}
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotFound, "原始资源不存在", nil)
|
||||
}
|
||||
|
||||
// 对象是否存在
|
||||
exist := true
|
||||
if service.IsDir {
|
||||
folder, err := model.GetFoldersByIDs([]uint{service.SourceID}, user.ID)
|
||||
folder, err := model.GetFoldersByIDs([]uint{sourceID}, user.ID)
|
||||
if err != nil || len(folder) == 0 {
|
||||
exist = false
|
||||
}
|
||||
} else {
|
||||
file, err := model.GetFilesByIDs([]uint{service.SourceID}, user.ID)
|
||||
file, err := model.GetFilesByIDs([]uint{sourceID}, user.ID)
|
||||
if err != nil || len(file) == 0 {
|
||||
exist = false
|
||||
}
|
||||
@@ -51,7 +65,7 @@ func (service *ShareCreateService) Create(c *gin.Context) serializer.Response {
|
||||
Password: service.Password,
|
||||
IsDir: service.IsDir,
|
||||
UserID: user.ID,
|
||||
SourceID: service.SourceID,
|
||||
SourceID: sourceID,
|
||||
Score: service.Score,
|
||||
RemainDownloads: -1,
|
||||
PreviewEnabled: service.Preview,
|
||||
|
||||
@@ -96,7 +96,8 @@ func (service *Service) CreateDownloadSession(c *gin.Context) serializer.Respons
|
||||
}
|
||||
|
||||
// 取得下载地址
|
||||
downloadURL, err := fs.GetDownloadURL(context.Background(), service.Path, "download_timeout")
|
||||
// TODO 改为真实ID
|
||||
downloadURL, err := fs.GetDownloadURL(context.Background(), 0, "download_timeout")
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
||||
}
|
||||
@@ -119,9 +120,7 @@ func (service *Service) PreviewContent(ctx context.Context, c *gin.Context, isTe
|
||||
} else {
|
||||
ctx = context.WithValue(ctx, fsctx.FileModelCtx, share.Source())
|
||||
}
|
||||
subService := explorer.SingleFileService{
|
||||
Path: service.Path,
|
||||
}
|
||||
subService := explorer.FileIDService{}
|
||||
|
||||
return subService.PreviewContent(ctx, c, isText)
|
||||
}
|
||||
@@ -138,9 +137,7 @@ func (service *Service) CreateDocPreviewSession(c *gin.Context) serializer.Respo
|
||||
} else {
|
||||
ctx = context.WithValue(ctx, fsctx.FileModelCtx, share.Source())
|
||||
}
|
||||
subService := explorer.SingleFileService{
|
||||
Path: service.Path,
|
||||
}
|
||||
subService := explorer.FileIDService{}
|
||||
|
||||
return subService.CreateDocPreviewSession(ctx, c)
|
||||
}
|
||||
@@ -321,10 +318,8 @@ func (service *ArchiveService) Archive(c *gin.Context) serializer.Response {
|
||||
tempUser.Group.OptionsSerialized.ArchiveDownload = true
|
||||
c.Set("user", tempUser)
|
||||
|
||||
subService := explorer.ItemService{
|
||||
Items: service.Items,
|
||||
Dirs: service.Dirs,
|
||||
}
|
||||
// todo 改成真实
|
||||
subService := explorer.ItemIDService{}
|
||||
|
||||
return subService.Archive(ctx, c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user