Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
make lint
make format
pnpm lint-staged
2 changes: 1 addition & 1 deletion api/pkg/handlers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (h *AccountHandler) getAccounts(w http.ResponseWriter, r *http.Request) {
storageQuota, err := provider.GetStorageQuota(
r.Context(),
userID,
&account.ID,
account.ID,
account.AccessToken,
account.RefreshToken,
)
Expand Down
25 changes: 16 additions & 9 deletions api/pkg/handlers/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (h *FilesHandler) RegisterRoutes() *chi.Mux {

r.Post("/create-folder", h.createFolder)

r.Put("/move-to-trash", h.moveFilesToTrash)
r.Patch("/move-to-trash", h.moveFilesToTrash)

r.Delete("/permanent-delete-files", h.permanentlyDelete)

Expand Down Expand Up @@ -356,6 +356,7 @@ func (h *FilesHandler) uploadFilesToProvider(w http.ResponseWriter, r *http.Requ

return
}
defer conn.Release()

queries := repository.New(conn)

Expand Down Expand Up @@ -390,7 +391,7 @@ func (h *FilesHandler) uploadFilesToProvider(w http.ResponseWriter, r *http.Requ
return
}

err = provider.UploadFiles(r.Context(), accountID, conn, queries, authTokens, uploadedFiles)
err = provider.UploadFiles(r.Context(), *accountID, conn, queries, authTokens, uploadedFiles)
if err != nil {
config.LOGGER.Error(
"failed to upload files",
Expand All @@ -407,7 +408,11 @@ func (h *FilesHandler) uploadFilesToProvider(w http.ResponseWriter, r *http.Requ
return
}

utils.SendAPIResponse(w, http.StatusOK, "files uploaded successfully")
utils.SendAPIResponse(
w,
http.StatusOK,
map[string]string{"message": "Successfully upload your file(s)!"},
)
}

func (h *FilesHandler) createFolder(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -523,7 +528,7 @@ func (h *FilesHandler) createFolder(w http.ResponseWriter, r *http.Request) {

provider := providers.OAuthProviders[string(account.Provider)]

err = provider.CreateFolder(r.Context(), payload.Name, parentFolder, account, conn, *queries)
err = provider.CreateFolder(r.Context(), payload.Name, parentFolder, account, conn, queries)
if err != nil {
config.LOGGER.Error("failed to create new folder", zap.Error(err))
utils.SendAPIErrorResponse(
Expand All @@ -538,7 +543,7 @@ func (h *FilesHandler) createFolder(w http.ResponseWriter, r *http.Request) {
utils.SendAPIResponse(
w,
http.StatusOK,
map[string]string{"message": "Your folder was successfully created"},
map[string]string{"message": "Your folder was successfully created!"},
)
}

Expand Down Expand Up @@ -590,6 +595,7 @@ func (h *FilesHandler) moveFilesToTrash(w http.ResponseWriter, r *http.Request)

return
}
defer conn.Release()

queries := repository.New(conn)

Expand Down Expand Up @@ -631,7 +637,7 @@ func (h *FilesHandler) moveFilesToTrash(w http.ResponseWriter, r *http.Request)

provider := providers.OAuthProviders[string(providerName)]

err = provider.MoveToTrash(r.Context(), &accountID, conn, queries, authTokens, items)
err = provider.MoveToTrash(r.Context(), accountID, conn, queries, authTokens, items)
if err != nil {
config.LOGGER.Error(
"failed to move file ids for move to trash action",
Expand All @@ -649,7 +655,7 @@ func (h *FilesHandler) moveFilesToTrash(w http.ResponseWriter, r *http.Request)
}

utils.SendAPIResponse(w, http.StatusOK, map[string]any{
"message": "Files successfully moved to trash",
"message": "Files successfully moved to trash.",
})
}

Expand Down Expand Up @@ -701,6 +707,7 @@ func (h *FilesHandler) permanentlyDelete(w http.ResponseWriter, r *http.Request)

return
}
defer conn.Release()

queries := repository.New(conn)

Expand Down Expand Up @@ -744,7 +751,7 @@ func (h *FilesHandler) permanentlyDelete(w http.ResponseWriter, r *http.Request)

err = provider.PermanentlyDeleteFiles(
r.Context(),
&accountID,
accountID,
conn,
queries,
authTokens,
Expand All @@ -767,7 +774,7 @@ func (h *FilesHandler) permanentlyDelete(w http.ResponseWriter, r *http.Request)
}

utils.SendAPIResponse(w, http.StatusOK, map[string]any{
"message": "Files successfully deleted",
"message": "File(s) successfully deleted.",
})
}

Expand Down
32 changes: 16 additions & 16 deletions api/pkg/handlers/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func (h *LinkHandler) linkAccountCallback(w http.ResponseWriter, r *http.Request
token, userId, accountInfo, err := provider.GetToken(w, r, store)
if err != nil {
h.logAndRedirectError(w, r, "GetToken failed", providerName, err)

return
}

Expand All @@ -197,7 +196,6 @@ func (h *LinkHandler) linkAccountCallback(w http.ResponseWriter, r *http.Request
conn, err := h.connPool.Acquire(r.Context())
if err != nil {
h.logAndRedirectError(w, r, "failed to acquire connection", providerName, err)

return
}
defer conn.Release()
Expand All @@ -210,13 +208,11 @@ func (h *LinkHandler) linkAccountCallback(w http.ResponseWriter, r *http.Request
)
if err != nil {
h.logAndRedirectError(w, r, "account upsert failed", providerName, err)

return
}

if err = h.scheduleBackgroundJobs(r.Context(), userId, providerName, accountID, token, queries); err != nil {
h.logAndRedirectError(w, r, "scheduling jobs failed", providerName, err)

if err = h.scheduleBackgroundTasks(r.Context(), userId, providerName, accountID, token, queries); err != nil {
h.logAndRedirectError(w, r, "scheduling tasks failed", providerName, err)
return
}

Expand All @@ -243,7 +239,7 @@ func (h *LinkHandler) logAndRedirectError(
h.errorRedirect(w, r)
}

func (h *LinkHandler) scheduleBackgroundJobs(
func (h *LinkHandler) scheduleBackgroundTasks(
ctx context.Context,
userID, providerName, accountID string,
token *oauth2.Token,
Expand Down Expand Up @@ -289,14 +285,18 @@ func (h *LinkHandler) upsertAccount(

successQuery := "newAccount"

tokenExpiryDuration := time.Duration(token.ExpiresIn) * time.Second

tokenExpiry := time.Now().Add(tokenExpiryDuration)

addCountParams := repository.AddAccountDetailsParams{
UserID: userID,
Provider: repository.ProviderEnum(providerName),
ProviderUserID: accountInfo.ProviderUserID,
AccessToken: encAccessToken,
RefreshToken: encRefreshToken,
TokenType: db.PGTextField(token.TokenType),
Expiry: db.PGTimestamptzField(token.Expiry),
Expiry: db.PGTimestamptzField(tokenExpiry),
Email: accountInfo.Email,
Name: accountInfo.Name,
AvatarUrl: db.PGTextField(accountInfo.AvatarURL),
Expand Down Expand Up @@ -449,17 +449,17 @@ func (h *LinkHandler) enqueueFileSyncTaskAndLog(
return nil
}

err = queries.AddNewJobLog(ctx, repository.AddNewJobLogParams{
JobID: info.ID,
err = queries.AddNewTaskLog(ctx, repository.AddNewTaskLogParams{
TaskID: info.ID,
AccountID: *accountUUID,
Type: info.Type,
Status: repository.JobStatusEnumQueued,
Status: repository.TaskStatusEnumQueued,
Queue: info.Queue,
Params: params,
})
if err != nil {
config.LOGGER.Error(
"failed to insert job log",
"failed to insert task log",
zap.String("provider", providerName),
zap.String("task_type", tasks.TypeFileSync),
zap.String("task_id", info.ID),
Expand Down Expand Up @@ -535,17 +535,17 @@ func (h *LinkHandler) enqueueAuthTokenRenewalTaskAndLog(
return nil
}

err = queries.AddNewJobLog(ctx, repository.AddNewJobLogParams{
JobID: info.ID,
err = queries.AddNewTaskLog(ctx, repository.AddNewTaskLogParams{
TaskID: info.ID,
AccountID: *accountUUID,
Type: info.Type,
Status: repository.JobStatusEnumQueued,
Status: repository.TaskStatusEnumQueued,
Queue: info.Queue,
Params: params,
})
if err != nil {
config.LOGGER.Error(
"failed to insert job log",
"failed to insert task log",
zap.String("provider", providerName),
zap.String("task_type", tasks.TypeAuthTokenRenewal),
zap.String("task_id", info.ID),
Expand Down
Loading
Loading