Skip to content

Commit

Permalink
fix: Incorrect file name params, should be use header instead
Browse files Browse the repository at this point in the history
  • Loading branch information
afifurrohman-id committed Dec 28, 2023
1 parent 24bf523 commit a420fcd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cmd/files/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func HandleUploadFile(ctx *fiber.Ctx) error {
var (
storeCtx = context.Background()
username = ctx.Params("username")
filePath = fmt.Sprintf("%s/%s", username, ctx.Get(store.HeaderFileName))
fileName = ctx.Get(store.HeaderFileName)
filePath = fmt.Sprintf("%s/%s", username, fileName)
)

storeCtx, cancel := context.WithTimeout(storeCtx, store.DefaultTimeoutCtx)
Expand All @@ -44,7 +45,7 @@ func HandleUploadFile(ctx *fiber.Ctx) error {
})
}

match, err := regexp.MatchString(`^[a-zA-Z0-9_-]+\.+[a-zA-Z0-9_-]+$`, ctx.Get(store.HeaderFileName))
match, err := regexp.MatchString(`^[a-zA-Z0-9_-]+\.+[a-zA-Z0-9_-]+$`, fileName)
internal.Check(err)

if !match {
Expand Down Expand Up @@ -103,7 +104,7 @@ func HandleUploadFile(ctx *fiber.Ctx) error {

return ctx.Status(fiber.StatusConflict).JSON(&models.ApiError{
Type: internal.ErrorTypeFileExists,
Description: fmt.Sprintf("File: %s Already Exists", ctx.Params("filename")),
Description: fmt.Sprintf("File: %s Already Exists", fileName),
})
}

Expand Down

0 comments on commit a420fcd

Please sign in to comment.