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

sync/v4 expects to return an empty root instead of 404 #327

Merged
merged 1 commit into from
Nov 15, 2024
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
17 changes: 16 additions & 1 deletion internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,13 @@ func (app *App) syncUpdateRootV3(c *gin.Context) {

const SchemaVersion = 3

func (app *App) syncGetRootV3(c *gin.Context) {
func (app *App) syncGetRoot(c *gin.Context, newAccount func(*gin.Context)) {
uid := c.GetString(userIDKey)

reader, generation, _, err := app.blobStorer.LoadBlob(uid, "root")
if err == fs.ErrorNotFound {
log.Warn("No root file found, assuming this is a new account")
newAccount(c)
c.JSON(http.StatusNotFound, gin.H{"message": "root not found"})
return
} else if err != nil {
Expand All @@ -795,6 +796,20 @@ func (app *App) syncGetRootV3(c *gin.Context) {
})
}

func (app *App) syncGetRootV3(c *gin.Context) {
app.syncGetRoot(c, func(c *gin.Context) {
c.JSON(http.StatusNotFound, gin.H{"message": "root not found"})
})
}

func (app *App) syncGetRootV4(c *gin.Context) {
app.syncGetRoot(c, func(c *gin.Context) {
c.JSON(http.StatusOK, messages.SyncRootV3Response{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
c.JSON(http.StatusOK, messages.SyncRootV3Response{
c.JSON(http.StatusOK, messages.SyncRootV3Request{

Got it to work after changing this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to respond with a Request. It must be something else.

The difference will be:

{
    "generation": 0,
    "schemaVersion": 0
}

to:

{
    "generation": 0,
    "broadcast": false
}

Perhaps adding the correct schemaVersion as seen in the rest of the code?

Generation: 0,
})
})
}

func (app *App) checkFilesPresence(c *gin.Context) {
uid := c.GetString(userIDKey)
var req messages.CheckFiles
Expand Down
2 changes: 1 addition & 1 deletion internal/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ func (app *App) registerRoutes(router *gin.Engine) {
authRoutes.POST("/sync/v3/check-files", app.checkFilesPresence)
authRoutes.GET("/sync/v3/missing", app.checkMissingBlob)

authRoutes.GET("/sync/v4/root", app.syncGetRootV3)
authRoutes.GET("/sync/v4/root", app.syncGetRootV4)
}
}
Loading