diff --git a/internal/app/handlers.go b/internal/app/handlers.go index 5b5732f4..3105536e 100644 --- a/internal/app/handlers.go +++ b/internal/app/handlers.go @@ -734,8 +734,8 @@ func (app *App) blobStorageUpload(c *gin.Context) { } func (app *App) syncUpdateRootV3(c *gin.Context) { - var rootv3 messages.SyncRootV3 - err := json.NewDecoder(c.Request.Body).Decode(&rootv3) + var rootv3 messages.SyncRootV3Request + err := c.BindJSON(&rootv3) if err != nil { log.Error(err) c.AbortWithStatus(http.StatusBadRequest) @@ -750,12 +750,23 @@ func (app *App) syncUpdateRootV3(c *gin.Context) { return } - c.JSON(http.StatusOK, messages.SyncRootV3{ - Generation: newgeneration, - Hash: rootv3.Hash, + if rootv3.Broadcast { + deviceID := c.GetString(deviceIDKey) + + log.Info("got sync completed, gen: ", newgeneration) + + app.hub.NotifySync(uid, deviceID) + } + + c.JSON(http.StatusOK, messages.SyncRootV3Response{ + Generation: newgeneration, + Hash: rootv3.Hash, + SchemaVersion: SchemaVersion, }) } +const SchemaVersion = 3 + func (app *App) syncGetRootV3(c *gin.Context) { uid := c.GetString(userIDKey) @@ -777,9 +788,10 @@ func (app *App) syncGetRootV3(c *gin.Context) { return } - c.JSON(http.StatusOK, messages.SyncRootV3{ - Generation: generation, - Hash: string(roothash), + c.JSON(http.StatusOK, messages.SyncRootV3Response{ + Generation: generation, + Hash: string(roothash), + SchemaVersion: SchemaVersion, }) } @@ -838,9 +850,10 @@ func (app *App) blobStorageWrite(c *gin.Context) { return } - c.JSON(http.StatusOK, messages.SyncRootV3{ - Generation: newgeneration, - Hash: string(blobID), + c.JSON(http.StatusOK, messages.SyncRootV3Response{ + Generation: newgeneration, + Hash: string(blobID), + SchemaVersion: SchemaVersion, }) } diff --git a/internal/app/routes.go b/internal/app/routes.go index 44cd48a0..113e613d 100644 --- a/internal/app/routes.go +++ b/internal/app/routes.go @@ -34,18 +34,18 @@ func (app *App) registerRoutes(router *gin.Engine) { "webapp": endpoint, }) }) - router.GET("/discovery/v1/webapp", func(c *gin.Context) { - endpoint, err := app.MyEndpoint() - if err != nil { - log.Warn("endpoint error:", err.Error()) - c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"err": err.Error()}) - return - } - c.JSON(http.StatusOK, gin.H{ - "Status": "OK", - "Host": endpoint, - }) - }) + router.GET("/discovery/v1/webapp", func(c *gin.Context) { + endpoint, err := app.MyEndpoint() + if err != nil { + log.Warn("endpoint error:", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"err": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "Status": "OK", + "Host": endpoint, + }) + }) router.GET("/health", func(c *gin.Context) { count := app.hub.ClientCount() diff --git a/internal/messages/messages.go b/internal/messages/messages.go index f888f2f5..efab3192 100644 --- a/internal/messages/messages.go +++ b/internal/messages/messages.go @@ -136,10 +136,18 @@ type SyncCompletedRequestV2 struct { Generation int64 `json:"generation"` } -// SyncRootV3 -type SyncRootV3 struct { +// SyncRootV3Request +type SyncRootV3Request struct { Generation int64 `json:"generation"` Hash string `json:"hash,omitempty"` + Broadcast bool `json:"broadcast"` +} + +// SyncRootV3Response +type SyncRootV3Response struct { + Generation int64 `json:"generation"` + Hash string `json:"hash,omitempty"` + SchemaVersion int64 `json:"schemaVersion"` } type CheckFiles struct {