Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lint issue and unused var #77

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: lint issue and unused var
  • Loading branch information
abskrj committed Oct 28, 2023
commit 084b12af799ec0bfe762d4262a99b0ccbff8b9a4
7 changes: 3 additions & 4 deletions controllers/upload.go
Original file line number Diff line number Diff line change
@@ -10,18 +10,17 @@ 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 it has no extension"})
return
}

videoID := utils.VideoIDGen(extension)

url := utils.GetSignedURL(videoID, fileType, basePath)
url := utils.GetSignedURL(videoID, basePath)
if url == "" {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error generating presigned URL", "details": ""})
return
9 changes: 4 additions & 5 deletions utils/helper.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,9 @@ package utils

import (
"bytes"
"crypto/rand"
"encoding/binary"
"log"
math_rand "math/rand"
"math/rand"
"strconv"
)

@@ -19,11 +18,11 @@ func VideoIDGen(fileExtension string) string {
return err.Error()
}

var i int64 = int64(binary.LittleEndian.Uint64(b[:]))
math_rand.Seed(i)
seed := int64(binary.LittleEndian.Uint64(b[:]))
r := rand.New(rand.NewSource(seed))

// Generate a 8 digit random number
randomNumber := math_rand.Intn(99999999-10000000) + 10000000
randomNumber := r.Intn(99999999-10000000) + 10000000

// VideoID = (8-digit random number) + (file Name)
return strconv.Itoa(randomNumber) + fileExtension
6 changes: 3 additions & 3 deletions utils/upload.go
Original file line number Diff line number Diff line change
@@ -245,10 +245,10 @@ func GetWhichCloudIsEnabled() (bool, bool, bool) {
return false, false, false
}

func GetSignedURL(videoId string, fileType string, basePath string) string {
func GetSignedURL(videoId string, basePath string) string {
isAWS, isGCP, isAzure := GetWhichCloudIsEnabled()

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

if isAWS {
@@ -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)