dto.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // Package model contains the data structures used throughout the LocalGo application
  2. package model
  3. const DefaultPort = 53317
  4. // DeviceType defines the type of the device.
  5. type DeviceType string
  6. const (
  7. DeviceTypeMobile DeviceType = "mobile"
  8. DeviceTypeDesktop DeviceType = "desktop"
  9. DeviceTypeWeb DeviceType = "web"
  10. DeviceTypeHeadless DeviceType = "headless"
  11. DeviceTypeServer DeviceType = "server"
  12. )
  13. // ProtocolType defines the protocol type.
  14. type ProtocolType string
  15. const (
  16. ProtocolTypeHTTP ProtocolType = "http"
  17. ProtocolTypeHTTPS ProtocolType = "https"
  18. )
  19. // DeviceInfo contains information about the current device
  20. type DeviceInfo struct {
  21. Alias string
  22. Version string
  23. DeviceModel *string
  24. DeviceType DeviceType
  25. Fingerprint string
  26. Port int
  27. DownloadDir string
  28. IP string
  29. Download bool
  30. HttpsEnabled bool
  31. }
  32. // ToInfoDto converts DeviceInfo to InfoDto
  33. func (d *DeviceInfo) ToInfoDto() InfoDto {
  34. return InfoDto{
  35. Alias: d.Alias,
  36. Version: d.Version,
  37. DeviceModel: d.DeviceModel,
  38. DeviceType: d.DeviceType,
  39. Fingerprint: d.Fingerprint,
  40. Download: d.Download,
  41. }
  42. }
  43. // ToRegisterDto converts DeviceInfo to RegisterDto
  44. func (d *DeviceInfo) ToRegisterDto() RegisterDto {
  45. protocol := ProtocolTypeHTTP
  46. if d.HttpsEnabled {
  47. protocol = ProtocolTypeHTTPS
  48. }
  49. return RegisterDto{
  50. Alias: d.Alias,
  51. Version: d.Version,
  52. DeviceModel: d.DeviceModel,
  53. DeviceType: d.DeviceType,
  54. Fingerprint: d.Fingerprint,
  55. Port: d.Port,
  56. Protocol: protocol,
  57. Download: d.Download,
  58. }
  59. }
  60. // ToMulticastDto converts DeviceInfo to MulticastDto
  61. func (d *DeviceInfo) ToMulticastDto(announce bool) MulticastDto {
  62. protocol := ProtocolTypeHTTP
  63. if d.HttpsEnabled {
  64. protocol = ProtocolTypeHTTPS
  65. }
  66. return MulticastDto{
  67. Alias: d.Alias,
  68. Version: d.Version,
  69. DeviceModel: d.DeviceModel,
  70. DeviceType: d.DeviceType,
  71. Fingerprint: d.Fingerprint,
  72. Port: d.Port,
  73. Protocol: protocol,
  74. Download: d.Download,
  75. Announce: announce,
  76. }
  77. }
  78. // InfoDto represents the response for /info and /register endpoints.
  79. // Also used as the info block in prepare-upload requests (port + protocol required).
  80. type InfoDto struct {
  81. Alias string `json:"alias"`
  82. Version string `json:"version"`
  83. DeviceModel *string `json:"deviceModel"` // nullable
  84. DeviceType DeviceType `json:"deviceType"`
  85. Fingerprint string `json:"fingerprint"`
  86. Port int `json:"port,omitempty"`
  87. Protocol ProtocolType `json:"protocol,omitempty"`
  88. Download bool `json:"download"`
  89. }
  90. // RegisterDto represents the request body for /register endpoint (sent by the discoverer).
  91. type RegisterDto struct {
  92. Alias string `json:"alias"`
  93. Version string `json:"version"`
  94. DeviceModel *string `json:"deviceModel"` // nullable
  95. DeviceType DeviceType `json:"deviceType"`
  96. Fingerprint string `json:"fingerprint"`
  97. Port int `json:"port"`
  98. Protocol ProtocolType `json:"protocol"` // "http" or "https"
  99. Download bool `json:"download"`
  100. }
  101. // MulticastDto represents the UDP discovery message.
  102. type MulticastDto struct {
  103. Alias string `json:"alias"`
  104. Version string `json:"version"`
  105. DeviceModel *string `json:"deviceModel"` // nullable
  106. DeviceType DeviceType `json:"deviceType"`
  107. Fingerprint string `json:"fingerprint"`
  108. Port int `json:"port"`
  109. Protocol ProtocolType `json:"protocol"` // http | https
  110. Download bool `json:"download"`
  111. Announce bool `json:"announce"` // True if initial announcement, false if response
  112. }
  113. // PrepareUploadRequestDto is sent to prepare file uploads
  114. type PrepareUploadRequestDto struct {
  115. Info InfoDto `json:"info"`
  116. Files map[string]FileDto `json:"files"`
  117. }
  118. // FileDto contains information about a file being uploaded
  119. type FileDto struct {
  120. ID string `json:"id"`
  121. FileName string `json:"fileName"`
  122. Size int64 `json:"size"`
  123. FileType string `json:"fileType"`
  124. SHA256 *string `json:"sha256,omitempty"` // Use pointer for nullable
  125. Preview *string `json:"preview,omitempty"` // Use pointer for nullable
  126. Metadata *FileMetadata `json:"metadata,omitempty"` // Use pointer for nullable
  127. }
  128. // FileMetadata holds optional file metadata (added in v2.2)
  129. type FileMetadata struct {
  130. Modified *string `json:"modified,omitempty"` // Using string for ISO 8601 format
  131. Accessed *string `json:"accessed,omitempty"` // Using string for ISO 8601 format
  132. }
  133. // PrepareUploadResponseDto is returned after a successful upload preparation
  134. type PrepareUploadResponseDto struct {
  135. SessionID string `json:"sessionId"`
  136. Files map[string]string `json:"files"`
  137. }
  138. // ReceiveRequestResponseDto is returned for download preparations
  139. type ReceiveRequestResponseDto struct {
  140. Info InfoDto `json:"info"` // Added Info field as per protocol spec
  141. SessionID string `json:"sessionId"`
  142. Files map[string]FileDto `json:"files"` // Changed to use FileDto
  143. }
  144. // StatusDto contains status information for a file
  145. type StatusDto struct {
  146. Status string `json:"status"`
  147. }