A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

88 righe
2.2 KiB

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