Files
seanime-docker/seanime-2.9.10/internal/util/useragent.go
2025-09-20 14:08:38 +01:00

49 lines
767 B
Go

package util
import "github.com/mileusna/useragent"
const (
PlatformAndroid = "android"
PlatformIOS = "ios"
PlatformLinux = "linux"
PlatformMac = "mac"
PlatformWindows = "windows"
PlatformChromeOS = "chromeos"
)
const (
DeviceDesktop = "desktop"
DeviceMobile = "mobile"
DeviceTablet = "tablet"
)
type ClientInfo struct {
Device string
Platform string
}
func GetClientInfo(userAgent string) ClientInfo {
ua := useragent.Parse(userAgent)
var device string
var platform string
if ua.Mobile {
device = DeviceMobile
} else if ua.Tablet {
device = DeviceTablet
} else {
device = DeviceDesktop
}
platform = ua.OS
if platform == "" {
platform = "-"
}
return ClientInfo{
Device: device,
Platform: platform,
}
}