feat: 腾讯 COS 支持大文件分片上传 (#2772)

pull/2773/head^2
ssongliu 2023-11-02 14:29:46 +08:00 committed by GitHub
parent 05029a3eda
commit 2d8a7bbbc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"github.com/1Panel-dev/1Panel/backend/constant"
cosSDK "github.com/tencentyun/cos-go-sdk-v5"
@ -97,6 +98,27 @@ func (cos cosClient) Upload(src, target string) (bool, error) {
if err != nil {
return false, err
}
fileInfo, err := os.Stat(src)
if err != nil {
return false, err
}
if fileInfo.Size() > 5368709120 {
opt := &cosSDK.MultiUploadOptions{
OptIni: &cosSDK.InitiateMultipartUploadOptions{
ACLHeaderOptions: nil,
ObjectPutHeaderOptions: &cosSDK.ObjectPutHeaderOptions{
XCosStorageClass: cos.scType,
},
},
PartSize: 200,
}
if _, _, err := client.Object.MultiUpload(
context.Background(), target, src, opt,
); err != nil {
return false, err
}
return true, nil
}
if _, err := client.Object.PutFromFile(context.Background(), target, src, &cosSDK.ObjectPutOptions{
ACLHeaderOptions: nil,
ObjectPutHeaderOptions: &cosSDK.ObjectPutHeaderOptions{

View File

@ -144,7 +144,7 @@ func TestAppToV2(t *testing.T) {
}
_ = fileOp.DeleteFile(newVersionDir + "/config.json")
oldReadMefile := newVersionDir + "/README.md"
_ = fileOp.Cut([]string{oldReadMefile}, newAppDir)
// _ = fileOp.Cut([]string{oldReadMefile}, newAppDir)
_ = fileOp.DeleteFile(oldReadMefile)
}
}

View File

@ -42,6 +42,9 @@
{{ loadZero(dialogData.rowData?.hour) }} :
{{ loadZero(dialogData.rowData?.minute) }}
</span>
<span v-if="dialogData.rowData?.specType === 'perDay'">
{{ loadZero(dialogData.rowData?.hour) }} : {{ loadZero(dialogData.rowData?.minute) }}
</span>
<span v-if="dialogData.rowData?.specType === 'perWeek'">
{{ loadWeek(dialogData.rowData?.week) }}&nbsp; {{ loadZero(dialogData.rowData?.hour) }} :
{{ loadZero(dialogData.rowData?.minute) }}
@ -127,7 +130,13 @@
<el-row :gutter="20" v-show="hasRecords" class="mainRowClass">
<el-col :span="6">
<div class="infinite-list" style="overflow: auto">
<el-table :data="records" border :show-header="false" @row-click="forDetail">
<el-table
style="cursor: pointer"
:data="records"
border
:show-header="false"
@row-click="forDetail"
>
<el-table-column>
<template #default="{ row }">
<span v-if="row.id === currentRecord.id" class="select-sign"></span>