Feat: download / preview files in slave side

This commit is contained in:
HFO4
2019-12-31 14:21:57 +08:00
parent 35c2a5c977
commit b19910867e
8 changed files with 107 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

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