response.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright 2022 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package googlereader // import "miniflux.app/googlereader"
  5. import (
  6. "fmt"
  7. "net/http"
  8. "miniflux.app/http/response"
  9. "miniflux.app/logger"
  10. )
  11. type login struct {
  12. SID string `json:"SID,omitempty"`
  13. LSID string `json:"LSID,omitempty"`
  14. Auth string `json:"Auth,omitempty"`
  15. }
  16. func (l login) String() string {
  17. return fmt.Sprintf("SID=%s\nLSID=%s\nAuth=%s\n", l.SID, l.LSID, l.Auth)
  18. }
  19. type userInfo struct {
  20. UserID string `json:"userId"`
  21. UserName string `json:"userName"`
  22. UserProfileID string `json:"userProfileId"`
  23. UserEmail string `json:"userEmail"`
  24. }
  25. type subscription struct {
  26. ID string `json:"id"`
  27. Title string `json:"title"`
  28. Categories []subscriptionCategory `json:"categories"`
  29. URL string `json:"url"`
  30. HTMLURL string `json:"htmlUrl"`
  31. IconURL string `json:"iconUrl"`
  32. }
  33. type quickAddResponse struct {
  34. NumResults int64 `json:"numResults"`
  35. Query string `json:"query,omitempty"`
  36. StreamID string `json:"streamId,omitempty"`
  37. StreamName string `json:"streamName,omitempty"`
  38. }
  39. type subscriptionCategory struct {
  40. ID string `json:"id"`
  41. Label string `json:"label,omitempty"`
  42. Type string `json:"type,omitempty"`
  43. }
  44. type subscriptionsResponse struct {
  45. Subscriptions []subscription `json:"subscriptions"`
  46. }
  47. type itemRef struct {
  48. ID string `json:"id"`
  49. DirectStreamIDs string `json:"directStreamIds,omitempty"`
  50. TimestampUsec string `json:"timestampUsec,omitempty"`
  51. }
  52. type streamIDResponse struct {
  53. ItemRefs []itemRef `json:"itemRefs"`
  54. }
  55. type tagsResponse struct {
  56. Tags []subscriptionCategory `json:"tags"`
  57. }
  58. type streamContentItems struct {
  59. Direction string `json:"direction"`
  60. ID string `json:"id"`
  61. Title string `json:"title"`
  62. Self []contentHREF `json:"self"`
  63. Alternate []contentHREFType `json:"alternate"`
  64. Updated int64 `json:"updated"`
  65. Items []contentItem `json:"items"`
  66. Author string `json:"author"`
  67. }
  68. type contentItem struct {
  69. ID string `json:"id"`
  70. Categories []string `json:"categories"`
  71. Title string `json:"title"`
  72. CrawlTimeMsec string `json:"crawlTimeMsec"`
  73. TimestampUsec string `json:"timestampUsec"`
  74. Published int64 `json:"published"`
  75. Updated int64 `json:"updated"`
  76. Author string `json:"author"`
  77. Alternate []contentHREFType `json:"alternate"`
  78. Summary contentItemContent `json:"summary"`
  79. Content contentItemContent `json:"content"`
  80. Origin contentItemOrigin `json:"origin"`
  81. Enclosure []contentItemEnclosure `json:"enclosure"`
  82. Canonical []contentHREF `json:"canonical"`
  83. }
  84. type contentHREFType struct {
  85. HREF string `json:"href"`
  86. Type string `json:"type"`
  87. }
  88. type contentHREF struct {
  89. HREF string `json:"href"`
  90. }
  91. type contentItemEnclosure struct {
  92. URL string `json:"url"`
  93. Type string `json:"type"`
  94. }
  95. type contentItemContent struct {
  96. Direction string `json:"direction"`
  97. Content string `json:"content"`
  98. }
  99. type contentItemOrigin struct {
  100. StreamID string `json:"streamId"`
  101. Title string `json:"title"`
  102. HTMLUrl string `json:"htmlUrl"`
  103. }
  104. // Unauthorized sends a not authorized error to the client.
  105. func Unauthorized(w http.ResponseWriter, r *http.Request) {
  106. logger.Error("[HTTP:Unauthorized] %s", r.URL)
  107. builder := response.New(w, r)
  108. builder.WithStatus(http.StatusUnauthorized)
  109. builder.WithHeader("Content-Type", "text/plain")
  110. builder.WithHeader("X-Reader-Google-Bad-Token", "true")
  111. builder.WithBody("Unauthorized")
  112. builder.Write()
  113. }
  114. // OK sends a ok response to the client.
  115. func OK(w http.ResponseWriter, r *http.Request) {
  116. logger.Info("[HTTP:OK] %s", r.URL)
  117. builder := response.New(w, r)
  118. builder.WithStatus(http.StatusOK)
  119. builder.WithHeader("Content-Type", "text/plain")
  120. builder.WithBody("OK")
  121. builder.Write()
  122. }