response.go 4.1 KB

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