MCPcopy
hub / github.com/daptin/daptin / handleGetPartPresignedURL

Function handleGetPartPresignedURL

server/asset_upload_handler.go:641–715  ·  view source on GitHub ↗

handleGetPartPresignedURL generates a presigned URL for a specific part in multipart upload

(c *gin.Context, assetCache *assetcachepojo.AssetFolderCache)

Source from the content-addressed store, hash-verified

639
640// handleGetPartPresignedURL generates a presigned URL for a specific part in multipart upload
641func handleGetPartPresignedURL(c *gin.Context, assetCache *assetcachepojo.AssetFolderCache) {
642 uploadId := c.Query("upload_id")
643 partNumberStr := c.Query("part_number")
644
645 if uploadId == "" || partNumberStr == "" {
646 c.AbortWithError(400, fmt.Errorf("upload_id and part_number are required"))
647 return
648 }
649
650 partNumber, err := strconv.ParseInt(partNumberStr, 10, 32)
651 if err != nil {
652 c.AbortWithError(400, fmt.Errorf("invalid part_number: %v", err))
653 return
654 }
655
656 // Check if this is S3 storage
657 if assetCache.Credentials == nil {
658 c.AbortWithError(400, fmt.Errorf("presigned URLs not supported for this storage type"))
659 return
660 }
661
662 providerType, ok := assetCache.Credentials["type"].(string)
663 if !ok || providerType != "s3" {
664 c.AbortWithError(400, fmt.Errorf("presigned URLs only supported for S3 storage"))
665 return
666 }
667
668 // Extract bucket and key
669 rootPath := assetCache.CloudStore.RootPath
670 fileName := c.Query("filename")
671 if fileName == "" {
672 c.AbortWithError(400, fmt.Errorf("filename is required"))
673 return
674 }
675
676 keyPath := assetCache.Keyname + "/" + fileName
677
678 // Parse bucket name
679 bucketName := ""
680 if strings.Contains(rootPath, ":") {
681 parts := strings.Split(rootPath, ":")
682 if len(parts) >= 2 {
683 bucketName = strings.TrimPrefix(parts[1], "/")
684 if strings.Contains(bucketName, "/") {
685 pathParts := strings.SplitN(bucketName, "/", 2)
686 bucketName = pathParts[0]
687 if len(pathParts) > 1 {
688 keyPath = pathParts[1] + "/" + keyPath
689 }
690 }
691 }
692 }
693
694 if bucketName == "" {
695 c.AbortWithError(500, fmt.Errorf("could not extract bucket name"))
696 return
697 }
698

Callers 1

AssetUploadHandlerFunction · 0.85

Calls 3

GetS3PartPresignedURLFunction · 0.85
QueryMethod · 0.80
AddMethod · 0.80

Tested by

no test coverage detected