Skip to content

Commit

Permalink
feat: 七牛云备份账号支持设置超时时间 (#5745)
Browse files Browse the repository at this point in the history
Refs #4330
  • Loading branch information
john1298308460 authored Jul 10, 2024
1 parent 730a25f commit afd4c84
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
24 changes: 17 additions & 7 deletions backend/utils/cloud_storage/client/kodo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"strconv"
"time"

"github.com/1Panel-dev/1Panel/backend/utils/files"
Expand All @@ -10,25 +11,29 @@ import (
)

type kodoClient struct {
bucket string
domain string
auth *auth.Credentials
client *storage.BucketManager
bucket string
domain string
timeout string
auth *auth.Credentials
client *storage.BucketManager
}

func NewKodoClient(vars map[string]interface{}) (*kodoClient, error) {
accessKey := loadParamFromVars("accessKey", vars)
secretKey := loadParamFromVars("secretKey", vars)
bucket := loadParamFromVars("bucket", vars)
domain := loadParamFromVars("domain", vars)

timeout := loadParamFromVars("timeout", vars)
if timeout == "" {
timeout = "1"
}
conn := auth.New(accessKey, secretKey)
cfg := storage.Config{
UseHTTPS: false,
}
bucketManager := storage.NewBucketManager(conn, &cfg)

return &kodoClient{client: bucketManager, auth: conn, bucket: bucket, domain: domain}, nil
return &kodoClient{client: bucketManager, auth: conn, bucket: bucket, domain: domain, timeout: timeout}, nil
}

func (k kodoClient) ListBuckets() ([]interface{}, error) {
Expand Down Expand Up @@ -66,8 +71,13 @@ func (k kodoClient) Delete(path string) (bool, error) {
}

func (k kodoClient) Upload(src, target string) (bool, error) {

int64Value, _ := strconv.ParseInt(k.timeout, 10, 64)
unixTimestamp := int64Value * 3600

putPolicy := storage.PutPolicy{
Scope: k.bucket,
Scope: k.bucket,
Expires: uint64(unixTimestamp),
}
upToken := putPolicy.UploadToken(k.auth)
cfg := storage.Config{UseHTTPS: true, UseCdnDomains: false}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ const message = {
errPath: 'Backup path [{0}] error, cannot download!',
cutWebsiteLog: 'Cut Website Log',
cutWebsiteLogHelper: 'The cut log files will be backed up to the backup directory of 1Panel',

requestExpirationTime: 'Upload Request Expiration Time',
unitHours: 'Unit: Hours',
},
monitor: {
monitor: 'Monitor',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ const message = {
errPath: '備份路徑 [{0}] 錯誤無法下載!',
cutWebsiteLog: '切割網站日誌',
cutWebsiteLogHelper: '切割的日誌文件會備份到 1Panel backup 目錄下',

requestExpirationTime: '上傳請求過期時間',
unitHours: '單小時',
},
monitor: {
monitor: '監',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,9 @@ const message = {
errPath: '备份路径 [{0}] 错误无法下载!',
cutWebsiteLog: '切割网站日志',
cutWebsiteLogHelper: '切割的日志文件会备份到 1Panel backup 目录下',

requestExpirationTime: '上传请求过期时间',
unitHours: '单小时',
},
monitor: {
monitor: '监',
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/views/setting/backup-account/kodo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
</el-button>
<span v-if="errBuckets" class="input-error">{{ $t('commons.rule.requiredSelect') }}</span>
</el-form-item>

<el-form-item :label="$t('cronjob.requestExpirationTime')" prop="varsJson.timeout">
<el-input-number
style="width: 200px"
:min="1"
step-strictly
:step="1"
v-model.number="kodoData.rowData!.varsJson['timeout']"
></el-input-number>
<span class="input-help">{{ $t('cronjob.unitHours') }}</span>
</el-form-item>

<el-form-item :label="$t('setting.backupDir')" prop="backupPath">
<el-input clearable v-model.trim="kodoData.rowData!.backupPath" placeholder="/1panel" />
</el-form-item>
Expand Down Expand Up @@ -107,6 +119,9 @@ const acceptParams = (params: DialogProps): void => {
domainProto.value = httpItem.proto;
}
title.value = i18n.global.t('commons.button.' + kodoData.value.title);
if (kodoData.value.rowData!.varsJson['timeout'] === undefined) {
kodoData.value.rowData!.varsJson['timeout'] = 1;
}
drawerVisible.value = true;
};
Expand Down

0 comments on commit afd4c84

Please sign in to comment.