mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: download / preview files in slave side
This commit is contained in:
@@ -282,7 +282,7 @@ func (fs *FileSystem) signURL(ctx context.Context, file *model.File, ttl int64,
|
||||
// 签名最终URL
|
||||
// 生成外链地址
|
||||
siteURL := model.GetSiteURL()
|
||||
source, err := fs.Handler.Source(ctx, fs.FileTarget[0].SourceName, *siteURL, ttl, isDownload)
|
||||
source, err := fs.Handler.Source(ctx, fs.FileTarget[0].SourceName, *siteURL, ttl, isDownload, fs.User.Group.SpeedLimit)
|
||||
if err != nil {
|
||||
return "", serializer.NewError(serializer.CodeNotSet, "无法获取外链", err)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ type Handler interface {
|
||||
// 获取外链/下载地址,
|
||||
// url - 站点本身地址,
|
||||
// isDownload - 是否直接下载
|
||||
Source(ctx context.Context, path string, url url.URL, ttl int64, isDownload bool) (string, error)
|
||||
Source(ctx context.Context, path string, url url.URL, ttl int64, isDownload bool, speed int) (string, error)
|
||||
|
||||
// Token 获取有效期为ttl的上传凭证和签名,同时回调会话有效期为sessionTTL
|
||||
Token(ctx context.Context, ttl int64, callbackKey string) (serializer.UploadCredential, error)
|
||||
|
||||
@@ -117,6 +117,7 @@ func (handler Handler) Source(
|
||||
baseURL url.URL,
|
||||
ttl int64,
|
||||
isDownload bool,
|
||||
speed int,
|
||||
) (string, error) {
|
||||
file, ok := ctx.Value(fsctx.FileModelCtx).(model.File)
|
||||
if !ok {
|
||||
|
||||
@@ -52,6 +52,7 @@ func (handler Handler) Source(
|
||||
baseURL url.URL,
|
||||
ttl int64,
|
||||
isDownload bool,
|
||||
speed int,
|
||||
) (string, error) {
|
||||
file, ok := ctx.Value(fsctx.FileModelCtx).(model.File)
|
||||
if !ok {
|
||||
@@ -80,7 +81,7 @@ func (handler Handler) Source(
|
||||
authInstance := auth.HMACAuth{SecretKey: []byte(handler.Policy.SecretKey)}
|
||||
signedURI, err = auth.SignURI(
|
||||
authInstance,
|
||||
fmt.Sprintf("%s/%s", controller, sourcePath),
|
||||
fmt.Sprintf("%s/%d/%s/%s", controller, speed, sourcePath, file.Name),
|
||||
expires,
|
||||
)
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ func (m FileHeaderMock) Thumb(ctx context.Context, files string) (*response.Cont
|
||||
return args.Get(0).(*response.ContentResponse), args.Error(1)
|
||||
}
|
||||
|
||||
func (m FileHeaderMock) Source(ctx context.Context, path string, url url.URL, expires int64, isDownload bool) (string, error) {
|
||||
args := m.Called(ctx, path, url, expires, isDownload)
|
||||
func (m FileHeaderMock) Source(ctx context.Context, path string, url url.URL, expires int64, isDownload bool, speed int) (string, error) {
|
||||
args := m.Called(ctx, path, url, expires, isDownload, speed)
|
||||
return args.Get(0).(string), args.Error(1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user