From 8501caa32a9ec5f5310be22f996a8b5f712c127a Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 17 Oct 2024 09:58:05 +0200 Subject: [PATCH] sync/v4 expects to return an empty root instead of 404 Fixes: #326 --- internal/app/handlers.go | 17 ++++++++++++++++- internal/app/routes.go | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/app/handlers.go b/internal/app/handlers.go index 3105536e..738ce590 100644 --- a/internal/app/handlers.go +++ b/internal/app/handlers.go @@ -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 { @@ -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 diff --git a/internal/app/routes.go b/internal/app/routes.go index 113e613d..703a56d8 100644 --- a/internal/app/routes.go +++ b/internal/app/routes.go @@ -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) } }