diff --git a/internal/app/handlers.go b/internal/app/handlers.go index d8254864..b6bf5d67 100644 --- a/internal/app/handlers.go +++ b/internal/app/handlers.go @@ -37,6 +37,31 @@ const ( maxRequestSize = 7000000000 ) +func parseUAVersion(ua string) (program string, version float64, build uint64) { + flds := strings.Fields(ua) + ua_text := strings.Split(flds[0], "/") + + program = ua_text[0] + + if len(ua_text) >= 2 { + ua_version := strings.Split(ua_text[1], ".") + + for i, v := range ua_version { + if n, err := strconv.ParseUint(v, 10, 64); err == nil { + if i == 3 { + build = n + } else if i == 0 { + version += float64(n) + } else { + version += float64(n) / 1000.0 * float64(i) + } + } + } + } + + return +} + func (app *App) getDeviceClaims(c *gin.Context) (*DeviceClaims, error) { token, err := common.GetToken(c) if err != nil { @@ -146,8 +171,14 @@ func (app *App) newUserToken(c *gin.Context) { scopes := []string{"intgr", "screenshare", "hwcmail:-1", "mail:-1"} if user.Sync15 { - log.Info("Using sync 1.5") - scopes = append(scopes, syncNew) + _, uaversion, _ := parseUAVersion(c.Request.Header.Get("user-agent")) + if uaversion == 0.0 || uaversion > 3.006 { + log.Info("Using sync 1.5 fox") + scopes = append(scopes, syncNew3) + } else { + log.Info("Using sync 1.5 tortoise (consider upgrading your rm/app)") + scopes = append(scopes, syncNew) + } } else { scopes = append(scopes, syncDefault) } @@ -759,6 +790,21 @@ func (app *App) syncGetRootV3(c *gin.Context) { }) } +func (app *App) blobStorageRead(c *gin.Context) { + uid := c.GetString(userIDKey) + blobID := common.ParamS(fileKey, c) + + reader, _, size, err := app.blobStorer.LoadBlob(uid, blobID) + if err != nil { + log.Error(err) + c.AbortWithStatus(http.StatusInternalServerError) + return + } + defer reader.Close() + + c.DataFromReader(http.StatusOK, size, "application/octet-stream", reader, nil) +} + func (app *App) integrationsGetMetadata(c *gin.Context) { var metadata messages.IntegrationMetadata metadata.Thumbnail = "" diff --git a/internal/app/middleware.go b/internal/app/middleware.go index e27b8bd1..fbbda093 100644 --- a/internal/app/middleware.go +++ b/internal/app/middleware.go @@ -18,6 +18,7 @@ const ( requestLog = "[requestlogging-middleware]" syncDefault = "sync:default" syncNew = "sync:tortoise" + syncNew3 = "sync:fox" ) func (app *App) authMiddleware() gin.HandlerFunc { @@ -35,7 +36,7 @@ func (app *App) authMiddleware() gin.HandlerFunc { var isSync15 = false for _, s := range scopes { - if s == syncNew { + if s == syncNew || s == syncNew3 { isSync15 = true break } diff --git a/internal/app/routes.go b/internal/app/routes.go index 88d49b36..aaea2454 100644 --- a/internal/app/routes.go +++ b/internal/app/routes.go @@ -130,5 +130,6 @@ func (app *App) registerRoutes(router *gin.Engine) { authRoutes.GET("/sync/v3/root", app.syncGetRootV3) authRoutes.PUT("/sync/v3/root", app.syncUpdateRootV3) + authRoutes.GET("/sync/v3/files/:"+fileKey, app.blobStorageRead) } }