| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- // Package model contains the data structures used throughout the LocalGo application
- package model
- const DefaultPort = 53317
- // DeviceType defines the type of the device.
- type DeviceType string
- const (
- DeviceTypeMobile DeviceType = "mobile"
- DeviceTypeDesktop DeviceType = "desktop"
- DeviceTypeWeb DeviceType = "web"
- DeviceTypeHeadless DeviceType = "headless"
- DeviceTypeServer DeviceType = "server"
- )
- // ProtocolType defines the protocol type.
- type ProtocolType string
- const (
- ProtocolTypeHTTP ProtocolType = "http"
- ProtocolTypeHTTPS ProtocolType = "https"
- )
- // DeviceInfo contains information about the current device
- type DeviceInfo struct {
- Alias string
- Version string
- DeviceModel *string
- DeviceType DeviceType
- Fingerprint string
- Port int
- DownloadDir string
- IP string
- Download bool
- HttpsEnabled bool
- }
- // ToInfoDto converts DeviceInfo to InfoDto
- func (d *DeviceInfo) ToInfoDto() InfoDto {
- return InfoDto{
- Alias: d.Alias,
- Version: d.Version,
- DeviceModel: d.DeviceModel,
- DeviceType: d.DeviceType,
- Fingerprint: d.Fingerprint,
- Download: d.Download,
- }
- }
- // ToRegisterDto converts DeviceInfo to RegisterDto
- func (d *DeviceInfo) ToRegisterDto() RegisterDto {
- protocol := ProtocolTypeHTTP
- if d.HttpsEnabled {
- protocol = ProtocolTypeHTTPS
- }
- return RegisterDto{
- Alias: d.Alias,
- Version: d.Version,
- DeviceModel: d.DeviceModel,
- DeviceType: d.DeviceType,
- Fingerprint: d.Fingerprint,
- Port: d.Port,
- Protocol: protocol,
- Download: d.Download,
- }
- }
- // ToMulticastDto converts DeviceInfo to MulticastDto
- func (d *DeviceInfo) ToMulticastDto(announce bool) MulticastDto {
- protocol := ProtocolTypeHTTP
- if d.HttpsEnabled {
- protocol = ProtocolTypeHTTPS
- }
- return MulticastDto{
- Alias: d.Alias,
- Version: d.Version,
- DeviceModel: d.DeviceModel,
- DeviceType: d.DeviceType,
- Fingerprint: d.Fingerprint,
- Port: d.Port,
- Protocol: protocol,
- Download: d.Download,
- Announce: announce,
- }
- }
- // InfoDto represents the response for /info and /register endpoints.
- // Also used as the info block in prepare-upload requests (port + protocol required).
- type InfoDto struct {
- Alias string `json:"alias"`
- Version string `json:"version"`
- DeviceModel *string `json:"deviceModel"` // nullable
- DeviceType DeviceType `json:"deviceType"`
- Fingerprint string `json:"fingerprint"`
- Port int `json:"port,omitempty"`
- Protocol ProtocolType `json:"protocol,omitempty"`
- Download bool `json:"download"`
- }
- // RegisterDto represents the request body for /register endpoint (sent by the discoverer).
- type RegisterDto struct {
- Alias string `json:"alias"`
- Version string `json:"version"`
- DeviceModel *string `json:"deviceModel"` // nullable
- DeviceType DeviceType `json:"deviceType"`
- Fingerprint string `json:"fingerprint"`
- Port int `json:"port"`
- Protocol ProtocolType `json:"protocol"` // "http" or "https"
- Download bool `json:"download"`
- }
- // MulticastDto represents the UDP discovery message.
- type MulticastDto struct {
- Alias string `json:"alias"`
- Version string `json:"version"`
- DeviceModel *string `json:"deviceModel"` // nullable
- DeviceType DeviceType `json:"deviceType"`
- Fingerprint string `json:"fingerprint"`
- Port int `json:"port"`
- Protocol ProtocolType `json:"protocol"` // http | https
- Download bool `json:"download"`
- Announce bool `json:"announce"` // True if initial announcement, false if response
- }
- // PrepareUploadRequestDto is sent to prepare file uploads
- type PrepareUploadRequestDto struct {
- Info InfoDto `json:"info"`
- Files map[string]FileDto `json:"files"`
- }
- // FileDto contains information about a file being uploaded
- type FileDto struct {
- ID string `json:"id"`
- FileName string `json:"fileName"`
- Size int64 `json:"size"`
- FileType string `json:"fileType"`
- SHA256 *string `json:"sha256,omitempty"` // Use pointer for nullable
- Preview *string `json:"preview,omitempty"` // Use pointer for nullable
- Metadata *FileMetadata `json:"metadata,omitempty"` // Use pointer for nullable
- }
- // FileMetadata holds optional file metadata (added in v2.2)
- type FileMetadata struct {
- Modified *string `json:"modified,omitempty"` // Using string for ISO 8601 format
- Accessed *string `json:"accessed,omitempty"` // Using string for ISO 8601 format
- }
- // PrepareUploadResponseDto is returned after a successful upload preparation
- type PrepareUploadResponseDto struct {
- SessionID string `json:"sessionId"`
- Files map[string]string `json:"files"`
- }
- // ReceiveRequestResponseDto is returned for download preparations
- type ReceiveRequestResponseDto struct {
- Info InfoDto `json:"info"` // Added Info field as per protocol spec
- SessionID string `json:"sessionId"`
- Files map[string]FileDto `json:"files"` // Changed to use FileDto
- }
- // StatusDto contains status information for a file
- type StatusDto struct {
- Status string `json:"status"`
- }
|