fix: use default chunk size if it is set as 0

pull/1217/head
HFO4 3 years ago
parent 3804efd792
commit 4f65d0e859

@ -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_file_suffix", Value: "._thumb", Type: "thumb"},
{Name: "thumb_max_task_count", Value: "-1", Type: "thumb"}, {Name: "thumb_max_task_count", Value: "-1", Type: "thumb"},
{Name: "thumb_encode_method", Value: "jpg", 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: "thumb_encode_quality", Value: "85", Type: "thumb"},
{Name: "pwa_small_icon", Value: "/static/img/favicon.ico", Type: "pwa"}, {Name: "pwa_small_icon", Value: "/static/img/favicon.ico", Type: "pwa"},
{Name: "pwa_medium_icon", Value: "/static/img/logo192.png", Type: "pwa"}, {Name: "pwa_medium_icon", Value: "/static/img/logo192.png", Type: "pwa"},

@ -77,6 +77,9 @@ func addDefaultPolicy() {
DirNameRule: "uploads/{uid}/{path}", DirNameRule: "uploads/{uid}/{path}",
FileNameRule: "{uid}_{randomkey8}_{originname}", FileNameRule: "{uid}_{randomkey8}_{originname}",
IsOriginLinkEnable: false, IsOriginLinkEnable: false,
OptionsSerialized: PolicyOption{
ChunkSize: 25 << 20, // 25MB
},
} }
if err := DB.Create(&defaultPolicy).Error; err != nil { if err := DB.Create(&defaultPolicy).Error; err != nil {
util.Log().Panic("无法创建初始存储策略, %s", err) util.Log().Panic("无法创建初始存储策略, %s", err)

@ -30,6 +30,10 @@ type Driver struct {
// NewDriver 从存储策略初始化新的Driver实例 // NewDriver 从存储策略初始化新的Driver实例
func NewDriver(policy *model.Policy) (driver.Handler, error) { func NewDriver(policy *model.Policy) (driver.Handler, error) {
client, err := NewClient(policy) client, err := NewClient(policy)
if policy.OptionsSerialized.ChunkSize == 0 {
policy.OptionsSerialized.ChunkSize = 50 << 20 // 50MB
}
return Driver{ return Driver{
Policy: policy, Policy: policy,
Client: client, Client: client,

@ -57,6 +57,10 @@ const (
) )
func NewDriver(policy *model.Policy) (*Driver, error) { func NewDriver(policy *model.Policy) (*Driver, error) {
if policy.OptionsSerialized.ChunkSize == 0 {
policy.OptionsSerialized.ChunkSize = 25 << 20 // 25 MB
}
driver := &Driver{ driver := &Driver{
Policy: policy, Policy: policy,
HTTPClient: request.NewClient(), HTTPClient: request.NewClient(),

@ -30,6 +30,10 @@ type Driver struct {
} }
func NewDriver(policy *model.Policy) *Driver { 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) mac := qbox.NewMac(policy.AccessKey, policy.SecretKey)
cfg := &storage.Config{UseHTTPS: true} cfg := &storage.Config{UseHTTPS: true}
return &Driver{ return &Driver{

@ -47,6 +47,10 @@ type MetaData struct {
} }
func NewDriver(policy *model.Policy) (*Driver, error) { func NewDriver(policy *model.Policy) (*Driver, error) {
if policy.OptionsSerialized.ChunkSize == 0 {
policy.OptionsSerialized.ChunkSize = 25 << 20 // 25 MB
}
driver := &Driver{ driver := &Driver{
Policy: policy, Policy: policy,
} }

Loading…
Cancel
Save