Skip to content

Commit

Permalink
fix: replaced vid with file for abstraction of image and audio (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
abskrj authored Nov 7, 2023
1 parent 8b08eb9 commit 4825168
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions controllers/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
4 changes: 2 additions & 2 deletions utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions utils/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ".")
Expand Down
4 changes: 2 additions & 2 deletions utils/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4825168

Please sign in to comment.