Skip to content

Commit 5c447e9

Browse files
authored
๐Ÿ”€ merge pull request #56 from GDG-on-Campus-KHU/feat/recording
๐Ÿ”€ merge branch 'feat/recording' into 'dev'
2 parents ae806f7 + a62f84b commit 5c447e9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

โ€Žrecording/recording_handler.goโ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ func SyncSttRecordingHandler(c *gin.Context) {
7878

7979

8080
// save with original file extension
81+
err = os.MkdirAll("tmp", os.ModePerm)
82+
if err != nil {
83+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create temp directory"})
84+
return
85+
}
86+
8187
ext := filepath.Ext(fileHeader.Filename)
8288
originalPath := fmt.Sprintf("tmp/%d%s", time.Now().Unix(), ext)
8389

โ€Žrecording/util/file_upload.goโ€Ž

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import (
99
"mime/multipart"
1010
"strings"
1111
"time"
12+
"regexp"
13+
"strconv"
1214

1315
"cloud.google.com/go/storage"
1416

1517
dbConfig "github.com/GDG-on-Campus-KHU/SDGP_team5_BE/db/config"
18+
coreUtil "github.com/GDG-on-Campus-KHU/SDGP_team5_BE/util"
1619
)
1720

1821
// GCS bucket์— ์Œ์„ฑ ๋…น์Œ ํŒŒ์ผ ์—…๋กœ๋“œํ•˜๊ณ  file URL์„ return
@@ -21,14 +24,26 @@ func UploadFileToGCS(file *multipart.FileHeader, userID string) (string, error)
2124
ctx := context.Background()
2225
client := dbConfig.GCSClient
2326

27+
id, err := strconv.Atoi(userID)
28+
if err != nil {
29+
return "", fmt.Errorf("invalid userID format: %v", err)
30+
}
31+
32+
user, err := coreUtil.GetUserByUserID(ctx, id)
33+
if err != nil {
34+
return "", fmt.Errorf("failed to get user info: %v", err)
35+
}
36+
37+
username := regexp.MustCompile(`[^๊ฐ€-ํžฃa-zA-Z0-9_-]`).ReplaceAllString(user.Name, "")
38+
2439
// GCS bucket
2540
bucketName := "resq-upload-bucket"
2641
bucket := client.Bucket(bucketName)
2742

2843
// unique filename generation rule
2944
ext := strings.ToLower(file.Filename[strings.LastIndex(file.Filename, "."):])
30-
timestamp := time.Now().Format("060102150405") // yyMMddhhmmss
31-
fileName := fmt.Sprintf("user_%s_%s%s", userID, timestamp, ext)
45+
timestamp := time.Now().Format("060102_150405") // yyMMdd_hhmmss
46+
fileName := fmt.Sprintf("%s_%s%s", username, timestamp, ext)
3247

3348
srcFile, err := file.Open()
3449
if err != nil {

0 commit comments

Comments
ย (0)