A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

98 rader
2.4 KiB

  1. package writefreely
  2. import (
  3. "github.com/writeas/go-nodeinfo"
  4. "github.com/writeas/web-core/log"
  5. "github.com/writeas/writefreely/config"
  6. "strings"
  7. )
  8. type nodeInfoResolver struct {
  9. cfg *config.Config
  10. db *datastore
  11. }
  12. func nodeInfoConfig(db *datastore, cfg *config.Config) *nodeinfo.Config {
  13. name := cfg.App.SiteName
  14. desc := "Minimal, federated blogging platform."
  15. if cfg.App.SingleUser {
  16. // Fetch blog information, instead
  17. coll, err := db.GetCollectionByID(1)
  18. if err == nil {
  19. desc = coll.Description
  20. }
  21. }
  22. return &nodeinfo.Config{
  23. BaseURL: cfg.App.Host,
  24. InfoURL: "/api/nodeinfo",
  25. Metadata: nodeinfo.Metadata{
  26. NodeName: name,
  27. NodeDescription: desc,
  28. Private: cfg.App.Private,
  29. Software: nodeinfo.SoftwareMeta{
  30. HomePage: softwareURL,
  31. GitHub: "https://github.com/writeas/writefreely",
  32. Follow: "https://writing.exchange/@write_as",
  33. },
  34. },
  35. Protocols: []nodeinfo.NodeProtocol{
  36. nodeinfo.ProtocolActivityPub,
  37. },
  38. Services: nodeinfo.Services{
  39. Inbound: []nodeinfo.NodeService{},
  40. Outbound: []nodeinfo.NodeService{
  41. nodeinfo.ServiceRSS,
  42. },
  43. },
  44. Software: nodeinfo.SoftwareInfo{
  45. Name: strings.ToLower(serverSoftware),
  46. Version: softwareVer,
  47. },
  48. }
  49. }
  50. func (r nodeInfoResolver) IsOpenRegistration() (bool, error) {
  51. return r.cfg.App.OpenRegistration, nil
  52. }
  53. func (r nodeInfoResolver) Usage() (nodeinfo.Usage, error) {
  54. var collCount, postCount, activeHalfYear, activeMonth int
  55. err := r.db.QueryRow(`SELECT COUNT(*) FROM collections`).Scan(&collCount)
  56. if err != nil {
  57. collCount = 0
  58. }
  59. err = r.db.QueryRow(`SELECT COUNT(*) FROM posts`).Scan(&postCount)
  60. if err != nil {
  61. log.Error("Unable to fetch post counts: %v", err)
  62. }
  63. if r.cfg.App.PublicStats {
  64. // Display bi-yearly / monthly stats
  65. err = r.db.QueryRow(`SELECT COUNT(*) FROM (
  66. SELECT DISTINCT collection_id
  67. FROM posts
  68. INNER JOIN collections c
  69. ON collection_id = c.id
  70. WHERE collection_id IS NOT NULL
  71. AND updated > DATE_SUB(NOW(), INTERVAL 6 MONTH)) co`).Scan(&activeHalfYear)
  72. err = r.db.QueryRow(`SELECT COUNT(*) FROM (
  73. SELECT DISTINCT collection_id
  74. FROM posts
  75. INNER JOIN FROM collections c
  76. ON collection_id = c.id
  77. WHERE collection_id IS NOT NULL
  78. AND updated > DATE_SUB(NOW(), INTERVAL 1 MONTH)) co`).Scan(&activeMonth)
  79. }
  80. return nodeinfo.Usage{
  81. Users: nodeinfo.UsageUsers{
  82. Total: collCount,
  83. ActiveHalfYear: activeHalfYear,
  84. ActiveMonth: activeMonth,
  85. },
  86. LocalPosts: postCount,
  87. }, nil
  88. }