Skip to content

Commit

Permalink
feat: Update git modules and add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
afifurrohman-id committed Dec 5, 2023
1 parent f96abd4 commit 199dd8c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/files/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func HandleDeleteAllFile(ctx *fiber.Ctx) error {
})
}

//TODO: More efficient way to delete all files
for _, fileData := range filesData {
internal.Check(store.DeleteObject(storeCtx, fileData.Name))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/files/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func HandleGetFileData(ctx *fiber.Ctx) error {
Description: fmt.Sprintf("File: %s, Is Not Found", fileName),
})
}
internal.Check(err)
log.Panic(err)
}

store.Format(fileData)
Expand Down
6 changes: 3 additions & 3 deletions cmd/files/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package middleware

import (
"fmt"
"github.com/afifurrohman-id/tempsy/internal"
"github.com/afifurrohman-id/tempsy/internal/auth"
"github.com/afifurrohman-id/tempsy/internal/auth/guest"
"github.com/afifurrohman-id/tempsy/internal/auth/oauth2"
"github.com/afifurrohman-id/tempsy/internal/models"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/gofiber/fiber/v2/middleware/cors"
"golang.org/x/exp/slices"
"strings"
Expand Down Expand Up @@ -38,14 +38,14 @@ func CheckAuth(ctx *fiber.Ctx) error {
if err == nil && tokenMap["jti"] == username {
return ctx.Next()
}
log.Error(err)
internal.LogErr(err)
} else {
accountInfo, err := oauth2.GetGoogleAccountInfo(strings.TrimPrefix(authToken, auth.BearerPrefix))

if err == nil && username == accountInfo.UserName && accountInfo.VerifiedEmail {
return ctx.Next()
}
log.Error(err)
internal.LogErr(err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/files/middleware/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func PurgeAnonymousAccount(ctx *fiber.Ctx) error {
)

if strings.HasPrefix(username, guest.UsernamePrefix) {
if lU := strings.SplitN(username, "-", 3); len(lU) > 2 {
autoDeletedAccount, err := strconv.ParseInt(lU[1], 10, 64)
if nameSplit := strings.SplitN(username, "-", 3); len(nameSplit) > 2 {
autoDeletedAccount, err := strconv.ParseInt(nameSplit[1], 10, 64)
if err == nil {
if autoDeletedAccount < time.Now().UnixMilli() {
timeout := 15 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion cmd/files/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func HandleUpdateFile(ctx *fiber.Ctx) error {
Description: fmt.Sprintf("File %s Is Not Found", fileName),
})
}
internal.Check(err)
log.Panic(err)
}

if !strings.Contains(file.ContentType, ctx.Get(fiber.HeaderContentType)) {
Expand Down
3 changes: 3 additions & 0 deletions cmd/files/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/afifurrohman-id/tempsy/internal/models"
store "github.com/afifurrohman-id/tempsy/internal/storage"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"strings"
)

Expand Down Expand Up @@ -47,6 +48,8 @@ func HandleGetUserInfo(ctx *fiber.Ctx) error {
if claims, err := guest.ParseToken(token); err == nil {
userinfo.UserName = claims["jti"].(string)
} else {
log.Error(err)

goUser, err := oauth2.GetGoogleAccountInfo(token)
if err != nil {
return ctx.Status(fiber.StatusBadRequest).JSON(&models.ApiError{
Expand Down

0 comments on commit 199dd8c

Please sign in to comment.