Skip to content

Commit

Permalink
Add sync routes for v3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
nemunaire committed Oct 26, 2023
1 parent c50c88b commit b40212e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
50 changes: 48 additions & 2 deletions internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 = ""
Expand Down
3 changes: 2 additions & 1 deletion internal/app/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
requestLog = "[requestlogging-middleware]"
syncDefault = "sync:default"
syncNew = "sync:tortoise"
syncNew3 = "sync:fox"
)

func (app *App) authMiddleware() gin.HandlerFunc {
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions internal/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit b40212e

Please sign in to comment.