pull/2116/merge
Darren Yu 11 months ago committed by GitHub
commit 701b142ab0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -26,6 +26,6 @@ jobs:
with: with:
distribution: goreleaser distribution: goreleaser
version: latest version: latest
args: release --clean --skip-validate args: release --clean
env: env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}

@ -4,7 +4,6 @@ env:
before: before:
hooks: hooks:
- go mod tidy - go mod tidy
- sh -c "cd assets && rm -rf build && yarn install --network-timeout 1000000 && yarn run build && cd ../ && zip -r - assets/build >assets.zip"
builds: builds:
- -
env: env:
@ -58,64 +57,3 @@ changelog:
exclude: exclude:
- '^docs:' - '^docs:'
- '^test:' - '^test:'
release:
draft: true
prerelease: auto
target_commitish: '{{ .Commit }}'
name_template: "{{.Version}}"
dockers:
-
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
goos: linux
goarch: amd64
goamd64: v1
image_templates:
- "cloudreve/cloudreve:{{ .Tag }}-amd64"
-
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--platform=linux/arm64"
goos: linux
goarch: arm64
image_templates:
- "cloudreve/cloudreve:{{ .Tag }}-arm64"
-
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--platform=linux/arm/v6"
goos: linux
goarch: arm
goarm: '6'
image_templates:
- "cloudreve/cloudreve:{{ .Tag }}-armv6"
-
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--platform=linux/arm/v7"
goos: linux
goarch: arm
goarm: '7'
image_templates:
- "cloudreve/cloudreve:{{ .Tag }}-armv7"
docker_manifests:
- name_template: "cloudreve/cloudreve:latest"
image_templates:
- "cloudreve/cloudreve:{{ .Tag }}-amd64"
- "cloudreve/cloudreve:{{ .Tag }}-arm64"
- "cloudreve/cloudreve:{{ .Tag }}-armv6"
- "cloudreve/cloudreve:{{ .Tag }}-armv7"
- name_template: "cloudreve/cloudreve:{{ .Tag }}"
image_templates:
- "cloudreve/cloudreve:{{ .Tag }}-amd64"
- "cloudreve/cloudreve:{{ .Tag }}-arm64"
- "cloudreve/cloudreve:{{ .Tag }}-armv6"
- "cloudreve/cloudreve:{{ .Tag }}-armv7"

Binary file not shown.

