Skip to content

Commit

Permalink
fix: replaced vid with file for abstraction of image and audio
Browse files Browse the repository at this point in the history
  • Loading branch information
abskrj committed Nov 4, 2023
1 parent a680fcd commit 7c808e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions controllers/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ import (

func GetPresignedURL(c *gin.Context) {
fileName := c.Query("fileName")
fileType := c.Query("fileType")
basePath := c.Query("basePath")
extension := filepath.Ext(fileName)

if fileName == "" || extension == "" || fileType == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Missing required query parameter 'fileName' or 'fileType'"})
if fileName == "" || 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, fileType, 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})
}
2 changes: 1 addition & 1 deletion utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
VideoIDGen 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 {
var b [8]byte
if _, err := rand.Read(b[:]); err != nil {
return err.Error()
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
6 changes: 3 additions & 3 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, fileType string, basePath string) string {
func GetSignedURL(fileID string, basePath string) string {
isAWS, isGCP, isAzure := GetWhichCloudIsEnabled()

filePath, err := GetCloudStoragePath(basePath, videoId, fileType)
filePath, err := GetCloudStoragePath(basePath, fileID)
LogErr(err)

if isAWS {
Expand Down Expand Up @@ -352,7 +352,7 @@ func generateAzureSignedURL(filePath string) string {
return sasURL
}

func GetCloudStoragePath(basePath, fileName string, _ string) (string, error) {
func GetCloudStoragePath(basePath, fileName string) (string, error) {
url, err := url.JoinPath(basePath, fileName)
LogErr(err)

Expand Down

0 comments on commit 7c808e7

Please sign in to comment.