Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package entity
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
DeviceIOS = "ios"
|
|
DeviceAndroid = "android"
|
|
DeviceHarmony = "harmony"
|
|
DeviceWindows = "windows"
|
|
DeviceMacOS = "macos"
|
|
DeviceWeb = "web"
|
|
)
|
|
|
|
var deviceTypes = map[string]struct{}{
|
|
DeviceIOS: {},
|
|
DeviceAndroid: {},
|
|
DeviceHarmony: {},
|
|
DeviceWindows: {},
|
|
DeviceMacOS: {},
|
|
DeviceWeb: {},
|
|
}
|
|
|
|
// Device is a login device row for one user.
|
|
type Device struct {
|
|
ID int64 // table AUTO_INCREMENT; business key is (UserID, DeviceID)
|
|
UserID int64
|
|
DeviceID uint64
|
|
DeviceType string
|
|
DeviceName string
|
|
AppVersion string
|
|
Language string
|
|
LastIP string
|
|
LastLoginAt time.Time
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// LoginDevice is the device snapshot supplied at login (not a table row).
|
|
type LoginDevice struct {
|
|
DeviceID uint64
|
|
DeviceType string
|
|
Platform string // alias of DeviceType; HTTP still accepts `platform`
|
|
DeviceName string
|
|
AppVersion string
|
|
Language string
|
|
RealIP string
|
|
}
|
|
|
|
func NormalizeDeviceType(s string) string {
|
|
return strings.ToLower(strings.TrimSpace(s))
|
|
}
|
|
|
|
func ValidDeviceType(s string) bool {
|
|
_, ok := deviceTypes[NormalizeDeviceType(s)]
|
|
return ok
|
|
}
|
|
|
|
func DeviceTypeOf(d *LoginDevice) string {
|
|
if d == nil {
|
|
return ""
|
|
}
|
|
if t := NormalizeDeviceType(d.DeviceType); ValidDeviceType(t) {
|
|
return t
|
|
}
|
|
return NormalizeDeviceType(d.Platform)
|
|
}
|