From 482516880a9c4c89030ebba0e65ff9667ca9728f Mon Sep 17 00:00:00 2001 From: Abhishek Raj Date: Tue, 7 Nov 2023 11:35:34 +0530 Subject: [PATCH] fix: replaced vid with file for abstraction of image and audio (#78) --- controllers/upload.go | 8 ++++---- utils/helper.go | 4 ++-- utils/helper_test.go | 4 ++-- utils/upload.go | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/controllers/upload.go b/controllers/upload.go index 879aeed..7870d52 100644 --- a/controllers/upload.go +++ b/controllers/upload.go @@ -14,17 +14,17 @@ func GetPresignedURL(c *gin.Context) { extension := filepath.Ext(fileName) if fileName == "" || extension == "" { - c.JSON(http.StatusBadRequest, gin.H{"error": "Missing required query parameter 'fileName' or it has no extension"}) + c.JSON(http.StatusBadRequest, gin.H{"error": "Missing required query parameter 'fileName' or 'fileName' without extension"}) return } - videoID := utils.VideoIDGen(extension) + fileID := utils.FileIDGen(extension) - url := utils.GetSignedURL(videoID, basePath) + url := utils.GetSignedURL(fileID, basePath) if url == "" { c.JSON(http.StatusInternalServerError, gin.H{"error": "Error generating presigned URL", "details": ""}) return } - c.JSON(http.StatusOK, gin.H{"preSignedURL": url, "videoID": videoID}) + c.JSON(http.StatusOK, gin.H{"preSignedURL": url, "fileID": fileID}) } diff --git a/utils/helper.go b/utils/helper.go index a3c86c2..f6f6507 100644 --- a/utils/helper.go +++ b/utils/helper.go @@ -8,10 +8,10 @@ import ( ) /* -VideoIDGen returns an unique videoID and appends the fileExtension to it, +FileIDGen returns an unique videoID and appends the fileExtension to it, it takes the fileExtensionas parameter */ -func VideoIDGen(fileExtension string) string { +func FileIDGen(fileExtension string) string { length := 8 randomBytes := make([]byte, length) diff --git a/utils/helper_test.go b/utils/helper_test.go index a8feb98..b1dad2b 100644 --- a/utils/helper_test.go +++ b/utils/helper_test.go @@ -7,10 +7,10 @@ import ( "github.com/stretchr/testify/assert" ) -func TestVideoIDGen(t *testing.T) { +func TestFileIDGen(t *testing.T) { // Call the Video ID Gen function - videoIDExt := VideoIDGen(".mp4") + videoIDExt := FileIDGen(".mp4") //Split the string into digits and ext videoID := strings.Split(videoIDExt, ".") diff --git a/utils/upload.go b/utils/upload.go index 2809884..08532b4 100644 --- a/utils/upload.go +++ b/utils/upload.go @@ -245,10 +245,10 @@ func GetWhichCloudIsEnabled() (bool, bool, bool) { return false, false, false } -func GetSignedURL(videoId string, basePath string) string { +func GetSignedURL(fileID string, basePath string) string { isAWS, isGCP, isAzure := GetWhichCloudIsEnabled() - filePath, err := GetCloudStoragePath(basePath, videoId) + filePath, err := GetCloudStoragePath(basePath, fileID) LogErr(err) if isAWS {