NodeInfo server implemented in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.2 KiB

  1. package nodeinfo
  2. type (
  3. NodeProtocol string
  4. NodeService string
  5. )
  6. const (
  7. // Protocols that can be supported by this node.
  8. ProtocolActivityPub NodeProtocol = "activitypub"
  9. ProtocolOStatus = "ostatus"
  10. // Services that can be supported (inbound or outbound) by this node's API.
  11. ServiceTwitter NodeService = "twitter"
  12. ServiceTumblr = "tumblr"
  13. )
  14. type Config struct {
  15. InfoURL string
  16. Metadata Metadata
  17. Protocols []NodeProtocol
  18. Services Services
  19. Software SoftwareInfo
  20. }
  21. type (
  22. // NodeInfo includes all required node info.
  23. NodeInfo struct {
  24. Metadata Metadata `json:"metadata"`
  25. OpenRegistrations bool `json:"openRegistrations"`
  26. Protocols []NodeProtocol `json:"protocols"`
  27. Services Services `json:"services"`
  28. Software SoftwareInfo `json:"software"`
  29. Usage Usage `json:"usage"`
  30. Version string `json:"version"`
  31. }
  32. // Metadata for nodeinfo. Properties are based on what Pleroma uses.
  33. //
  34. // From the spec: Free form key value pairs for software specific values.
  35. // Clients should not rely on any specific key present.
  36. Metadata struct {
  37. NodeName string `json:"nodeName,omitempty"`
  38. NodeDescription string `json:"nodeDescription,omitempty"`
  39. Private bool `json:"private,omitempty"`
  40. }
  41. Services struct {
  42. Inbound []NodeService `json:"inbound"`
  43. Outbound []NodeService `json:"outbound"`
  44. }
  45. SoftwareInfo struct {
  46. // Name (canonical) of this server software.
  47. Name string `json:"name"`
  48. // Version of this server software.
  49. Version string `json:"version"`
  50. }
  51. // Usage is usage statistics for this server.
  52. Usage struct {
  53. Users UsageUsers `json:"users"`
  54. LocalPosts int `json:"localPosts,omitempty"`
  55. LocalComments int `json:"localComments,omitempty"`
  56. }
  57. UsageUsers struct {
  58. Total int `json:"total,omitempty"`
  59. ActiveHalfYear int `json:"activeHalfyear,omitempty"`
  60. ActiveMonth int `json:"activeMonth,omitempty"`
  61. }
  62. )
  63. func (s Service) BuildInfo() NodeInfo {
  64. ni := s.Info
  65. ni.OpenRegistrations, _ = s.resolver.IsOpenRegistration()
  66. ni.Usage, _ = s.resolver.Usage()
  67. ni.Version = profileVer
  68. return ni
  69. }