diff --git a/internal/app/handlers.go b/internal/app/handlers.go index e2a66727..5c5a4a98 100644 --- a/internal/app/handlers.go +++ b/internal/app/handlers.go @@ -779,6 +779,35 @@ func (app *App) syncGetRootV3(c *gin.Context) { }) } +func (app *App) checkFilesPresence(c *gin.Context) { + uid := c.GetString(userIDKey) + var req messages.CheckFiles + if err := c.ShouldBindJSON(&req); err != nil { + log.Error(err) + badReq(c, err.Error()) + return + } + + mfs := message.MissingFiles{} + + for _, fileid := range req.Files { + _, _, err := app.blobStorer.GetBlobURL(uid, fileid, false) + if err != nil { + mfs = append(mfs, fileid) + } + } + + c.JSON(http.StatusOK, mfs) +} + +func (app *App) checkMissingBlob(c *gin.Context) { + mhs := message.MissingHashes{} + + // TODO + + c.JSON(http.StatusOK, mhs) +} + func (app *App) blobStorageRead(c *gin.Context) { uid := c.GetString(userIDKey) blobID := common.ParamS(fileKey, c) diff --git a/internal/app/routes.go b/internal/app/routes.go index 9a7513ec..1d9cdb31 100644 --- a/internal/app/routes.go +++ b/internal/app/routes.go @@ -91,6 +91,16 @@ func (app *App) registerRoutes(router *gin.Engine) { } c.Status(http.StatusOK) }) + router.POST("/v2/reports", func(c *gin.Context) { + _, err := ioutil.ReadAll(c.Request.Body) + + if err != nil { + log.Warn("cant parse telemetry, ignored") + c.Status(http.StatusOK) + return + } + c.Status(http.StatusOK) + }) //routes needing api authentitcation authRoutes := router.Group("/") @@ -144,5 +154,8 @@ func (app *App) registerRoutes(router *gin.Engine) { authRoutes.PUT("/sync/v3/root", app.syncUpdateRootV3) authRoutes.GET("/sync/v3/files/:"+fileKey, app.blobStorageRead) authRoutes.PUT("/sync/v3/files/:"+fileKey, app.blobStorageWrite) + + authRoutes.POST("/sync/v3/check-files", app.checkFilesPresence) + authRoutes.GET("/sync/v3/missing", app.checkMissingBlob) } } diff --git a/internal/messages/messages.go b/internal/messages/messages.go index c6608885..f888f2f5 100644 --- a/internal/messages/messages.go +++ b/internal/messages/messages.go @@ -142,6 +142,20 @@ type SyncRootV3 struct { Hash string `json:"hash,omitempty"` } +type CheckFiles struct { + Filename string `json:"filename"` + Files []string `json:"files"` + Reason string `json:"reason"` +} + +type MissingFiles struct { + MissingFiles []string `json:"missingFiles"` +} + +type MissingHashes struct { + Hashes []string `json:"hashes"` +} + // IntegrationsResponse integrations type IntegrationsResponse struct { Integrations []Integration `json:"integrations"`