Compare commits
13 Commits
440ab775b8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8db5ab056 | ||
|
|
fe76d14835 | ||
| 4f0511bdfe | |||
|
|
21cdafb2af | ||
|
|
e29237d593 | ||
|
|
46897e2880 | ||
|
|
213eaa54dd | ||
|
|
e7d6fb25e4 | ||
|
|
e3e08a9b75 | ||
|
|
78f7ec8b08 | ||
|
|
3d41e00384 | ||
|
|
5e5dca40c4 | ||
|
|
668b542c59 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "assets"]
|
[submodule "assets"]
|
||||||
path = assets
|
path = assets
|
||||||
url = https://github.com/cloudreve/frontend.git
|
url = http://leonmmcoset.jjxmm.win:2000/MiaoStars/cloudreve-assets.git
|
||||||
|
|||||||
@@ -467,7 +467,7 @@ func (d *dependency) MediaMetaExtractor(ctx context.Context) mediameta.Extractor
|
|||||||
return d.mediaMeta
|
return d.mediaMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
d.mediaMeta = mediameta.NewExtractorManager(ctx, d.SettingProvider(), d.Logger())
|
d.mediaMeta = mediameta.NewExtractorManager(ctx, d.SettingProvider(), d.Logger(), d.RequestClient())
|
||||||
return d.mediaMeta
|
return d.mediaMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
assets
2
assets
Submodule assets updated: dece1c7098...921570f229
@@ -5,7 +5,7 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- postgresql
|
- postgresql
|
||||||
- redis
|
- redis
|
||||||
restart: always
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- 5212:5212
|
- 5212:5212
|
||||||
- 6888:6888
|
- 6888:6888
|
||||||
@@ -26,6 +26,7 @@ services:
|
|||||||
# backup & consult https://www.postgresql.org/docs/current/pgupgrade.html
|
# backup & consult https://www.postgresql.org/docs/current/pgupgrade.html
|
||||||
image: postgres:17
|
image: postgres:17
|
||||||
container_name: postgresql
|
container_name: postgresql
|
||||||
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=cloudreve
|
- POSTGRES_USER=cloudreve
|
||||||
- POSTGRES_DB=cloudreve
|
- POSTGRES_DB=cloudreve
|
||||||
@@ -36,6 +37,7 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
container_name: redis
|
container_name: redis
|
||||||
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- redis_data:/data
|
- redis_data:/data
|
||||||
|
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -6,8 +6,9 @@ require (
|
|||||||
entgo.io/ent v0.13.0
|
entgo.io/ent v0.13.0
|
||||||
github.com/Masterminds/semver/v3 v3.3.1
|
github.com/Masterminds/semver/v3 v3.3.1
|
||||||
github.com/abslant/gzip v0.0.9
|
github.com/abslant/gzip v0.0.9
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
github.com/aliyun/alibabacloud-oss-go-sdk-v2 v1.3.0
|
||||||
github.com/aws/aws-sdk-go v1.31.5
|
github.com/aws/aws-sdk-go v1.31.5
|
||||||
|
github.com/bodgit/sevenzip v1.6.0
|
||||||
github.com/cloudflare/cfssl v1.6.1
|
github.com/cloudflare/cfssl v1.6.1
|
||||||
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
|
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
|
||||||
github.com/dsoprea/go-exif/v3 v3.0.1
|
github.com/dsoprea/go-exif/v3 v3.0.1
|
||||||
@@ -70,7 +71,6 @@ require (
|
|||||||
github.com/andybalholm/brotli v1.1.2-0.20250424173009-453214e765f3 // indirect
|
github.com/andybalholm/brotli v1.1.2-0.20250424173009-453214e765f3 // indirect
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||||
github.com/bodgit/plumbing v1.3.0 // indirect
|
github.com/bodgit/plumbing v1.3.0 // indirect
|
||||||
github.com/bodgit/sevenzip v1.6.0 // indirect
|
|
||||||
github.com/bodgit/windows v1.0.1 // indirect
|
github.com/bodgit/windows v1.0.1 // indirect
|
||||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
|
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
|
||||||
github.com/bytedance/sonic v1.11.6 // indirect
|
github.com/bytedance/sonic v1.11.6 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -100,8 +100,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
|
|||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
|
github.com/aliyun/alibabacloud-oss-go-sdk-v2 v1.3.0 h1:wQlqotpyjYPjJz+Noh5bRu7Snmydk8SKC5Z6u1CR20Y=
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
|
github.com/aliyun/alibabacloud-oss-go-sdk-v2 v1.3.0/go.mod h1:FTzydeQVmR24FI0D6XWUOMKckjXehM/jgMn1xC+DA9M=
|
||||||
github.com/andybalholm/brotli v1.1.2-0.20250424173009-453214e765f3 h1:8PmGpDEZl9yDpcdEr6Odf23feCxK3LNUNMxjXg41pZQ=
|
github.com/andybalholm/brotli v1.1.2-0.20250424173009-453214e765f3 h1:8PmGpDEZl9yDpcdEr6Odf23feCxK3LNUNMxjXg41pZQ=
|
||||||
github.com/andybalholm/brotli v1.1.2-0.20250424173009-453214e765f3/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
github.com/andybalholm/brotli v1.1.2-0.20250424173009-453214e765f3/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -180,9 +180,9 @@ func SlaveFileContentUrl(base *url.URL, srcPath, name string, download bool, spe
|
|||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
|
|
||||||
func SlaveMediaMetaRoute(src, ext string) string {
|
func SlaveMediaMetaRoute(src, ext, language string) string {
|
||||||
src = url.PathEscape(base64.URLEncoding.EncodeToString([]byte(src)))
|
src = url.PathEscape(base64.URLEncoding.EncodeToString([]byte(src)))
|
||||||
return fmt.Sprintf("file/meta/%s/%s", src, url.PathEscape(ext))
|
return fmt.Sprintf("file/meta/%s/%s?language=%s", src, url.PathEscape(ext), language)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SlaveFileListRoute(srcPath string, recursive bool) string {
|
func SlaveFileListRoute(srcPath string, recursive bool) string {
|
||||||
|
|||||||
@@ -594,7 +594,7 @@ func (handler Driver) Meta(ctx context.Context, path string) (*MetaData, error)
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
if util.ContainsString(supportedImageExt, ext) {
|
if util.ContainsString(supportedImageExt, ext) {
|
||||||
return handler.extractImageMeta(ctx, path)
|
return handler.extractImageMeta(ctx, path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ type (
|
|||||||
Capabilities() *Capabilities
|
Capabilities() *Capabilities
|
||||||
|
|
||||||
// MediaMeta extracts media metadata from the given file.
|
// MediaMeta extracts media metadata from the given file.
|
||||||
MediaMeta(ctx context.Context, path, ext string) ([]MediaMeta, error)
|
MediaMeta(ctx context.Context, path, ext, language string) ([]MediaMeta, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
Capabilities struct {
|
Capabilities struct {
|
||||||
@@ -117,6 +117,7 @@ const (
|
|||||||
MetaTypeExif MetaType = "exif"
|
MetaTypeExif MetaType = "exif"
|
||||||
MediaTypeMusic MetaType = "music"
|
MediaTypeMusic MetaType = "music"
|
||||||
MetaTypeStreamMedia MetaType = "stream"
|
MetaTypeStreamMedia MetaType = "stream"
|
||||||
|
MetaTypeGeocoding MetaType = "geocoding"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ForceUsePublicEndpointCtx struct{}
|
type ForceUsePublicEndpointCtx struct{}
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ func (handler *Driver) Thumb(ctx context.Context, expire *time.Time, ext string,
|
|||||||
case "jpg", "webp":
|
case "jpg", "webp":
|
||||||
thumbParam += fmt.Sprintf("&q=%d&F=%s", enco.Quality, enco.Format)
|
thumbParam += fmt.Sprintf("&q=%d&F=%s", enco.Quality, enco.Format)
|
||||||
case "png":
|
case "png":
|
||||||
thumbParam += fmt.Sprintf("&F=%s", enco.Format)
|
thumbParam += fmt.Sprintf("&F=%s", enco.Format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保过期时间不小于 0 ,如果小于则设置为 7 天
|
// 确保过期时间不小于 0 ,如果小于则设置为 7 天
|
||||||
@@ -318,10 +318,10 @@ func (handler *Driver) Thumb(ctx context.Context, expire *time.Time, ext string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
thumbUrl, err := handler.svc.GeneratePresignedUrl(&s3.GeneratePresignedUrlInput{
|
thumbUrl, err := handler.svc.GeneratePresignedUrl(&s3.GeneratePresignedUrlInput{
|
||||||
HTTPMethod: s3.GET, // 请求方法
|
HTTPMethod: s3.GET, // 请求方法
|
||||||
Bucket: &handler.policy.BucketName, // 存储空间名称
|
Bucket: &handler.policy.BucketName, // 存储空间名称
|
||||||
Key: aws.String(e.Source()+thumbParam), // 对象的key
|
Key: aws.String(e.Source() + thumbParam), // 对象的key
|
||||||
Expires: ttl, // 过期时间,转换为秒数
|
Expires: ttl, // 过期时间,转换为秒数
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -505,7 +505,7 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MediaMeta 获取媒体元信息
|
// MediaMeta 获取媒体元信息
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -298,6 +298,6 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
return capabilities
|
return capabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (d *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
thumbURL, err := d.signSourceURL(&obs.CreateSignedUrlInput{
|
thumbURL, err := d.signSourceURL(&obs.CreateSignedUrlInput{
|
||||||
Method: obs.HttpMethodGet,
|
Method: obs.HttpMethodGet,
|
||||||
Bucket: d.policy.BucketName,
|
Bucket: d.policy.BucketName,
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,17 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/driver"
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/mediameta"
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/request"
|
|
||||||
"github.com/samber/lo"
|
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/driver"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/mediameta"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/request"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -265,13 +266,14 @@ func (handler *Driver) extractImageMeta(ctx context.Context, path string) ([]dri
|
|||||||
|
|
||||||
// extractMediaInfo Sends API calls to OSS IMM service to extract media info.
|
// extractMediaInfo Sends API calls to OSS IMM service to extract media info.
|
||||||
func (handler *Driver) extractMediaInfo(ctx context.Context, path string, category string, forceSign bool) (string, error) {
|
func (handler *Driver) extractMediaInfo(ctx context.Context, path string, category string, forceSign bool) (string, error) {
|
||||||
mediaOption := []oss.Option{oss.Process(category)}
|
|
||||||
mediaInfoExpire := time.Now().Add(mediaInfoTTL)
|
mediaInfoExpire := time.Now().Add(mediaInfoTTL)
|
||||||
thumbURL, err := handler.signSourceURL(
|
thumbURL, err := handler.signSourceURL(
|
||||||
ctx,
|
ctx,
|
||||||
path,
|
path,
|
||||||
&mediaInfoExpire,
|
&mediaInfoExpire,
|
||||||
mediaOption,
|
&oss.GetObjectRequest{
|
||||||
|
Process: oss.Ptr(category),
|
||||||
|
},
|
||||||
forceSign,
|
forceSign,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
|
||||||
|
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/boolset"
|
"github.com/cloudreve/Cloudreve/v4/pkg/boolset"
|
||||||
@@ -52,7 +53,6 @@ type Driver struct {
|
|||||||
policy *ent.StoragePolicy
|
policy *ent.StoragePolicy
|
||||||
|
|
||||||
client *oss.Client
|
client *oss.Client
|
||||||
bucket *oss.Bucket
|
|
||||||
settings setting.Provider
|
settings setting.Provider
|
||||||
l logging.Logger
|
l logging.Logger
|
||||||
config conf.ConfigProvider
|
config conf.ConfigProvider
|
||||||
@@ -65,12 +65,11 @@ type Driver struct {
|
|||||||
type key int
|
type key int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
chunkRetrySleep = time.Duration(5) * time.Second
|
chunkRetrySleep = time.Duration(5) * time.Second
|
||||||
uploadIdParam = "uploadId"
|
maxDeleteBatch = 1000
|
||||||
partNumberParam = "partNumber"
|
completeAllHeader = "x-oss-complete-all"
|
||||||
callbackParam = "callback"
|
forbidOverwriteHeader = "x-oss-forbid-overwrite"
|
||||||
completeAllHeader = "x-oss-complete-all"
|
trafficLimitHeader = "x-oss-traffic-limit"
|
||||||
maxDeleteBatch = 1000
|
|
||||||
|
|
||||||
// MultiPartUploadThreshold 服务端使用分片上传的阈值
|
// MultiPartUploadThreshold 服务端使用分片上传的阈值
|
||||||
MultiPartUploadThreshold int64 = 5 * (1 << 30) // 5GB
|
MultiPartUploadThreshold int64 = 5 * (1 << 30) // 5GB
|
||||||
@@ -102,21 +101,27 @@ func New(ctx context.Context, policy *ent.StoragePolicy, settings setting.Provid
|
|||||||
|
|
||||||
// CORS 创建跨域策略
|
// CORS 创建跨域策略
|
||||||
func (handler *Driver) CORS() error {
|
func (handler *Driver) CORS() error {
|
||||||
return handler.client.SetBucketCORS(handler.policy.BucketName, []oss.CORSRule{
|
_, err := handler.client.PutBucketCors(context.Background(), &oss.PutBucketCorsRequest{
|
||||||
{
|
Bucket: &handler.policy.BucketName,
|
||||||
AllowedOrigin: []string{"*"},
|
CORSConfiguration: &oss.CORSConfiguration{
|
||||||
AllowedMethod: []string{
|
CORSRules: []oss.CORSRule{
|
||||||
"GET",
|
{
|
||||||
"POST",
|
AllowedOrigins: []string{"*"},
|
||||||
"PUT",
|
AllowedMethods: []string{
|
||||||
"DELETE",
|
"GET",
|
||||||
"HEAD",
|
"POST",
|
||||||
|
"PUT",
|
||||||
|
"DELETE",
|
||||||
|
"HEAD",
|
||||||
|
},
|
||||||
|
ExposeHeaders: []string{},
|
||||||
|
AllowedHeaders: []string{"*"},
|
||||||
|
MaxAgeSeconds: oss.Ptr(int64(3600)),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
ExposeHeader: []string{},
|
}})
|
||||||
AllowedHeader: []string{"*"},
|
|
||||||
MaxAgeSeconds: 3600,
|
return err
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitOSSClient 初始化OSS鉴权客户端
|
// InitOSSClient 初始化OSS鉴权客户端
|
||||||
@@ -125,34 +130,28 @@ func (handler *Driver) InitOSSClient(forceUsePublicEndpoint bool) error {
|
|||||||
return errors.New("empty policy")
|
return errors.New("empty policy")
|
||||||
}
|
}
|
||||||
|
|
||||||
opt := make([]oss.ClientOption, 0)
|
|
||||||
|
|
||||||
// 决定是否使用内网 Endpoint
|
// 决定是否使用内网 Endpoint
|
||||||
endpoint := handler.policy.Server
|
endpoint := handler.policy.Server
|
||||||
|
useCname := false
|
||||||
if handler.policy.Settings.ServerSideEndpoint != "" && !forceUsePublicEndpoint {
|
if handler.policy.Settings.ServerSideEndpoint != "" && !forceUsePublicEndpoint {
|
||||||
endpoint = handler.policy.Settings.ServerSideEndpoint
|
endpoint = handler.policy.Settings.ServerSideEndpoint
|
||||||
} else if handler.policy.Settings.UseCname {
|
} else if handler.policy.Settings.UseCname {
|
||||||
opt = append(opt, oss.UseCname(true))
|
useCname = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
|
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
|
||||||
endpoint = "https://" + endpoint
|
endpoint = "https://" + endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg := oss.LoadDefaultConfig().
|
||||||
|
WithCredentialsProvider(credentials.NewStaticCredentialsProvider(handler.policy.AccessKey, handler.policy.SecretKey, "")).
|
||||||
|
WithEndpoint(endpoint).
|
||||||
|
WithRegion(handler.policy.Settings.Region).
|
||||||
|
WithUseCName(useCname)
|
||||||
|
|
||||||
// 初始化客户端
|
// 初始化客户端
|
||||||
client, err := oss.New(endpoint, handler.policy.AccessKey, handler.policy.SecretKey, opt...)
|
client := oss.NewClient(cfg)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
handler.client = client
|
handler.client = client
|
||||||
|
|
||||||
// 初始化存储桶
|
|
||||||
bucket, err := client.Bucket(handler.policy.BucketName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
handler.bucket = bucket
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,38 +165,40 @@ func (handler *Driver) List(ctx context.Context, base string, onProgress driver.
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
delimiter string
|
delimiter string
|
||||||
marker string
|
|
||||||
objects []oss.ObjectProperties
|
objects []oss.ObjectProperties
|
||||||
commons []string
|
commons []oss.CommonPrefix
|
||||||
)
|
)
|
||||||
if !recursive {
|
if !recursive {
|
||||||
delimiter = "/"
|
delimiter = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
p := handler.client.NewListObjectsPaginator(&oss.ListObjectsRequest{
|
||||||
subRes, err := handler.bucket.ListObjects(oss.Marker(marker), oss.Prefix(base),
|
Bucket: &handler.policy.BucketName,
|
||||||
oss.MaxKeys(1000), oss.Delimiter(delimiter))
|
Prefix: &base,
|
||||||
|
MaxKeys: 1000,
|
||||||
|
Delimiter: &delimiter,
|
||||||
|
})
|
||||||
|
|
||||||
|
for p.HasNext() {
|
||||||
|
page, err := p.NextPage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
objects = append(objects, subRes.Objects...)
|
|
||||||
commons = append(commons, subRes.CommonPrefixes...)
|
objects = append(objects, page.Contents...)
|
||||||
marker = subRes.NextMarker
|
commons = append(commons, page.CommonPrefixes...)
|
||||||
if marker == "" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理列取结果
|
// 处理列取结果
|
||||||
res := make([]fs.PhysicalObject, 0, len(objects)+len(commons))
|
res := make([]fs.PhysicalObject, 0, len(objects)+len(commons))
|
||||||
// 处理目录
|
// 处理目录
|
||||||
for _, object := range commons {
|
for _, object := range commons {
|
||||||
rel, err := filepath.Rel(base, object)
|
rel, err := filepath.Rel(base, *object.Prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res = append(res, fs.PhysicalObject{
|
res = append(res, fs.PhysicalObject{
|
||||||
Name: path.Base(object),
|
Name: path.Base(*object.Prefix),
|
||||||
RelativePath: filepath.ToSlash(rel),
|
RelativePath: filepath.ToSlash(rel),
|
||||||
Size: 0,
|
Size: 0,
|
||||||
IsDir: true,
|
IsDir: true,
|
||||||
@@ -208,17 +209,17 @@ func (handler *Driver) List(ctx context.Context, base string, onProgress driver.
|
|||||||
|
|
||||||
// 处理文件
|
// 处理文件
|
||||||
for _, object := range objects {
|
for _, object := range objects {
|
||||||
rel, err := filepath.Rel(base, object.Key)
|
rel, err := filepath.Rel(base, *object.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res = append(res, fs.PhysicalObject{
|
res = append(res, fs.PhysicalObject{
|
||||||
Name: path.Base(object.Key),
|
Name: path.Base(*object.Key),
|
||||||
Source: object.Key,
|
Source: *object.Key,
|
||||||
RelativePath: filepath.ToSlash(rel),
|
RelativePath: filepath.ToSlash(rel),
|
||||||
Size: object.Size,
|
Size: object.Size,
|
||||||
IsDir: false,
|
IsDir: false,
|
||||||
LastModify: object.LastModified,
|
LastModify: *object.LastModified,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onProgress(len(res))
|
onProgress(len(res))
|
||||||
@@ -245,25 +246,34 @@ func (handler *Driver) Put(ctx context.Context, file *fs.UploadRequest) error {
|
|||||||
|
|
||||||
// 是否允许覆盖
|
// 是否允许覆盖
|
||||||
overwrite := file.Mode&fs.ModeOverwrite == fs.ModeOverwrite
|
overwrite := file.Mode&fs.ModeOverwrite == fs.ModeOverwrite
|
||||||
options := []oss.Option{
|
forbidOverwrite := oss.Ptr(strconv.FormatBool(!overwrite))
|
||||||
oss.WithContext(ctx),
|
exipires := oss.Ptr(time.Now().Add(credentialTTL * time.Second).Format(time.RFC3339))
|
||||||
oss.Expires(time.Now().Add(credentialTTL * time.Second)),
|
|
||||||
oss.ForbidOverWrite(!overwrite),
|
|
||||||
oss.ContentType(mimeType),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 小文件直接上传
|
// 小文件直接上传
|
||||||
if file.Props.Size < MultiPartUploadThreshold {
|
if file.Props.Size < MultiPartUploadThreshold {
|
||||||
return handler.bucket.PutObject(file.Props.SavePath, file, options...)
|
_, err := handler.client.PutObject(ctx, &oss.PutObjectRequest{
|
||||||
|
Bucket: &handler.policy.BucketName,
|
||||||
|
Key: &file.Props.SavePath,
|
||||||
|
Body: file,
|
||||||
|
ForbidOverwrite: forbidOverwrite,
|
||||||
|
ContentType: oss.Ptr(mimeType),
|
||||||
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 超过阈值时使用分片上传
|
// 超过阈值时使用分片上传
|
||||||
imur, err := handler.bucket.InitiateMultipartUpload(file.Props.SavePath, options...)
|
imur, err := handler.client.InitiateMultipartUpload(ctx, &oss.InitiateMultipartUploadRequest{
|
||||||
|
Bucket: &handler.policy.BucketName,
|
||||||
|
Key: &file.Props.SavePath,
|
||||||
|
ContentType: oss.Ptr(mimeType),
|
||||||
|
ForbidOverwrite: forbidOverwrite,
|
||||||
|
Expires: exipires,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to initiate multipart upload: %w", err)
|
return fmt.Errorf("failed to initiate multipart upload: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := make([]oss.UploadPart, 0)
|
parts := make([]*oss.UploadPartResult, 0)
|
||||||
|
|
||||||
chunks := chunk.NewChunkGroup(file, handler.chunkSize, &backoff.ConstantBackoff{
|
chunks := chunk.NewChunkGroup(file, handler.chunkSize, &backoff.ConstantBackoff{
|
||||||
Max: handler.settings.ChunkRetryLimit(ctx),
|
Max: handler.settings.ChunkRetryLimit(ctx),
|
||||||
@@ -271,7 +281,13 @@ func (handler *Driver) Put(ctx context.Context, file *fs.UploadRequest) error {
|
|||||||
}, handler.settings.UseChunkBuffer(ctx), handler.l, handler.settings.TempPath(ctx))
|
}, handler.settings.UseChunkBuffer(ctx), handler.l, handler.settings.TempPath(ctx))
|
||||||
|
|
||||||
uploadFunc := func(current *chunk.ChunkGroup, content io.Reader) error {
|
uploadFunc := func(current *chunk.ChunkGroup, content io.Reader) error {
|
||||||
part, err := handler.bucket.UploadPart(imur, content, current.Length(), current.Index()+1, oss.WithContext(ctx))
|
part, err := handler.client.UploadPart(ctx, &oss.UploadPartRequest{
|
||||||
|
Bucket: &handler.policy.BucketName,
|
||||||
|
Key: &file.Props.SavePath,
|
||||||
|
UploadId: imur.UploadId,
|
||||||
|
PartNumber: int32(current.Index() + 1),
|
||||||
|
Body: content,
|
||||||
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
parts = append(parts, part)
|
parts = append(parts, part)
|
||||||
}
|
}
|
||||||
@@ -280,14 +296,27 @@ func (handler *Driver) Put(ctx context.Context, file *fs.UploadRequest) error {
|
|||||||
|
|
||||||
for chunks.Next() {
|
for chunks.Next() {
|
||||||
if err := chunks.Process(uploadFunc); err != nil {
|
if err := chunks.Process(uploadFunc); err != nil {
|
||||||
handler.cancelUpload(imur)
|
handler.cancelUpload(*imur)
|
||||||
return fmt.Errorf("failed to upload chunk #%d: %w", chunks.Index(), err)
|
return fmt.Errorf("failed to upload chunk #%d: %w", chunks.Index(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = handler.bucket.CompleteMultipartUpload(imur, parts, oss.ForbidOverWrite(!overwrite), oss.WithContext(ctx))
|
_, err = handler.client.CompleteMultipartUpload(ctx, &oss.CompleteMultipartUploadRequest{
|
||||||
|
Bucket: &handler.policy.BucketName,
|
||||||
|
Key: imur.Key,
|
||||||
|
UploadId: imur.UploadId,
|
||||||
|
CompleteMultipartUpload: &oss.CompleteMultipartUpload{
|
||||||
|
Parts: lo.Map(parts, func(part *oss.UploadPartResult, i int) oss.UploadPart {
|
||||||
|
return oss.UploadPart{
|
||||||
|
PartNumber: int32(i + 1),
|
||||||
|
ETag: part.ETag,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
ForbidOverwrite: oss.Ptr(strconv.FormatBool(!overwrite)),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.cancelUpload(imur)
|
handler.cancelUpload(*imur)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@@ -302,7 +331,12 @@ func (handler *Driver) Delete(ctx context.Context, files ...string) ([]string, e
|
|||||||
for index, group := range groups {
|
for index, group := range groups {
|
||||||
handler.l.Debug("Process delete group #%d: %v", index, group)
|
handler.l.Debug("Process delete group #%d: %v", index, group)
|
||||||
// 删除文件
|
// 删除文件
|
||||||
delRes, err := handler.bucket.DeleteObjects(group)
|
delRes, err := handler.client.DeleteMultipleObjects(ctx, &oss.DeleteMultipleObjectsRequest{
|
||||||
|
Bucket: &handler.policy.BucketName,
|
||||||
|
Objects: lo.Map(group, func(v string, i int) oss.DeleteObject {
|
||||||
|
return oss.DeleteObject{Key: &v}
|
||||||
|
}),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
failed = append(failed, group...)
|
failed = append(failed, group...)
|
||||||
lastError = err
|
lastError = err
|
||||||
@@ -310,7 +344,14 @@ func (handler *Driver) Delete(ctx context.Context, files ...string) ([]string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 统计未删除的文件
|
// 统计未删除的文件
|
||||||
failed = append(failed, util.SliceDifference(files, delRes.DeletedObjects)...)
|
failed = append(
|
||||||
|
failed,
|
||||||
|
util.SliceDifference(files,
|
||||||
|
lo.Map(delRes.DeletedObjects, func(v oss.DeletedInfo, i int) string {
|
||||||
|
return *v.Key
|
||||||
|
}),
|
||||||
|
)...,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(failed) > 0 && lastError == nil {
|
if len(failed) > 0 && lastError == nil {
|
||||||
@@ -343,12 +384,14 @@ func (handler *Driver) Thumb(ctx context.Context, expire *time.Time, ext string,
|
|||||||
thumbParam += fmt.Sprintf("/format,%s", enco.Format)
|
thumbParam += fmt.Sprintf("/format,%s", enco.Format)
|
||||||
}
|
}
|
||||||
|
|
||||||
thumbOption := []oss.Option{oss.Process(thumbParam)}
|
req := &oss.GetObjectRequest{
|
||||||
|
Process: oss.Ptr(thumbParam),
|
||||||
|
}
|
||||||
thumbURL, err := handler.signSourceURL(
|
thumbURL, err := handler.signSourceURL(
|
||||||
ctx,
|
ctx,
|
||||||
e.Source(),
|
e.Source(),
|
||||||
expire,
|
expire,
|
||||||
thumbOption,
|
req,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -370,11 +413,11 @@ func (handler *Driver) Source(ctx context.Context, e fs.Entity, args *driver.Get
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 添加各项设置
|
// 添加各项设置
|
||||||
var signOptions = make([]oss.Option, 0, 2)
|
req := &oss.GetObjectRequest{}
|
||||||
if args.IsDownload {
|
if args.IsDownload {
|
||||||
encodedFilename := url.PathEscape(args.DisplayName)
|
encodedFilename := url.PathEscape(args.DisplayName)
|
||||||
signOptions = append(signOptions, oss.ResponseContentDisposition(fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`,
|
req.ResponseContentDisposition = oss.Ptr(fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`,
|
||||||
encodedFilename, encodedFilename)))
|
encodedFilename, encodedFilename))
|
||||||
}
|
}
|
||||||
if args.Speed > 0 {
|
if args.Speed > 0 {
|
||||||
// Byte 转换为 bit
|
// Byte 转换为 bit
|
||||||
@@ -387,25 +430,35 @@ func (handler *Driver) Source(ctx context.Context, e fs.Entity, args *driver.Get
|
|||||||
if args.Speed > 838860800 {
|
if args.Speed > 838860800 {
|
||||||
args.Speed = 838860800
|
args.Speed = 838860800
|
||||||
}
|
}
|
||||||
signOptions = append(signOptions, oss.TrafficLimitParam(args.Speed))
|
req.Parameters = map[string]string{
|
||||||
|
trafficLimitHeader: strconv.FormatInt(args.Speed, 10),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler.signSourceURL(ctx, e.Source(), args.Expire, signOptions, false)
|
return handler.signSourceURL(ctx, e.Source(), args.Expire, req, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) signSourceURL(ctx context.Context, path string, expire *time.Time, options []oss.Option, forceSign bool) (string, error) {
|
func (handler *Driver) signSourceURL(ctx context.Context, path string, expire *time.Time, req *oss.GetObjectRequest, forceSign bool) (string, error) {
|
||||||
ttl := int64(86400 * 365 * 20)
|
ttl := time.Duration(24) * time.Hour * 365 * 20
|
||||||
if expire != nil {
|
if expire != nil {
|
||||||
ttl = int64(time.Until(*expire).Seconds())
|
ttl = time.Until(*expire)
|
||||||
}
|
}
|
||||||
|
|
||||||
signedURL, err := handler.bucket.SignURL(path, oss.HTTPGet, ttl, options...)
|
if req == nil {
|
||||||
|
req = &oss.GetObjectRequest{}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Bucket = &handler.policy.BucketName
|
||||||
|
req.Key = &path
|
||||||
|
|
||||||
|
// signedURL, err := handler.client.Presign(path, oss.HTTPGet, ttl, options...)
|
||||||
|
result, err := handler.client.Presign(ctx, req, oss.PresignExpires(ttl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将最终生成的签名URL域名换成用户自定义的加速域名(如果有)
|
// 将最终生成的签名URL域名换成用户自定义的加速域名(如果有)
|
||||||
finalURL, err := url.Parse(signedURL)
|
finalURL, err := url.Parse(result.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -416,7 +469,7 @@ func (handler *Driver) signSourceURL(ctx context.Context, path string, expire *t
|
|||||||
query.Del("OSSAccessKeyId")
|
query.Del("OSSAccessKeyId")
|
||||||
query.Del("Signature")
|
query.Del("Signature")
|
||||||
query.Del("response-content-disposition")
|
query.Del("response-content-disposition")
|
||||||
query.Del("x-oss-traffic-limit")
|
query.Del(trafficLimitHeader)
|
||||||
finalURL.RawQuery = query.Encode()
|
finalURL.RawQuery = query.Encode()
|
||||||
}
|
}
|
||||||
return finalURL.String(), nil
|
return finalURL.String(), nil
|
||||||
@@ -454,34 +507,41 @@ func (handler *Driver) Token(ctx context.Context, uploadSession *fs.UploadSessio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化分片上传
|
// 初始化分片上传
|
||||||
options := []oss.Option{
|
imur, err := handler.client.InitiateMultipartUpload(ctx, &oss.InitiateMultipartUploadRequest{
|
||||||
oss.WithContext(ctx),
|
Bucket: &handler.policy.BucketName,
|
||||||
oss.Expires(uploadSession.Props.ExpireAt),
|
Key: &file.Props.SavePath,
|
||||||
oss.ForbidOverWrite(true),
|
ContentType: oss.Ptr(mimeType),
|
||||||
oss.ContentType(mimeType),
|
ForbidOverwrite: oss.Ptr(strconv.FormatBool(true)),
|
||||||
}
|
Expires: oss.Ptr(uploadSession.Props.ExpireAt.Format(time.RFC3339)),
|
||||||
imur, err := handler.bucket.InitiateMultipartUpload(file.Props.SavePath, options...)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to initialize multipart upload: %w", err)
|
return nil, fmt.Errorf("failed to initialize multipart upload: %w", err)
|
||||||
}
|
}
|
||||||
uploadSession.UploadID = imur.UploadID
|
uploadSession.UploadID = *imur.UploadId
|
||||||
|
|
||||||
// 为每个分片签名上传 URL
|
// 为每个分片签名上传 URL
|
||||||
chunks := chunk.NewChunkGroup(file, handler.chunkSize, &backoff.ConstantBackoff{}, false, handler.l, "")
|
chunks := chunk.NewChunkGroup(file, handler.chunkSize, &backoff.ConstantBackoff{}, false, handler.l, "")
|
||||||
urls := make([]string, chunks.Num())
|
urls := make([]string, chunks.Num())
|
||||||
ttl := int64(time.Until(uploadSession.Props.ExpireAt).Seconds())
|
ttl := time.Until(uploadSession.Props.ExpireAt)
|
||||||
for chunks.Next() {
|
for chunks.Next() {
|
||||||
err := chunks.Process(func(c *chunk.ChunkGroup, chunk io.Reader) error {
|
err := chunks.Process(func(c *chunk.ChunkGroup, chunk io.Reader) error {
|
||||||
signedURL, err := handler.bucket.SignURL(file.Props.SavePath, oss.HTTPPut,
|
signedURL, err := handler.client.Presign(ctx, &oss.UploadPartRequest{
|
||||||
ttl,
|
Bucket: &handler.policy.BucketName,
|
||||||
oss.AddParam(partNumberParam, strconv.Itoa(c.Index()+1)),
|
Key: &file.Props.SavePath,
|
||||||
oss.AddParam(uploadIdParam, imur.UploadID),
|
UploadId: imur.UploadId,
|
||||||
oss.ContentType("application/octet-stream"))
|
PartNumber: int32(c.Index() + 1),
|
||||||
|
Body: chunk,
|
||||||
|
RequestCommon: oss.RequestCommon{
|
||||||
|
Headers: map[string]string{
|
||||||
|
"Content-Type": "application/octet-stream",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, oss.PresignExpires(ttl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
urls[c.Index()] = signedURL
|
urls[c.Index()] = signedURL.URL
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -490,29 +550,43 @@ func (handler *Driver) Token(ctx context.Context, uploadSession *fs.UploadSessio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 签名完成分片上传的URL
|
// 签名完成分片上传的URL
|
||||||
completeURL, err := handler.bucket.SignURL(file.Props.SavePath, oss.HTTPPost, ttl,
|
completeURL, err := handler.client.Presign(ctx, &oss.CompleteMultipartUploadRequest{
|
||||||
oss.ContentType("application/octet-stream"),
|
Bucket: &handler.policy.BucketName,
|
||||||
oss.AddParam(uploadIdParam, imur.UploadID),
|
Key: &file.Props.SavePath,
|
||||||
oss.Expires(time.Now().Add(time.Duration(ttl)*time.Second)),
|
UploadId: imur.UploadId,
|
||||||
oss.SetHeader(completeAllHeader, "yes"),
|
RequestCommon: oss.RequestCommon{
|
||||||
oss.ForbidOverWrite(true),
|
Parameters: map[string]string{
|
||||||
oss.AddParam(callbackParam, callbackPolicyEncoded))
|
"callback": callbackPolicyEncoded,
|
||||||
|
},
|
||||||
|
Headers: map[string]string{
|
||||||
|
"Content-Type": "application/octet-stream",
|
||||||
|
completeAllHeader: "yes",
|
||||||
|
forbidOverwriteHeader: "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, oss.PresignExpires(ttl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &fs.UploadCredential{
|
return &fs.UploadCredential{
|
||||||
UploadID: imur.UploadID,
|
UploadID: *imur.UploadId,
|
||||||
UploadURLs: urls,
|
UploadURLs: urls,
|
||||||
CompleteURL: completeURL,
|
CompleteURL: completeURL.URL,
|
||||||
SessionID: uploadSession.Props.UploadSessionID,
|
SessionID: uploadSession.Props.UploadSessionID,
|
||||||
ChunkSize: handler.chunkSize,
|
ChunkSize: handler.chunkSize,
|
||||||
|
Callback: callbackPolicyEncoded,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 取消上传凭证
|
// 取消上传凭证
|
||||||
func (handler *Driver) CancelToken(ctx context.Context, uploadSession *fs.UploadSession) error {
|
func (handler *Driver) CancelToken(ctx context.Context, uploadSession *fs.UploadSession) error {
|
||||||
return handler.bucket.AbortMultipartUpload(oss.InitiateMultipartUploadResult{UploadID: uploadSession.UploadID, Key: uploadSession.Props.SavePath}, oss.WithContext(ctx))
|
_, err := handler.client.AbortMultipartUpload(ctx, &oss.AbortMultipartUploadRequest{
|
||||||
|
Bucket: &handler.policy.BucketName,
|
||||||
|
Key: &uploadSession.Props.SavePath,
|
||||||
|
UploadId: &uploadSession.UploadID,
|
||||||
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) CompleteUpload(ctx context.Context, session *fs.UploadSession) error {
|
func (handler *Driver) CompleteUpload(ctx context.Context, session *fs.UploadSession) error {
|
||||||
@@ -535,7 +609,7 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
if util.ContainsString(supportedImageExt, ext) {
|
if util.ContainsString(supportedImageExt, ext) {
|
||||||
return handler.extractImageMeta(ctx, path)
|
return handler.extractImageMeta(ctx, path)
|
||||||
}
|
}
|
||||||
@@ -556,7 +630,11 @@ func (handler *Driver) LocalPath(ctx context.Context, path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) cancelUpload(imur oss.InitiateMultipartUploadResult) {
|
func (handler *Driver) cancelUpload(imur oss.InitiateMultipartUploadResult) {
|
||||||
if err := handler.bucket.AbortMultipartUpload(imur); err != nil {
|
if _, err := handler.client.AbortMultipartUpload(context.Background(), &oss.AbortMultipartUploadRequest{
|
||||||
|
Bucket: &handler.policy.BucketName,
|
||||||
|
Key: imur.Key,
|
||||||
|
UploadId: imur.UploadId,
|
||||||
|
}); err != nil {
|
||||||
handler.l.Warning("failed to abort multipart upload: %s", err)
|
handler.l.Warning("failed to abort multipart upload: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
if util.ContainsString(supportedImageExt, ext) {
|
if util.ContainsString(supportedImageExt, ext) {
|
||||||
return handler.extractImageMeta(ctx, path)
|
return handler.extractImageMeta(ctx, path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ type Client interface {
|
|||||||
// DeleteUploadSession deletes remote upload session
|
// DeleteUploadSession deletes remote upload session
|
||||||
DeleteUploadSession(ctx context.Context, sessionID string) error
|
DeleteUploadSession(ctx context.Context, sessionID string) error
|
||||||
// MediaMeta gets media meta from remote server
|
// MediaMeta gets media meta from remote server
|
||||||
MediaMeta(ctx context.Context, src, ext string) ([]driver.MediaMeta, error)
|
MediaMeta(ctx context.Context, src, ext, language string) ([]driver.MediaMeta, error)
|
||||||
// DeleteFiles deletes files from remote server
|
// DeleteFiles deletes files from remote server
|
||||||
DeleteFiles(ctx context.Context, files ...string) ([]string, error)
|
DeleteFiles(ctx context.Context, files ...string) ([]string, error)
|
||||||
// List lists files from remote server
|
// List lists files from remote server
|
||||||
@@ -183,10 +183,10 @@ func (c *remoteClient) DeleteFiles(ctx context.Context, files ...string) ([]stri
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *remoteClient) MediaMeta(ctx context.Context, src, ext string) ([]driver.MediaMeta, error) {
|
func (c *remoteClient) MediaMeta(ctx context.Context, src, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
resp, err := c.httpClient.Request(
|
resp, err := c.httpClient.Request(
|
||||||
http.MethodGet,
|
http.MethodGet,
|
||||||
routes.SlaveMediaMetaRoute(src, ext),
|
routes.SlaveMediaMetaRoute(src, ext, language),
|
||||||
nil,
|
nil,
|
||||||
request.WithContext(ctx),
|
request.WithContext(ctx),
|
||||||
request.WithLogger(c.l),
|
request.WithLogger(c.l),
|
||||||
|
|||||||
@@ -179,6 +179,6 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
return handler.uploadClient.MediaMeta(ctx, path, ext)
|
return handler.uploadClient.MediaMeta(ctx, path, ext, language)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ func (handler *Driver) Capabilities() *driver.Capabilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Driver) MediaMeta(ctx context.Context, path, ext string) ([]driver.MediaMeta, error) {
|
func (handler *Driver) MediaMeta(ctx context.Context, path, ext, language string) ([]driver.MediaMeta, error) {
|
||||||
return handler.extractImageMeta(ctx, path)
|
return handler.extractImageMeta(ctx, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -244,8 +244,8 @@ type (
|
|||||||
UploadURLs []string `json:"upload_urls,omitempty"`
|
UploadURLs []string `json:"upload_urls,omitempty"`
|
||||||
Credential string `json:"credential,omitempty"`
|
Credential string `json:"credential,omitempty"`
|
||||||
UploadID string `json:"uploadID,omitempty"`
|
UploadID string `json:"uploadID,omitempty"`
|
||||||
Callback string `json:"callback,omitempty"` // 回调地址
|
Callback string `json:"callback,omitempty"`
|
||||||
Uri string `json:"uri,omitempty"` // 存储路径
|
Uri string `json:"uri,omitempty"` // 存储路径
|
||||||
AccessKey string `json:"ak,omitempty"`
|
AccessKey string `json:"ak,omitempty"`
|
||||||
KeyTime string `json:"keyTime,omitempty"` // COS用有效期
|
KeyTime string `json:"keyTime,omitempty"` // COS用有效期
|
||||||
CompleteURL string `json:"completeURL,omitempty"`
|
CompleteURL string `json:"completeURL,omitempty"`
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs"
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs/dbfs"
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs/dbfs"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
|
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/mediameta"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/queue"
|
"github.com/cloudreve/Cloudreve/v4/pkg/queue"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/util"
|
"github.com/cloudreve/Cloudreve/v4/pkg/util"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@@ -106,6 +107,11 @@ func (m *manager) ExtractAndSaveMediaMeta(ctx context.Context, uri *fs.URI, enti
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
language := ""
|
||||||
|
if file.Owner().Settings != nil {
|
||||||
|
language = file.Owner().Settings.Language
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
metas []driver.MediaMeta
|
metas []driver.MediaMeta
|
||||||
)
|
)
|
||||||
@@ -117,7 +123,7 @@ func (m *manager) ExtractAndSaveMediaMeta(ctx context.Context, uri *fs.URI, enti
|
|||||||
driverCaps := d.Capabilities()
|
driverCaps := d.Capabilities()
|
||||||
if util.IsInExtensionList(driverCaps.MediaMetaSupportedExts, file.Name()) {
|
if util.IsInExtensionList(driverCaps.MediaMetaSupportedExts, file.Name()) {
|
||||||
m.l.Debug("Using native driver to generate media meta.")
|
m.l.Debug("Using native driver to generate media meta.")
|
||||||
metas, err = d.MediaMeta(ctx, targetVersion.Source(), file.Ext())
|
metas, err = d.MediaMeta(ctx, targetVersion.Source(), file.Ext(), language)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get media meta using native driver: %w", err)
|
return fmt.Errorf("failed to get media meta using native driver: %w", err)
|
||||||
}
|
}
|
||||||
@@ -130,7 +136,7 @@ func (m *manager) ExtractAndSaveMediaMeta(ctx context.Context, uri *fs.URI, enti
|
|||||||
return fmt.Errorf("failed to get entity source: %w", err)
|
return fmt.Errorf("failed to get entity source: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
metas, err = extractor.Extract(ctx, file.Ext(), source)
|
metas, err = extractor.Extract(ctx, file.Ext(), source, mediameta.WithLanguage(language))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to extract media meta using local extractor: %w", err)
|
return fmt.Errorf("failed to extract media meta using local extractor: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,15 @@ var (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"dav": {},
|
"dav": {},
|
||||||
|
// Allow manipulating thumbnail metadata via public PatchMetadata API
|
||||||
|
"thumb": {
|
||||||
|
// Only supported thumb metadata currently is thumb:disabled
|
||||||
|
dbfs.ThumbDisabledKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
||||||
|
// Presence of this key disables thumbnails; value is ignored.
|
||||||
|
// We allow both setting and removing this key.
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
customizeMetadataSuffix: {
|
customizeMetadataSuffix: {
|
||||||
iconColorMetadataKey: validateColor(false),
|
iconColorMetadataKey: validateColor(false),
|
||||||
emojiIconMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
emojiIconMetadataKey: func(ctx context.Context, m *manager, patch *fs.MetadataPatch) error {
|
||||||
|
|||||||
@@ -145,7 +145,12 @@ func (e *exifExtractor) Exts() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reference: https://github.com/photoprism/photoprism/blob/602097635f1c84d91f2d919f7aedaef7a07fc458/internal/meta/exif.go
|
// Reference: https://github.com/photoprism/photoprism/blob/602097635f1c84d91f2d919f7aedaef7a07fc458/internal/meta/exif.go
|
||||||
func (e *exifExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource) ([]driver.MediaMeta, error) {
|
func (e *exifExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc) ([]driver.MediaMeta, error) {
|
||||||
|
option := &option{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.apply(option)
|
||||||
|
}
|
||||||
|
|
||||||
localLimit, remoteLimit := e.settings.MediaMetaExifSizeLimit(ctx)
|
localLimit, remoteLimit := e.settings.MediaMetaExifSizeLimit(ctx)
|
||||||
if err := checkFileSize(localLimit, remoteLimit, source); err != nil {
|
if err := checkFileSize(localLimit, remoteLimit, source); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/driver"
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/driver"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/manager/entitysource"
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/manager/entitysource"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
|
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/request"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
|
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -17,7 +19,7 @@ type (
|
|||||||
// Exts returns the supported file extensions.
|
// Exts returns the supported file extensions.
|
||||||
Exts() []string
|
Exts() []string
|
||||||
// Extract extracts the media meta from the given source.
|
// Extract extracts the media meta from the given source.
|
||||||
Extract(ctx context.Context, ext string, source entitysource.EntitySource) ([]driver.MediaMeta, error)
|
Extract(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc) ([]driver.MediaMeta, error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ func init() {
|
|||||||
gob.Register([]driver.MediaMeta{})
|
gob.Register([]driver.MediaMeta{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExtractorManager(ctx context.Context, settings setting.Provider, l logging.Logger) Extractor {
|
func NewExtractorManager(ctx context.Context, settings setting.Provider, l logging.Logger, client request.Client) Extractor {
|
||||||
e := &extractorManager{
|
e := &extractorManager{
|
||||||
settings: settings,
|
settings: settings,
|
||||||
extMap: make(map[string][]Extractor),
|
extMap: make(map[string][]Extractor),
|
||||||
@@ -52,6 +54,11 @@ func NewExtractorManager(ctx context.Context, settings setting.Provider, l loggi
|
|||||||
extractors = append(extractors, ffprobeE)
|
extractors = append(extractors, ffprobeE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.settings.MediaMetaGeocodingEnabled(ctx) {
|
||||||
|
geocodingE := newGeocodingExtractor(settings, l, client)
|
||||||
|
extractors = append(extractors, geocodingE)
|
||||||
|
}
|
||||||
|
|
||||||
for _, extractor := range extractors {
|
for _, extractor := range extractors {
|
||||||
for _, ext := range extractor.Exts() {
|
for _, ext := range extractor.Exts() {
|
||||||
if e.extMap[ext] == nil {
|
if e.extMap[ext] == nil {
|
||||||
@@ -73,12 +80,12 @@ func (e *extractorManager) Exts() []string {
|
|||||||
return lo.Keys(e.extMap)
|
return lo.Keys(e.extMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *extractorManager) Extract(ctx context.Context, ext string, source entitysource.EntitySource) ([]driver.MediaMeta, error) {
|
func (e *extractorManager) Extract(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc) ([]driver.MediaMeta, error) {
|
||||||
if extractor, ok := e.extMap[ext]; ok {
|
if extractor, ok := e.extMap[ext]; ok {
|
||||||
res := []driver.MediaMeta{}
|
res := []driver.MediaMeta{}
|
||||||
for _, e := range extractor {
|
for _, e := range extractor {
|
||||||
_, _ = source.Seek(0, io.SeekStart)
|
_, _ = source.Seek(0, io.SeekStart)
|
||||||
data, err := e.Extract(ctx, ext, source)
|
data, err := e.Extract(ctx, ext, source, append(opts, WithExtracted(res))...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -92,6 +99,29 @@ func (e *extractorManager) Extract(ctx context.Context, ext string, source entit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type option struct {
|
||||||
|
extracted []driver.MediaMeta
|
||||||
|
language string
|
||||||
|
}
|
||||||
|
|
||||||
|
type optionFunc func(*option)
|
||||||
|
|
||||||
|
func (f optionFunc) apply(o *option) {
|
||||||
|
f(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithExtracted(extracted []driver.MediaMeta) optionFunc {
|
||||||
|
return optionFunc(func(o *option) {
|
||||||
|
o.extracted = extracted
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithLanguage(language string) optionFunc {
|
||||||
|
return optionFunc(func(o *option) {
|
||||||
|
o.language = language
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// checkFileSize checks if the file size exceeds the limit.
|
// checkFileSize checks if the file size exceeds the limit.
|
||||||
func checkFileSize(localLimit, remoteLimit int64, source entitysource.EntitySource) error {
|
func checkFileSize(localLimit, remoteLimit int64, source entitysource.EntitySource) error {
|
||||||
if source.IsLocal() && localLimit > 0 && source.Entity().Size() > localLimit {
|
if source.IsLocal() && localLimit > 0 && source.Entity().Size() > localLimit {
|
||||||
|
|||||||
@@ -88,7 +88,12 @@ func (f *ffprobeExtractor) Exts() []string {
|
|||||||
return ffprobeExts
|
return ffprobeExts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ffprobeExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource) ([]driver.MediaMeta, error) {
|
func (f *ffprobeExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc) ([]driver.MediaMeta, error) {
|
||||||
|
option := &option{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.apply(option)
|
||||||
|
}
|
||||||
|
|
||||||
localLimit, remoteLimit := f.settings.MediaMetaFFProbeSizeLimit(ctx)
|
localLimit, remoteLimit := f.settings.MediaMetaFFProbeSizeLimit(ctx)
|
||||||
if err := checkFileSize(localLimit, remoteLimit, source); err != nil {
|
if err := checkFileSize(localLimit, remoteLimit, source); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
236
pkg/mediameta/geocoding.go
Normal file
236
pkg/mediameta/geocoding.go
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
package mediameta
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/driver"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/manager/entitysource"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/request"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
|
||||||
|
)
|
||||||
|
|
||||||
|
const mapBoxURL = "https://api.mapbox.com/search/geocode/v6/reverse"
|
||||||
|
|
||||||
|
const (
|
||||||
|
Street = "street"
|
||||||
|
Locality = "locality"
|
||||||
|
Place = "place"
|
||||||
|
District = "district"
|
||||||
|
Region = "region"
|
||||||
|
Country = "country"
|
||||||
|
)
|
||||||
|
|
||||||
|
type geocodingExtractor struct {
|
||||||
|
settings setting.Provider
|
||||||
|
l logging.Logger
|
||||||
|
client request.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func newGeocodingExtractor(settings setting.Provider, l logging.Logger, client request.Client) *geocodingExtractor {
|
||||||
|
return &geocodingExtractor{
|
||||||
|
settings: settings,
|
||||||
|
l: l,
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *geocodingExtractor) Exts() []string {
|
||||||
|
return exifExts
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *geocodingExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc) ([]driver.MediaMeta, error) {
|
||||||
|
option := &option{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.apply(option)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find GPS info from extracted
|
||||||
|
var latStr, lngStr string
|
||||||
|
for _, meta := range option.extracted {
|
||||||
|
if meta.Key == GpsLat {
|
||||||
|
latStr = meta.Value
|
||||||
|
}
|
||||||
|
if meta.Key == GpsLng {
|
||||||
|
lngStr = meta.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if latStr == "" || lngStr == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
lat, err := strconv.ParseFloat(latStr, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("geocoding: failed to parse latitude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
lng, err := strconv.ParseFloat(lngStr, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("geocoding: failed to parse longitude: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
metas, err := e.getGeocoding(ctx, lat, lng, option.language)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("geocoding: failed to get geocoding: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, _ := range metas {
|
||||||
|
metas[i].Type = driver.MetaTypeGeocoding
|
||||||
|
}
|
||||||
|
|
||||||
|
return metas, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *geocodingExtractor) getGeocoding(ctx context.Context, lat, lng float64, language string) ([]driver.MediaMeta, error) {
|
||||||
|
values := url.Values{}
|
||||||
|
values.Add("longitude", fmt.Sprintf("%f", lng))
|
||||||
|
values.Add("latitude", fmt.Sprintf("%f", lat))
|
||||||
|
values.Add("limit", "1")
|
||||||
|
values.Add("access_token", e.settings.MediaMetaGeocodingMapboxAK(ctx))
|
||||||
|
if language != "" {
|
||||||
|
values.Add("language", language)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := e.client.Request(
|
||||||
|
"GET",
|
||||||
|
mapBoxURL+"?"+values.Encode(),
|
||||||
|
nil,
|
||||||
|
request.WithContext(ctx),
|
||||||
|
request.WithLogger(e.l),
|
||||||
|
).CheckHTTPResponse(http.StatusOK).GetResponse()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get geocoding from mapbox: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var geocoding MapboxGeocodingResponse
|
||||||
|
if err := json.Unmarshal([]byte(resp), &geocoding); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to unmarshal geocoding from mapbox: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(geocoding.Features) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
metas := make([]driver.MediaMeta, 0)
|
||||||
|
contexts := geocoding.Features[0].Properties.Context
|
||||||
|
if contexts.Street != nil {
|
||||||
|
metas = append(metas, driver.MediaMeta{
|
||||||
|
Key: Street,
|
||||||
|
Value: contexts.Street.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if contexts.Locality != nil {
|
||||||
|
metas = append(metas, driver.MediaMeta{
|
||||||
|
Key: Locality,
|
||||||
|
Value: contexts.Locality.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if contexts.Place != nil {
|
||||||
|
metas = append(metas, driver.MediaMeta{
|
||||||
|
Key: Place,
|
||||||
|
Value: contexts.Place.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if contexts.District != nil {
|
||||||
|
metas = append(metas, driver.MediaMeta{
|
||||||
|
Key: District,
|
||||||
|
Value: contexts.District.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if contexts.Region != nil {
|
||||||
|
metas = append(metas, driver.MediaMeta{
|
||||||
|
Key: Region,
|
||||||
|
Value: contexts.Region.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if contexts.Country != nil {
|
||||||
|
metas = append(metas, driver.MediaMeta{
|
||||||
|
Key: Country,
|
||||||
|
Value: contexts.Country.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return metas, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapboxGeocodingResponse represents the response from Mapbox Geocoding API
|
||||||
|
type MapboxGeocodingResponse struct {
|
||||||
|
Type string `json:"type"` // "FeatureCollection"
|
||||||
|
Features []Feature `json:"features"` // Array of feature objects
|
||||||
|
Attribution string `json:"attribution"` // Attribution to Mapbox
|
||||||
|
}
|
||||||
|
|
||||||
|
// Feature represents a feature object in the geocoding response
|
||||||
|
type Feature struct {
|
||||||
|
ID string `json:"id"` // Feature ID (same as mapbox_id)
|
||||||
|
Type string `json:"type"` // "Feature"
|
||||||
|
Geometry Geometry `json:"geometry"` // Spatial geometry of the feature
|
||||||
|
Properties Properties `json:"properties"` // Feature details
|
||||||
|
}
|
||||||
|
|
||||||
|
// Geometry represents the spatial geometry of a feature
|
||||||
|
type Geometry struct {
|
||||||
|
Type string `json:"type"` // "Point"
|
||||||
|
Coordinates []float64 `json:"coordinates"` // [longitude, latitude]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Properties contains the feature's detailed information
|
||||||
|
type Properties struct {
|
||||||
|
MapboxID string `json:"mapbox_id"` // Unique feature identifier
|
||||||
|
FeatureType string `json:"feature_type"` // Type of feature (country, region, etc.)
|
||||||
|
Name string `json:"name"` // Formatted address string
|
||||||
|
NamePreferred string `json:"name_preferred"` // Canonical or common alias
|
||||||
|
PlaceFormatted string `json:"place_formatted"` // Formatted context string
|
||||||
|
FullAddress string `json:"full_address"` // Full formatted address
|
||||||
|
Context Context `json:"context"` // Hierarchy of parent features
|
||||||
|
Coordinates Coordinates `json:"coordinates"` // Geographic position and accuracy
|
||||||
|
BBox []float64 `json:"bbox,omitempty"` // Bounding box [minLon,minLat,maxLon,maxLat]
|
||||||
|
MatchCode MatchCode `json:"match_code"` // Metadata about result matching
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context represents the hierarchy of encompassing parent features
|
||||||
|
type Context struct {
|
||||||
|
Country *ContextFeature `json:"country,omitempty"`
|
||||||
|
Region *ContextFeature `json:"region,omitempty"`
|
||||||
|
Postcode *ContextFeature `json:"postcode,omitempty"`
|
||||||
|
District *ContextFeature `json:"district,omitempty"`
|
||||||
|
Place *ContextFeature `json:"place,omitempty"`
|
||||||
|
Locality *ContextFeature `json:"locality,omitempty"`
|
||||||
|
Neighborhood *ContextFeature `json:"neighborhood,omitempty"`
|
||||||
|
Street *ContextFeature `json:"street,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContextFeature represents a feature in the context hierarchy
|
||||||
|
type ContextFeature struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
NamePreferred string `json:"name_preferred,omitempty"`
|
||||||
|
MapboxID string `json:"mapbox_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coordinates represents geographical position and accuracy information
|
||||||
|
type Coordinates struct {
|
||||||
|
Longitude float64 `json:"longitude"` // Longitude of result
|
||||||
|
Latitude float64 `json:"latitude"` // Latitude of result
|
||||||
|
Accuracy string `json:"accuracy,omitempty"` // Accuracy metric for address results
|
||||||
|
RoutablePoints []RoutablePoint `json:"routable_points,omitempty"` // Array of routable points
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoutablePoint represents a routable point for an address feature
|
||||||
|
type RoutablePoint struct {
|
||||||
|
Name string `json:"name"` // Name of the routable point
|
||||||
|
Longitude float64 `json:"longitude"` // Longitude coordinate
|
||||||
|
Latitude float64 `json:"latitude"` // Latitude coordinate
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchCode contains metadata about how result components match the input query
|
||||||
|
type MatchCode struct {
|
||||||
|
// Add specific match code fields as needed based on Mapbox documentation
|
||||||
|
// This structure may vary depending on the specific match codes returned
|
||||||
|
}
|
||||||
@@ -48,7 +48,12 @@ func (a *musicExtractor) Exts() []string {
|
|||||||
return audioExts
|
return audioExts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *musicExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource) ([]driver.MediaMeta, error) {
|
func (a *musicExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc) ([]driver.MediaMeta, error) {
|
||||||
|
option := &option{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.apply(option)
|
||||||
|
}
|
||||||
|
|
||||||
localLimit, remoteLimit := a.settings.MediaMetaMusicSizeLimit(ctx)
|
localLimit, remoteLimit := a.settings.MediaMetaMusicSizeLimit(ctx)
|
||||||
if err := checkFileSize(localLimit, remoteLimit, source); err != nil {
|
if err := checkFileSize(localLimit, remoteLimit, source); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ type (
|
|||||||
MediaMetaFFProbeSizeLimit(ctx context.Context) (int64, int64)
|
MediaMetaFFProbeSizeLimit(ctx context.Context) (int64, int64)
|
||||||
// MediaMetaFFProbePath returns the path of ffprobe executable.
|
// MediaMetaFFProbePath returns the path of ffprobe executable.
|
||||||
MediaMetaFFProbePath(ctx context.Context) string
|
MediaMetaFFProbePath(ctx context.Context) string
|
||||||
|
// MediaMetaGeocodingEnabled returns true if media meta geocoding is enabled.
|
||||||
|
MediaMetaGeocodingEnabled(ctx context.Context) bool
|
||||||
|
// MediaMetaGeocodingMapboxAK returns the Mapbox access token.
|
||||||
|
MediaMetaGeocodingMapboxAK(ctx context.Context) string
|
||||||
// ThumbSize returns the size limit of thumbnails.
|
// ThumbSize returns the size limit of thumbnails.
|
||||||
ThumbSize(ctx context.Context) (int, int)
|
ThumbSize(ctx context.Context) (int, int)
|
||||||
// ThumbEncode returns the thumbnail encoding settings.
|
// ThumbEncode returns the thumbnail encoding settings.
|
||||||
@@ -306,6 +310,7 @@ func (s *settingProvider) MapSetting(ctx context.Context) *MapSetting {
|
|||||||
return &MapSetting{
|
return &MapSetting{
|
||||||
Provider: MapProvider(s.getString(ctx, "map_provider", "openstreetmap")),
|
Provider: MapProvider(s.getString(ctx, "map_provider", "openstreetmap")),
|
||||||
GoogleTileType: MapGoogleTileType(s.getString(ctx, "map_google_tile_type", "roadmap")),
|
GoogleTileType: MapGoogleTileType(s.getString(ctx, "map_google_tile_type", "roadmap")),
|
||||||
|
MapboxAK: s.getString(ctx, "map_mapbox_ak", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,6 +532,14 @@ func (s *settingProvider) MediaMetaEnabled(ctx context.Context) bool {
|
|||||||
return s.getBoolean(ctx, "media_meta", true)
|
return s.getBoolean(ctx, "media_meta", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *settingProvider) MediaMetaGeocodingEnabled(ctx context.Context) bool {
|
||||||
|
return s.getBoolean(ctx, "media_meta_geocoding", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingProvider) MediaMetaGeocodingMapboxAK(ctx context.Context) string {
|
||||||
|
return s.getString(ctx, "media_meta_geocoding_mapbox_ak", "")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *settingProvider) PublicResourceMaxAge(ctx context.Context) int {
|
func (s *settingProvider) PublicResourceMaxAge(ctx context.Context) int {
|
||||||
return s.getInt(ctx, "public_resource_maxage", 0)
|
return s.getInt(ctx, "public_resource_maxage", 0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ type MapProvider string
|
|||||||
const (
|
const (
|
||||||
MapProviderOpenStreetMap = MapProvider("openstreetmap")
|
MapProviderOpenStreetMap = MapProvider("openstreetmap")
|
||||||
MapProviderGoogle = MapProvider("google")
|
MapProviderGoogle = MapProvider("google")
|
||||||
|
MapProviderMapbox = MapProvider("mapbox")
|
||||||
)
|
)
|
||||||
|
|
||||||
type MapGoogleTileType string
|
type MapGoogleTileType string
|
||||||
@@ -173,6 +174,7 @@ const (
|
|||||||
type MapSetting struct {
|
type MapSetting struct {
|
||||||
Provider MapProvider
|
Provider MapProvider
|
||||||
GoogleTileType MapGoogleTileType
|
GoogleTileType MapGoogleTileType
|
||||||
|
MapboxAK string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Viewer related
|
// Viewer related
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ import (
|
|||||||
|
|
||||||
const thumbTempFolder = "thumb"
|
const thumbTempFolder = "thumb"
|
||||||
|
|
||||||
|
// BuiltinSupportedExts lists file extensions supported by the built-in
|
||||||
|
// thumbnail generator. Extensions are lowercased and do not include the dot.
|
||||||
|
var BuiltinSupportedExts = []string{"jpg", "jpeg", "png", "gif"}
|
||||||
|
|
||||||
// Thumb 缩略图
|
// Thumb 缩略图
|
||||||
type Thumb struct {
|
type Thumb struct {
|
||||||
src image.Image
|
src image.Image
|
||||||
|
|||||||
@@ -212,7 +212,13 @@ func handleMkcol(c *gin.Context, user *ent.User, fm manager.FileManager) (status
|
|||||||
|
|
||||||
_, err = fm.Create(ctx, uri, types.FileTypeFolder, dbfs.WithNoChainedCreation(), dbfs.WithErrorOnConflict())
|
_, err = fm.Create(ctx, uri, types.FileTypeFolder, dbfs.WithNoChainedCreation(), dbfs.WithErrorOnConflict())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return purposeStatusCodeFromError(err), err
|
code := purposeStatusCodeFromError(err)
|
||||||
|
if code == http.StatusNotFound {
|
||||||
|
// When the MKCOL operation creates a new collection resource, all ancestors MUST already exist,
|
||||||
|
// or the method MUST fail with a 409 (Conflict) status code.
|
||||||
|
return http.StatusConflict, err
|
||||||
|
}
|
||||||
|
return code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.StatusCreated, nil
|
return http.StatusCreated, nil
|
||||||
|
|||||||
@@ -618,7 +618,7 @@ func initMasterRouter(dep dependency.Dep) *gin.Engine {
|
|||||||
controllers.ServeEntity,
|
controllers.ServeEntity,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// 获取缩略图
|
// get thumb
|
||||||
file.GET("thumb",
|
file.GET("thumb",
|
||||||
middleware.ContextHint(),
|
middleware.ContextHint(),
|
||||||
controllers.FromQuery[explorer.FileThumbService](explorer.FileThumbParameterCtx{}),
|
controllers.FromQuery[explorer.FileThumbService](explorer.FileThumbParameterCtx{}),
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package basic
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory"
|
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
|
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/thumb"
|
||||||
"github.com/cloudreve/Cloudreve/v4/service/user"
|
"github.com/cloudreve/Cloudreve/v4/service/user"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/mojocn/base64Captcha"
|
"github.com/mojocn/base64Captcha"
|
||||||
@@ -43,12 +47,16 @@ type SiteConfig struct {
|
|||||||
EmojiPreset string `json:"emoji_preset,omitempty"`
|
EmojiPreset string `json:"emoji_preset,omitempty"`
|
||||||
MapProvider setting.MapProvider `json:"map_provider,omitempty"`
|
MapProvider setting.MapProvider `json:"map_provider,omitempty"`
|
||||||
GoogleMapTileType setting.MapGoogleTileType `json:"google_map_tile_type,omitempty"`
|
GoogleMapTileType setting.MapGoogleTileType `json:"google_map_tile_type,omitempty"`
|
||||||
|
MapboxAK string `json:"mapbox_ak,omitempty"`
|
||||||
FileViewers []types.ViewerGroup `json:"file_viewers,omitempty"`
|
FileViewers []types.ViewerGroup `json:"file_viewers,omitempty"`
|
||||||
MaxBatchSize int `json:"max_batch_size,omitempty"`
|
MaxBatchSize int `json:"max_batch_size,omitempty"`
|
||||||
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
||||||
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
||||||
CustomProps []types.CustomProps `json:"custom_props,omitempty"`
|
CustomProps []types.CustomProps `json:"custom_props,omitempty"`
|
||||||
|
|
||||||
|
// Thumbnail section
|
||||||
|
ThumbExts []string `json:"thumb_exts,omitempty"`
|
||||||
|
|
||||||
// App settings
|
// App settings
|
||||||
AppPromotion bool `json:"app_promotion,omitempty"`
|
AppPromotion bool `json:"app_promotion,omitempty"`
|
||||||
|
|
||||||
@@ -104,6 +112,7 @@ func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) {
|
|||||||
Icons: explorerSettings.Icons,
|
Icons: explorerSettings.Icons,
|
||||||
MapProvider: mapSettings.Provider,
|
MapProvider: mapSettings.Provider,
|
||||||
GoogleMapTileType: mapSettings.GoogleTileType,
|
GoogleMapTileType: mapSettings.GoogleTileType,
|
||||||
|
MapboxAK: mapSettings.MapboxAK,
|
||||||
ThumbnailWidth: w,
|
ThumbnailWidth: w,
|
||||||
ThumbnailHeight: h,
|
ThumbnailHeight: h,
|
||||||
CustomProps: customProps,
|
CustomProps: customProps,
|
||||||
@@ -118,6 +127,47 @@ func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) {
|
|||||||
return &SiteConfig{
|
return &SiteConfig{
|
||||||
AppPromotion: appSetting.Promotion,
|
AppPromotion: appSetting.Promotion,
|
||||||
}, nil
|
}, nil
|
||||||
|
case "thumb":
|
||||||
|
// Return supported thumbnail extensions from enabled generators.
|
||||||
|
exts := map[string]bool{}
|
||||||
|
if settings.BuiltinThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range thumb.BuiltinSupportedExts {
|
||||||
|
exts[e] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.FFMpegThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.FFMpegThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.VipsThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.VipsThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.LibreOfficeThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.LibreOfficeThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.MusicCoverThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.MusicCoverThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.LibRawThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.LibRawThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// map -> sorted slice
|
||||||
|
result := make([]string, 0, len(exts))
|
||||||
|
for e := range exts {
|
||||||
|
result = append(result, e)
|
||||||
|
}
|
||||||
|
sort.Strings(result)
|
||||||
|
return &SiteConfig{ThumbExts: result}, nil
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs"
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/manager"
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/manager"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/manager/entitysource"
|
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/manager/entitysource"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/mediameta"
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
|
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@@ -135,8 +136,9 @@ func (s *SlaveMetaService) MediaMeta(c *gin.Context) ([]driver.MediaMeta, error)
|
|||||||
}
|
}
|
||||||
defer entitySource.Close()
|
defer entitySource.Close()
|
||||||
|
|
||||||
|
language := c.Query("language")
|
||||||
extractor := dep.MediaMetaExtractor(c)
|
extractor := dep.MediaMetaExtractor(c)
|
||||||
res, err := extractor.Extract(c, s.Ext, entitySource)
|
res, err := extractor.Extract(c, s.Ext, entitySource, mediameta.WithLanguage(language))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to extract media meta: %w", err)
|
return nil, fmt.Errorf("failed to extract media meta: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package share
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||||
@@ -25,7 +26,26 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *ShortLinkRedirectService) RedirectTo(c *gin.Context) string {
|
func (s *ShortLinkRedirectService) RedirectTo(c *gin.Context) string {
|
||||||
return routes.MasterShareLongUrl(s.ID, s.Password).String()
|
shareLongUrl := routes.MasterShareLongUrl(s.ID, s.Password)
|
||||||
|
|
||||||
|
shortLinkQuery := c.Request.URL.Query() // Query in ShortLink, adapt to Cloudreve V3
|
||||||
|
shareLongUrlQuery := shareLongUrl.Query()
|
||||||
|
|
||||||
|
userSpecifiedPath := shortLinkQuery.Get("path")
|
||||||
|
if userSpecifiedPath != "" {
|
||||||
|
masterPath := shareLongUrlQuery.Get("path")
|
||||||
|
masterPath += "/" + strings.TrimPrefix(userSpecifiedPath, "/")
|
||||||
|
|
||||||
|
shareLongUrlQuery.Set("path", masterPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
shortLinkQuery.Del("path") // 防止用户指定的 Path 就是空字符串
|
||||||
|
for k, vals := range shortLinkQuery {
|
||||||
|
shareLongUrlQuery[k] = append(shareLongUrlQuery[k], vals...)
|
||||||
|
}
|
||||||
|
|
||||||
|
shareLongUrl.RawQuery = shareLongUrlQuery.Encode()
|
||||||
|
return shareLongUrl.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
Reference in New Issue
Block a user