From 4f65d0e859b1d1c9dfd02067daa64f0b33271731 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Tue, 19 Apr 2022 19:41:03 +0800 Subject: [PATCH] fix: use default chunk size if it is set as 0 --- models/defaults.go | 2 +- models/migration.go | 3 +++ pkg/filesystem/driver/onedrive/handler.go | 4 ++++ pkg/filesystem/driver/oss/handler.go | 4 ++++ pkg/filesystem/driver/qiniu/handler.go | 4 ++++ pkg/filesystem/driver/s3/handler.go | 4 ++++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/models/defaults.go b/models/defaults.go index b505da2..22f68f1 100644 --- a/models/defaults.go +++ b/models/defaults.go @@ -105,7 +105,7 @@ Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; verti {Name: "thumb_file_suffix", Value: "._thumb", Type: "thumb"}, {Name: "thumb_max_task_count", Value: "-1", Type: "thumb"}, {Name: "thumb_encode_method", Value: "jpg", Type: "thumb"}, - {Name: "thumb_gc_after_gen", Value: "false", Type: "thumb"}, + {Name: "thumb_gc_after_gen", Value: "0", Type: "thumb"}, {Name: "thumb_encode_quality", Value: "85", Type: "thumb"}, {Name: "pwa_small_icon", Value: "/static/img/favicon.ico", Type: "pwa"}, {Name: "pwa_medium_icon", Value: "/static/img/logo192.png", Type: "pwa"}, diff --git a/models/migration.go b/models/migration.go index d3ba8df..ac36d32 100644 --- a/models/migration.go +++ b/models/migration.go @@ -77,6 +77,9 @@ func addDefaultPolicy() { DirNameRule: "uploads/{uid}/{path}", FileNameRule: "{uid}_{randomkey8}_{originname}", IsOriginLinkEnable: false, + OptionsSerialized: PolicyOption{ + ChunkSize: 25 << 20, // 25MB + }, } if err := DB.Create(&defaultPolicy).Error; err != nil { util.Log().Panic("无法创建初始存储策略, %s", err) diff --git a/pkg/filesystem/driver/onedrive/handler.go b/pkg/filesystem/driver/onedrive/handler.go index 8e8dacb..8eec3b3 100644 --- a/pkg/filesystem/driver/onedrive/handler.go +++ b/pkg/filesystem/driver/onedrive/handler.go @@ -30,6 +30,10 @@ type Driver struct { // NewDriver 从存储策略初始化新的Driver实例 func NewDriver(policy *model.Policy) (driver.Handler, error) { client, err := NewClient(policy) + if policy.OptionsSerialized.ChunkSize == 0 { + policy.OptionsSerialized.ChunkSize = 50 << 20 // 50MB + } + return Driver{ Policy: policy, Client: client, diff --git a/pkg/filesystem/driver/oss/handler.go b/pkg/filesystem/driver/oss/handler.go index b0b55d2..2db88b6 100644 --- a/pkg/filesystem/driver/oss/handler.go +++ b/pkg/filesystem/driver/oss/handler.go @@ -57,6 +57,10 @@ const ( ) func NewDriver(policy *model.Policy) (*Driver, error) { + if policy.OptionsSerialized.ChunkSize == 0 { + policy.OptionsSerialized.ChunkSize = 25 << 20 // 25 MB + } + driver := &Driver{ Policy: policy, HTTPClient: request.NewClient(), diff --git a/pkg/filesystem/driver/qiniu/handler.go b/pkg/filesystem/driver/qiniu/handler.go index 22a97d0..3fed572 100644 --- a/pkg/filesystem/driver/qiniu/handler.go +++ b/pkg/filesystem/driver/qiniu/handler.go @@ -30,6 +30,10 @@ type Driver struct { } func NewDriver(policy *model.Policy) *Driver { + if policy.OptionsSerialized.ChunkSize == 0 { + policy.OptionsSerialized.ChunkSize = 25 << 20 // 25 MB + } + mac := qbox.NewMac(policy.AccessKey, policy.SecretKey) cfg := &storage.Config{UseHTTPS: true} return &Driver{ diff --git a/pkg/filesystem/driver/s3/handler.go b/pkg/filesystem/driver/s3/handler.go index ba9ce60..cc47993 100644 --- a/pkg/filesystem/driver/s3/handler.go +++ b/pkg/filesystem/driver/s3/handler.go @@ -47,6 +47,10 @@ type MetaData struct { } func NewDriver(policy *model.Policy) (*Driver, error) { + if policy.OptionsSerialized.ChunkSize == 0 { + policy.OptionsSerialized.ChunkSize = 25 << 20 // 25 MB + } + driver := &Driver{ Policy: policy, }