response.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package googlereader // import "miniflux.app/v2/internal/googlereader"
  4. import (
  5. "fmt"
  6. "net/http"
  7. "miniflux.app/v2/internal/http/response"
  8. "miniflux.app/v2/internal/logger"
  9. )
  10. type login struct {
  11. SID string `json:"SID,omitempty"`
  12. LSID string `json:"LSID,omitempty"`
  13. Auth string `json:"Auth,omitempty"`
  14. }
  15. func (l login) String() string {
  16. return fmt.Sprintf("SID=%s\nLSID=%s\nAuth=%s\n", l.SID, l.LSID, l.Auth)
  17. }
  18. type userInfo struct {
  19. UserID string `json:"userId"`
  20. UserName string `json:"userName"`
  21. UserProfileID string `json:"userProfileId"`
  22. UserEmail string `json:"userEmail"`
  23. }
  24. type subscription struct {
  25. ID string `json:"id"`
  26. Title string `json:"title"`
  27. Categories []subscriptionCategory `json:"categories"`
  28. URL string `json:"url"`
  29. HTMLURL string `json:"htmlUrl"`
  30. IconURL string `json:"iconUrl"`
  31. }
  32. type quickAddResponse struct {
  33. NumResults int64 `json:"numResults"`
  34. Query string `json:"query,omitempty"`
  35. StreamID string `json:"streamId,omitempty"`
  36. StreamName string `json:"streamName,omitempty"`
  37. }
  38. type subscriptionCategory struct {
  39. ID string `json:"id"`
  40. Label string `json:"label,omitempty"`
  41. Type string `json:"type,omitempty"`
  42. }
  43. type subscriptionsResponse struct {
  44. Subscriptions []subscription `json:"subscriptions"`
  45. }
  46. type itemRef struct {
  47. ID string `json:"id"`
  48. DirectStreamIDs string `json:"directStreamIds,omitempty"`
  49. TimestampUsec string `json:"timestampUsec,omitempty"`
  50. }
  51. type streamIDResponse struct {
  52. ItemRefs []itemRef `json:"itemRefs"`
  53. Continuation int `json:"continuation,omitempty,string"`
  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. }