@ -148,9 +148,9 @@ func (handler Driver) CORS() error {
} }
// Get 获取文件 // Get 获取文件
func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser, error) { func (handler Driver) Get(ctx context.Context, objectPath string) (response.RSCloser, error) {
// 获取文件源地址 // 获取文件源地址
downloadURL, err := handler.Source(ctx, path, int64(model.GetIntSetting("preview_timeout", 60)), false, 0) downloadURL, err := handler.Source(ctx, objectPath, int64(model.GetIntSetting("preview_timeout", 60)), false, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -263,7 +263,7 @@ func (handler Driver) Thumb(ctx context.Context, file *model.File) (*response.Co
} }
// Source 获取外链URL // Source 获取外链URL
func (handler Driver) Source(ctx context.Context, path string, ttl int64, isDownload bool, speed int) (string, error) { func (handler Driver) Source(ctx context.Context, objectPath string, ttl int64, isDownload bool, speed int) (string, error) {
// 尝试从上下文获取文件名 // 尝试从上下文获取文件名
fileName := "" fileName := ""
if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok { if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok {
@ -285,10 +285,10 @@ func (handler Driver) Source(ctx context.Context, path string, ttl int64, isDown
options.ContentDescription = "attachment; filename=\"" + url.PathEscape(fileName) + "\"" options.ContentDescription = "attachment; filename=\"" + url.PathEscape(fileName) + "\""
} }
return handler.signSourceURL(ctx, path, ttl, &options) return handler.signSourceURL(ctx, objectPath, ttl, &options)
} }
func (handler Driver) signSourceURL(ctx context.Context, path string, ttl int64, options *urlOption) (string, error) { func (handler Driver) signSourceURL(ctx context.Context, objectPath string, ttl int64, options *urlOption) (string, error) {
cdnURL, err := url.Parse(handler.Policy.BaseURL) cdnURL, err := url.Parse(handler.Policy.BaseURL)
if err != nil { if err != nil {
return "", err return "", err
@ -296,7 +296,7 @@ func (handler Driver) signSourceURL(ctx context.Context, path string, ttl int64,
// 公有空间不需要签名 // 公有空间不需要签名
if !handler.Policy.IsPrivate { if !handler.Policy.IsPrivate {
file, err := url.Parse(path) file, err := url.Parse(objectPath)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -314,7 +314,7 @@ func (handler Driver) signSourceURL(ctx context.Context, path string, ttl int64,
return sourceURL.String(), nil return sourceURL.String(), nil
} }
presignedURL, err := handler.Client.Object.GetPresignedURL(ctx, http.MethodGet, path, presignedURL, err := handler.Client.Object.GetPresignedURL(ctx, http.MethodGet, objectPath,
handler.Policy.AccessKey, handler.Policy.SecretKey, time.Duration(ttl)*time.Second, options) handler.Policy.AccessKey, handler.Policy.SecretKey, time.Duration(ttl)*time.Second, options)
if err != nil { if err != nil {
return "", err return "", err
@ -324,6 +324,10 @@ func (handler Driver) signSourceURL(ctx context.Context, path string, ttl int64,
presignedURL.Host = cdnURL.Host presignedURL.Host = cdnURL.Host
presignedURL.Scheme = cdnURL.Scheme presignedURL.Scheme = cdnURL.Scheme
// 支持代理域名使用子目录
// Support sub-directories for proxy domain
presignedURL.Path = path.Join(cdnURL.Path, presignedURL.Path)
return presignedURL.String(), nil return presignedURL.String(), nil
} }
@ -374,8 +378,8 @@ func (handler Driver) CancelToken(ctx context.Context, uploadSession *serializer
} }
// Meta 获取文件信息 // Meta 获取文件信息
func (handler Driver) Meta(ctx context.Context, path string) (*MetaData, error) { func (handler Driver) Meta(ctx context.Context, objectPath string) (*MetaData, error) {
res, err := handler.Client.Object.Head(ctx, path, &cossdk.ObjectHeadOptions{}) res, err := handler.Client.Object.Head(ctx, objectPath, &cossdk.ObjectHeadOptions{})
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -7,6 +7,7 @@ import (
"io" "io"
"net/url" "net/url"
"os" "os"
"path"
"path/filepath" "path/filepath"
model "github.com/cloudreve/Cloudreve/v3/models" model "github.com/cloudreve/Cloudreve/v3/models"
@ -76,9 +77,9 @@ func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]
} }
// Get 获取文件内容 // Get 获取文件内容
func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser, error) { func (handler Driver) Get(ctx context.Context, objectPath string) (response.RSCloser, error) {
// 打开文件 // 打开文件
file, err := os.Open(util.RelativePath(path)) file, err := os.Open(util.RelativePath(objectPath))
if err != nil { if err != nil {
util.Log().Debug("Failed to open file: %s", err) util.Log().Debug("Failed to open file: %s", err)
return nil, err return nil, err
@ -219,7 +220,7 @@ func (handler Driver) Thumb(ctx context.Context, file *model.File) (*response.Co
} }
// Source 获取外链URL // Source 获取外链URL
func (handler Driver) Source(ctx context.Context, path string, ttl int64, isDownload bool, speed int) (string, error) { func (handler Driver) Source(ctx context.Context, objectPath string, ttl int64, isDownload bool, speed int) (string, error) {
file, ok := ctx.Value(fsctx.FileModelCtx).(model.File) file, ok := ctx.Value(fsctx.FileModelCtx).(model.File)
if !ok { if !ok {
return "", errors.New("failed to read file model context") return "", errors.New("failed to read file model context")
@ -268,7 +269,11 @@ func (handler Driver) Source(ctx context.Context, path string, ttl int64, isDown
finalURL := signedURI.String() finalURL := signedURI.String()
if baseURL != nil { if baseURL != nil {
finalURL = baseURL.ResolveReference(signedURI).String() // 支持代理域名使用子目录
// Support sub-directories for proxy domain
baseURL.Path = path.Join(baseURL.Path, signedURI.Path)
baseURL.RawQuery = signedURI.RawQuery
finalURL = baseURL.String()
} }
return finalURL, nil return finalURL, nil

@ -86,11 +86,11 @@ func (handler Driver) List(ctx context.Context, base string, recursive bool) ([]
} }
// Get 获取文件 // Get 获取文件
func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser, error) { func (handler Driver) Get(ctx context.Context, objectPath string) (response.RSCloser, error) {
// 获取文件源地址 // 获取文件源地址
downloadURL, err := handler.Source( downloadURL, err := handler.Source(
ctx, ctx,
path, objectPath,
60, 60,
false, false,
0, 0,
@ -162,12 +162,12 @@ func (handler Driver) Thumb(ctx context.Context, file *model.File) (*response.Co
// Source 获取外链URL // Source 获取外链URL
func (handler Driver) Source( func (handler Driver) Source(
ctx context.Context, ctx context.Context,
path string, objectPath string,
ttl int64, ttl int64,
isDownload bool, isDownload bool,
speed int, speed int,
) (string, error) { ) (string, error) {
cacheKey := fmt.Sprintf("onedrive_source_%d_%s", handler.Policy.ID, path) cacheKey := fmt.Sprintf("onedrive_source_%d_%s", handler.Policy.ID, objectPath)
if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok { if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok {
cacheKey = fmt.Sprintf("onedrive_source_file_%d_%d", file.UpdatedAt.Unix(), file.ID) cacheKey = fmt.Sprintf("onedrive_source_file_%d_%d", file.UpdatedAt.Unix(), file.ID)
} }
@ -178,7 +178,7 @@ func (handler Driver) Source(
} }
// 缓存不存在,重新获取 // 缓存不存在,重新获取
res, err := handler.Client.Meta(ctx, "", path) res, err := handler.Client.Meta(ctx, "", objectPath)
if err == nil { if err == nil {
// 写入新的缓存 // 写入新的缓存
cache.Set( cache.Set(
@ -206,6 +206,11 @@ func (handler Driver) replaceSourceHost(origin string) (string, error) {
// 替换反代地址 // 替换反代地址
source.Scheme = cdn.Scheme source.Scheme = cdn.Scheme
source.Host = cdn.Host source.Host = cdn.Host
// 支持代理域名使用子目录
// Support sub-directories for proxy domain
source.Path = path.Join(cdn.Path, source.Path)
return source.String(), nil return source.String(), nil
} }

@ -186,7 +186,7 @@ func (handler *Driver) List(ctx context.Context, base string, recursive bool) ([
} }
// Get 获取文件 // Get 获取文件
func (handler *Driver) Get(ctx context.Context, path string) (response.RSCloser, error) { func (handler *Driver) Get(ctx context.Context, objectPath string) (response.RSCloser, error) {
// 通过VersionID禁止缓存 // 通过VersionID禁止缓存
ctx = context.WithValue(ctx, VersionID, time.Now().UnixNano()) ctx = context.WithValue(ctx, VersionID, time.Now().UnixNano())
@ -194,7 +194,7 @@ func (handler *Driver) Get(ctx context.Context, path string) (response.RSCloser,
ctx = context.WithValue(ctx, fsctx.ForceUsePublicEndpointCtx, false) ctx = context.WithValue(ctx, fsctx.ForceUsePublicEndpointCtx, false)
// 获取文件源地址 // 获取文件源地址
downloadURL, err := handler.Source(ctx, path, int64(model.GetIntSetting("preview_timeout", 60)), false, 0) downloadURL, err := handler.Source(ctx, objectPath, int64(model.GetIntSetting("preview_timeout", 60)), false, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -334,7 +334,7 @@ func (handler *Driver) Thumb(ctx context.Context, file *model.File) (*response.C
} }
// Source 获取外链URL // Source 获取外链URL
func (handler *Driver) Source(ctx context.Context, path string, ttl int64, isDownload bool, speed int) (string, error) { func (handler *Driver) Source(ctx context.Context, objectPath string, ttl int64, isDownload bool, speed int) (string, error) {
// 初始化客户端 // 初始化客户端
usePublicEndpoint := true usePublicEndpoint := true
if forceUsePublicEndpoint, ok := ctx.Value(fsctx.ForceUsePublicEndpointCtx).(bool); ok { if forceUsePublicEndpoint, ok := ctx.Value(fsctx.ForceUsePublicEndpointCtx).(bool); ok {
@ -369,11 +369,11 @@ func (handler *Driver) Source(ctx context.Context, path string, ttl int64, isDow
signOptions = append(signOptions, oss.TrafficLimitParam(int64(speed))) signOptions = append(signOptions, oss.TrafficLimitParam(int64(speed)))
} }
return handler.signSourceURL(ctx, path, ttl, signOptions) return handler.signSourceURL(ctx, objectPath, ttl, signOptions)
} }
func (handler *Driver) signSourceURL(ctx context.Context, path string, ttl int64, options []oss.Option) (string, error) { func (handler *Driver) signSourceURL(ctx context.Context, objectPath string, ttl int64, options []oss.Option) (string, error) {
signedURL, err := handler.bucket.SignURL(path, oss.HTTPGet, ttl, options...) signedURL, err := handler.bucket.SignURL(objectPath, oss.HTTPGet, ttl, options...)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -401,6 +401,10 @@ func (handler *Driver) signSourceURL(ctx context.Context, path string, ttl int64
} }
finalURL.Host = cdnURL.Host finalURL.Host = cdnURL.Host
finalURL.Scheme = cdnURL.Scheme finalURL.Scheme = cdnURL.Scheme
// 支持代理域名使用子目录
// Support sub-directories for proxy domain
finalURL.Path = path.Join(cdnURL.Path, finalURL.Path)
} }
return finalURL.String(), nil return finalURL.String(), nil

@ -116,7 +116,7 @@ func (handler *Driver) getAPIUrl(scope string, routes ...string) string {
} }
// Get 获取文件内容 // Get 获取文件内容
func (handler *Driver) Get(ctx context.Context, path string) (response.RSCloser, error) { func (handler *Driver) Get(ctx context.Context, objectPath string) (response.RSCloser, error) {
// 尝试获取速度限制 // 尝试获取速度限制
speedLimit := 0 speedLimit := 0
if user, ok := ctx.Value(fsctx.UserCtx).(model.User); ok { if user, ok := ctx.Value(fsctx.UserCtx).(model.User); ok {
@ -124,7 +124,7 @@ func (handler *Driver) Get(ctx context.Context, path string) (response.RSCloser,
} }
// 获取文件源地址 // 获取文件源地址
downloadURL, err := handler.Source(ctx, path, 0, true, speedLimit) downloadURL, err := handler.Source(ctx, objectPath, 0, true, speedLimit)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -233,7 +233,7 @@ func (handler *Driver) Thumb(ctx context.Context, file *model.File) (*response.C
} }
// Source 获取外链URL // Source 获取外链URL
func (handler *Driver) Source(ctx context.Context, path string, ttl int64, isDownload bool, speed int) (string, error) { func (handler *Driver) Source(ctx context.Context, objectPath string, ttl int64, isDownload bool, speed int) (string, error) {
// 尝试从上下文获取文件名 // 尝试从上下文获取文件名
fileName := "file" fileName := "file"
if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok { if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok {
@ -263,7 +263,7 @@ func (handler *Driver) Source(ctx context.Context, path string, ttl int64, isDow
} }
// 签名下载地址 // 签名下载地址
sourcePath := base64.RawURLEncoding.EncodeToString([]byte(path)) sourcePath := base64.RawURLEncoding.EncodeToString([]byte(objectPath))
signedURI, err = auth.SignURI( signedURI, err = auth.SignURI(
handler.AuthInstance, handler.AuthInstance,
fmt.Sprintf("%s/%d/%s/%s", controller, speed, sourcePath, url.PathEscape(fileName)), fmt.Sprintf("%s/%d/%s/%s", controller, speed, sourcePath, url.PathEscape(fileName)),
@ -274,9 +274,12 @@ func (handler *Driver) Source(ctx context.Context, path string, ttl int64, isDow
return "", serializer.NewError(serializer.CodeEncryptError, "Failed to sign URL", err) return "", serializer.NewError(serializer.CodeEncryptError, "Failed to sign URL", err)
} }
finalURL := serverURL.ResolveReference(signedURI).String() // 支持代理域名使用子目录
return finalURL, nil // Support sub-directories for proxy domain
serverURL.Path = path.Join(serverURL.Path, signedURI.Path)
serverURL.RawQuery = signedURI.RawQuery
return serverURL.String(), nil
} }
// Token 获取上传策略和认证Token // Token 获取上传策略和认证Token

Loading…
Cancel
Save