Skip to content

Commit

Permalink
Merge pull request #327 from nemunaire/f/new-account-v4
Browse files Browse the repository at this point in the history
sync/v4 expects to return an empty root instead of 404
  • Loading branch information
ddvk authored Nov 15, 2024
2 parents 4af294b + 8501caa commit 87d79db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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{
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)
}
}

0 comments on commit 87d79db

Please sign in to comment.