Skip to content

Commit

Permalink
Merge pull request #243 from nemunaire/f/sync-3.4
Browse files Browse the repository at this point in the history
Add routes for sync v3.4
  • Loading branch information
ddvk authored Jul 1, 2023
2 parents 5784582 + 16d3e65 commit 9209bc3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
47 changes: 47 additions & 0 deletions internal/app/handlers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -702,6 +703,52 @@ func (app *App) blobStorageUpload(c *gin.Context) {
c.JSON(http.StatusOK, response)
}

func (app *App) syncUpdateRootV3(c *gin.Context) {
var rootv3 messages.SyncRootV3
err := json.NewDecoder(c.Request.Body).Decode(&rootv3)
if err != nil {
log.Error(err)
c.AbortWithStatus(http.StatusBadRequest)
return
}

uid := c.GetString(userIDKey)
newgeneration, err := app.blobStorer.StoreBlob(uid, "root", bytes.NewBufferString(rootv3.Hash), rootv3.Generation)
if err != nil {
log.Error(err)
c.AbortWithStatus(http.StatusInternalServerError)
return
}

c.JSON(http.StatusOK, messages.SyncRootV3{
Generation: newgeneration,
Hash: rootv3.Hash,
})
}

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

reader, generation, _, err := app.blobStorer.LoadBlob(uid, "root")
if err != nil {
log.Error(err)
c.AbortWithStatus(http.StatusInternalServerError)
return
}

roothash, err := io.ReadAll(reader)
if err != nil {
log.Error(err)
c.AbortWithStatus(http.StatusInternalServerError)
return
}

c.JSON(http.StatusOK, messages.SyncRootV3{
Generation: generation,
Hash: string(roothash),
})
}

func (app *App) integrationsGetMetadata(c *gin.Context) {
var metadata messages.IntegrationMetadata
metadata.Thumbnail = ""
Expand Down
3 changes: 3 additions & 0 deletions internal/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,8 @@ func (app *App) registerRoutes(router *gin.Engine) {
authRoutes.POST("/sync/v2/signed-urls/downloads", app.blobStorageDownload)
authRoutes.POST("/sync/v2/signed-urls/uploads", app.blobStorageUpload)
authRoutes.POST("/sync/v2/sync-complete", app.syncCompleteV2)

authRoutes.GET("/sync/v3/root", app.syncGetRootV3)
authRoutes.PUT("/sync/v3/root", app.syncUpdateRootV3)
}
}
6 changes: 6 additions & 0 deletions internal/messages/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ type SyncCompletedRequestV2 struct {
Generation int64 `json:"generation"`
}

// SyncRootV3
type SyncRootV3 struct {
Generation int64 `json:"generation"`
Hash string `json:"hash"`
}

// IntegrationsResponse integrations
type IntegrationsResponse struct {
Integrations []Integration `json:"integrations"`
Expand Down

0 comments on commit 9209bc3

Please sign in to comment.