response.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 loginResponse struct {
  10. SID string `json:"SID,omitempty"`
  11. LSID string `json:"LSID,omitempty"`
  12. Auth string `json:"Auth,omitempty"`
  13. }
  14. func (l loginResponse) String() string {
  15. return fmt.Sprintf("SID=%s\nLSID=%s\nAuth=%s\n", l.SID, l.LSID, l.Auth)
  16. }
  17. type userInfoResponse struct {
  18. UserID string `json:"userId"`
  19. UserName string `json:"userName"`
  20. UserProfileID string `json:"userProfileId"`
  21. UserEmail string `json:"userEmail"`
  22. }
  23. type subscriptionResponse struct {
  24. ID string `json:"id"`
  25. Title string `json:"title"`
  26. Categories []subscriptionCategoryResponse `json:"categories"`
  27. URL string `json:"url"`
  28. HTMLURL string `json:"htmlUrl"`
  29. IconURL string `json:"iconUrl"`
  30. }
  31. type subscriptionsResponse struct {
  32. Subscriptions []subscriptionResponse `json:"subscriptions"`
  33. }
  34. type quickAddResponse struct {
  35. NumResults int64 `json:"numResults"`
  36. Query string `json:"query,omitempty"`
  37. StreamID string `json:"streamId,omitempty"`
  38. StreamName string `json:"streamName,omitempty"`
  39. }
  40. type subscriptionCategoryResponse struct {
  41. ID string `json:"id"`
  42. Label string `json:"label,omitempty"`
  43. Type string `json:"type,omitempty"`
  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 []subscriptionCategoryResponse `json:"tags"`
  56. }
  57. type streamContentItemsResponse struct {
  58. Direction string `json:"direction"`
  59. ID string `json:"id"`
  60. Title string `json:"title"`
  61. Self []contentHREF `json:"self"`
  62. Updated int64 `json:"updated"`
  63. Items []contentItem `json:"items"`
  64. Author string `json:"author"`
  65. }
  66. type contentItem struct {
  67. ID string `json:"id"`
  68. Categories []string `json:"categories"`
  69. Title string `json:"title"`
  70. CrawlTimeMsec string `json:"crawlTimeMsec"`
  71. TimestampUsec string `json:"timestampUsec"`
  72. Published int64 `json:"published"`
  73. Updated int64 `json:"updated"`
  74. Author string `json:"author"`
  75. Alternate []contentHREFType `json:"alternate"`
  76. Summary contentItemContent `json:"summary"`
  77. Content contentItemContent `json:"content"`
  78. Origin contentItemOrigin `json:"origin"`
  79. Enclosure []contentItemEnclosure `json:"enclosure"`
  80. Canonical []contentHREF `json:"canonical"`
  81. }
  82. type contentHREFType struct {
  83. HREF string `json:"href"`
  84. Type string `json:"type"`
  85. }
  86. type contentHREF struct {
  87. HREF string `json:"href"`
  88. }
  89. type contentItemEnclosure struct {
  90. URL string `json:"url"`
  91. Type string `json:"type"`
  92. }
  93. type contentItemContent struct {
  94. Direction string `json:"direction"`
  95. Content string `json:"content"`
  96. }
  97. type contentItemOrigin struct {
  98. StreamID string `json:"streamId"`
  99. Title string `json:"title"`
  100. HTMLUrl string `json:"htmlUrl"`
  101. }
  102. func sendUnauthorizedResponse(w http.ResponseWriter, r *http.Request) {
  103. builder := response.NewBuilder(w, r)
  104. builder.WithStatus(http.StatusUnauthorized)
  105. builder.WithHeader("X-Reader-Google-Bad-Token", "true")
  106. builder.WithHeader("Content-Type", "text/plain; charset=utf-8")
  107. builder.WithBodyAsString("Unauthorized")
  108. builder.Write()
  109. }