|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/auth"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"path"
|
|
|
|
"path"
|
|
|
@ -152,6 +153,26 @@ func (handler Driver) Source(
|
|
|
|
isDownload bool,
|
|
|
|
isDownload bool,
|
|
|
|
speed int,
|
|
|
|
speed int,
|
|
|
|
) (string, error) {
|
|
|
|
) (string, error) {
|
|
|
|
|
|
|
|
file, ok := ctx.Value(fsctx.FileModelCtx).(model.File)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
return "", errors.New("无法获取文件记录上下文")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !isDownload {
|
|
|
|
|
|
|
|
// 签名生成文件记录
|
|
|
|
|
|
|
|
signedURI, err := auth.SignURI(
|
|
|
|
|
|
|
|
auth.General,
|
|
|
|
|
|
|
|
fmt.Sprintf("/api/v3/file/get/%d/%s", file.ID, file.Name),
|
|
|
|
|
|
|
|
ttl,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", serializer.NewError(serializer.CodeEncryptError, "无法对URL进行签名", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
finalURL := baseURL.ResolveReference(signedURI).String()
|
|
|
|
|
|
|
|
return finalURL, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 尝试从缓存中查找
|
|
|
|
// 尝试从缓存中查找
|
|
|
|
if cachedURL, ok := cache.Get(fmt.Sprintf("onedrive_source_%d_%s", handler.Policy.ID, path)); ok {
|
|
|
|
if cachedURL, ok := cache.Get(fmt.Sprintf("onedrive_source_%d_%s", handler.Policy.ID, path)); ok {
|
|
|
|
return handler.replaceSourceHost(cachedURL.(string))
|
|
|
|
return handler.replaceSourceHost(cachedURL.(string))
|
|
|
|