| @@ -2,6 +2,7 @@ package storage | |||||
| import ( | import ( | ||||
| "encoding/xml" | "encoding/xml" | ||||
| "errors" | |||||
| "path" | "path" | ||||
| "sort" | "sort" | ||||
| "strconv" | "strconv" | ||||
| @@ -129,7 +130,7 @@ func NewMultiPartUpload(uuid string) (string, error) { | |||||
| return core.NewMultipartUpload(bucketName, objectName, miniov6.PutObjectOptions{}) | return core.NewMultipartUpload(bucketName, objectName, miniov6.PutObjectOptions{}) | ||||
| } | } | ||||
| func CompleteMultiPartUpload(uuid string, uploadID string) (string, error) { | |||||
| func CompleteMultiPartUpload(uuid string, uploadID string, totalChunks int) (string, error) { | |||||
| client, core, err := getClients() | client, core, err := getClients() | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("getClients failed:", err.Error()) | log.Error("getClients failed:", err.Error()) | ||||
| @@ -146,6 +147,11 @@ func CompleteMultiPartUpload(uuid string, uploadID string) (string, error) { | |||||
| return "", err | return "", err | ||||
| } | } | ||||
| if len(partInfos) != totalChunks { | |||||
| log.Error("ListObjectParts number(%d) is not equal the set total chunk number(%d)", len(partInfos), totalChunks) | |||||
| return "", errors.New("the parts is not complete") | |||||
| } | |||||
| var complMultipartUpload completeMultipartUpload | var complMultipartUpload completeMultipartUpload | ||||
| for _, partInfo := range partInfos { | for _, partInfo := range partInfos { | ||||
| complMultipartUpload.Parts = append(complMultipartUpload.Parts, miniov6.CompletePart{ | complMultipartUpload.Parts = append(complMultipartUpload.Parts, miniov6.CompletePart{ | ||||
| @@ -85,7 +85,7 @@ func listAllParts(uuid, uploadID, key string) (output *obs.ListPartsOutput, err | |||||
| }) | }) | ||||
| } | } | ||||
| if len(temp.Parts) < temp.MaxParts { | |||||
| if !temp.IsTruncated { | |||||
| break | break | ||||
| } else { | } else { | ||||
| continue | continue | ||||
| @@ -128,7 +128,7 @@ func NewObsMultiPartUpload(uuid, fileName string) (string, error) { | |||||
| return output.UploadId, nil | return output.UploadId, nil | ||||
| } | } | ||||
| func CompleteObsMultiPartUpload(uuid, uploadID, fileName string) error { | |||||
| func CompleteObsMultiPartUpload(uuid, uploadID, fileName string, totalChunks int) error { | |||||
| input := &obs.CompleteMultipartUploadInput{} | input := &obs.CompleteMultipartUploadInput{} | ||||
| input.Bucket = setting.Bucket | input.Bucket = setting.Bucket | ||||
| input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/") | input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/") | ||||
| @@ -140,6 +140,11 @@ func CompleteObsMultiPartUpload(uuid, uploadID, fileName string) error { | |||||
| return err | return err | ||||
| } | } | ||||
| if len(allParts.Parts) != totalChunks { | |||||
| log.Error("listAllParts number(%d) is not equal the set total chunk number(%d)", len(allParts.Parts), totalChunks) | |||||
| return errors.New("the parts is not complete") | |||||
| } | |||||
| input.Parts = allParts.Parts | input.Parts = allParts.Parts | ||||
| output, err := ObsCli.CompleteMultipartUpload(input) | output, err := ObsCli.CompleteMultipartUpload(input) | ||||
| @@ -855,13 +855,13 @@ func CompleteMultipart(ctx *context.Context) { | |||||
| } | } | ||||
| if typeCloudBrain == models.TypeCloudBrainOne { | if typeCloudBrain == models.TypeCloudBrainOne { | ||||
| _, err = storage.CompleteMultiPartUpload(uuid, uploadID) | |||||
| _, err = storage.CompleteMultiPartUpload(uuid, uploadID, fileChunk.TotalChunks) | |||||
| if err != nil { | if err != nil { | ||||
| ctx.Error(500, fmt.Sprintf("CompleteMultiPartUpload failed: %v", err)) | ctx.Error(500, fmt.Sprintf("CompleteMultiPartUpload failed: %v", err)) | ||||
| return | return | ||||
| } | } | ||||
| } else { | } else { | ||||
| err = storage.CompleteObsMultiPartUpload(uuid, uploadID, fileName) | |||||
| err = storage.CompleteObsMultiPartUpload(uuid, uploadID, fileName, fileChunk.TotalChunks) | |||||
| if err != nil { | if err != nil { | ||||
| ctx.Error(500, fmt.Sprintf("CompleteObsMultiPartUpload failed: %v", err)) | ctx.Error(500, fmt.Sprintf("CompleteObsMultiPartUpload failed: %v", err)) | ||||
| return | return | ||||
| @@ -34,7 +34,6 @@ import { | |||||
| } from './features/notification.js'; | } from './features/notification.js'; | ||||
| import {createCodeEditor} from './features/codeeditor.js'; | import {createCodeEditor} from './features/codeeditor.js'; | ||||
| import MinioUploader from './components/MinioUploader.vue'; | import MinioUploader from './components/MinioUploader.vue'; | ||||
| import ObsUploader from './components/ObsUploader.vue'; | |||||
| import EditAboutInfo from './components/EditAboutInfo.vue'; | import EditAboutInfo from './components/EditAboutInfo.vue'; | ||||
| // import Images from './components/Images.vue'; | // import Images from './components/Images.vue'; | ||||
| import EditTopics from './components/EditTopics.vue'; | import EditTopics from './components/EditTopics.vue'; | ||||
| @@ -2958,7 +2957,6 @@ $(document).ready(async () => { | |||||
| initCodeView(); | initCodeView(); | ||||
| initVueApp(); | initVueApp(); | ||||
| initVueUploader(); | initVueUploader(); | ||||
| initObsUploader(); | |||||
| initVueDataset(); | initVueDataset(); | ||||
| initVueEditAbout(); | initVueEditAbout(); | ||||
| initVueEditTopic(); | initVueEditTopic(); | ||||
| @@ -3854,8 +3852,7 @@ function initVueDataset() { | |||||
| }, | }, | ||||
| }, | }, | ||||
| components: { | components: { | ||||
| MinioUploader, | |||||
| ObsUploader | |||||
| MinioUploader | |||||
| }, | }, | ||||
| mounted(){ | mounted(){ | ||||
| // if(document.getElementById('postPath')){ | // if(document.getElementById('postPath')){ | ||||
| @@ -4380,19 +4377,6 @@ function initVueDataAnalysis() { | |||||
| render: h => h(DataAnalysis) | render: h => h(DataAnalysis) | ||||
| }); | }); | ||||
| } | } | ||||
| // 新增 | |||||
| function initObsUploader() { | |||||
| const el = document.getElementById('obsUploader'); | |||||
| if (!el) { | |||||
| return; | |||||
| } | |||||
| new Vue({ | |||||
| el: '#obsUploader', | |||||
| components: {ObsUploader}, | |||||
| template: '<ObsUploader />' | |||||
| }); | |||||
| } | |||||
| function initVueWxAutorize() { | function initVueWxAutorize() { | ||||
| const el = document.getElementById('WxAutorize'); | const el = document.getElementById('WxAutorize'); | ||||
| if (!el) { | if (!el) { | ||||