response.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. Continuation int `json:"continuation,omitempty,string"`
  55. }
  56. type tagsResponse struct {
  57. Tags []subscriptionCategory `json:"tags"`
  58. }
  59. type streamContentItems struct {
  60. Direction string `json:"direction"`
  61. ID string `json:"id"`
  62. Title string `json:"title"`
  63. Self []contentHREF `json:"self"`
  64. Alternate []contentHREFType `json:"alternate"`
  65. Updated int64 `json:"updated"`
  66. Items []contentItem `json:"items"`
  67. Author string `json:"author"`
  68. }
  69. type contentItem struct {
  70. ID string `json:"id"`
  71. Categories []string `json:"categories"`
  72. Title string `json:"title"`
  73. CrawlTimeMsec string `json:"crawlTimeMsec"`
  74. TimestampUsec string `json:"timestampUsec"`
  75. Published int64 `json:"published"`
  76. Updated int64 `json:"updated"`
  77. Author string `json:"author"`
  78. Alternate []contentHREFType `json:"alternate"`
  79. Summary contentItemContent `json:"summary"`
  80. Content contentItemContent `json:"content"`
  81. Origin contentItemOrigin `json:"origin"`
  82. Enclosure []contentItemEnclosure `json:"enclosure"`
  83. Canonical []contentHREF `json:"canonical"`
  84. }
  85. type contentHREFType struct {
  86. HREF string `json:"href"`
  87. Type string `json:"type"`
  88. }
  89. type contentHREF struct {
  90. HREF string `json:"href"`
  91. }
  92. type contentItemEnclosure struct {
  93. URL string `json:"url"`
  94. Type string `json:"type"`
  95. }
  96. type contentItemContent struct {
  97. Direction string `json:"direction"`
  98. Content string `json:"content"`
  99. }
  100. type contentItemOrigin struct {
  101. StreamID string `json:"streamId"`
  102. Title string `json:"title"`
  103. HTMLUrl string `json:"htmlUrl"`
  104. }
  105. // Unauthorized sends a not authorized error to the client.
  106. func Unauthorized(w http.ResponseWriter, r *http.Request) {
  107. logger.Error("[HTTP:Unauthorized] %s", r.URL)
  108. builder := response.New(w, r)
  109. builder.WithStatus(http.StatusUnauthorized)
  110. builder.WithHeader("Content-Type", "text/plain")
  111. builder.WithHeader("X-Reader-Google-Bad-Token", "true")
  112. builder.WithBody("Unauthorized")
  113. builder.Write()
  114. }
  115. // OK sends a ok response to the client.
  116. func OK(w http.ResponseWriter, r *http.Request) {
  117. logger.Info("[HTTP:OK] %s", r.URL)
  118. builder := response.New(w, r)
  119. builder.WithStatus(http.StatusOK)
  120. builder.WithHeader("Content-Type", "text/plain")
  121. builder.WithBody("OK")
  122. builder.Write()
  123. }