response.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. )
  8. type loginResponse struct {
  9. SID string `json:"SID,omitempty"`
  10. LSID string `json:"LSID,omitempty"`
  11. Auth string `json:"Auth,omitempty"`
  12. }
  13. func (l loginResponse) String() string {
  14. return fmt.Sprintf("SID=%s\nLSID=%s\nAuth=%s\n", l.SID, l.LSID, l.Auth)
  15. }
  16. type userInfoResponse struct {
  17. UserID string `json:"userId"`
  18. UserName string `json:"userName"`
  19. UserProfileID string `json:"userProfileId"`
  20. UserEmail string `json:"userEmail"`
  21. }
  22. type subscriptionResponse struct {
  23. ID string `json:"id"`
  24. Title string `json:"title"`
  25. Categories []subscriptionCategoryResponse `json:"categories"`
  26. URL string `json:"url"`
  27. HTMLURL string `json:"htmlUrl"`
  28. IconURL string `json:"iconUrl"`
  29. }
  30. type subscriptionsResponse struct {
  31. Subscriptions []subscriptionResponse `json:"subscriptions"`
  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 subscriptionCategoryResponse struct {
  40. ID string `json:"id"`
  41. Label string `json:"label,omitempty"`
  42. Type string `json:"type,omitempty"`
  43. }
  44. type itemRef struct {
  45. ID string `json:"id"`
  46. DirectStreamIDs string `json:"directStreamIds,omitempty"`
  47. TimestampUsec string `json:"timestampUsec,omitempty"`
  48. }
  49. type streamIDResponse struct {
  50. ItemRefs []itemRef `json:"itemRefs"`
  51. Continuation int `json:"continuation,omitempty,string"`
  52. }
  53. type tagsResponse struct {
  54. Tags []subscriptionCategoryResponse `json:"tags"`
  55. }
  56. type streamContentItemsResponse struct {
  57. Direction string `json:"direction"`
  58. ID string `json:"id"`
  59. Title string `json:"title"`
  60. Self []contentHREF `json:"self"`
  61. Updated int64 `json:"updated"`
  62. Items []contentItem `json:"items"`
  63. Author string `json:"author"`
  64. }
  65. type contentItem struct {
  66. ID string `json:"id"`
  67. Categories []string `json:"categories"`
  68. Title string `json:"title"`
  69. CrawlTimeMsec string `json:"crawlTimeMsec"`
  70. TimestampUsec string `json:"timestampUsec"`
  71. Published int64 `json:"published"`
  72. Updated int64 `json:"updated"`
  73. Author string `json:"author"`
  74. Alternate []contentHREFType `json:"alternate"`
  75. Summary contentItemContent `json:"summary"`
  76. Content contentItemContent `json:"content"`
  77. Origin contentItemOrigin `json:"origin"`
  78. Enclosure []contentItemEnclosure `json:"enclosure"`
  79. Canonical []contentHREF `json:"canonical"`
  80. }
  81. type contentHREFType struct {
  82. HREF string `json:"href"`
  83. Type string `json:"type"`
  84. }
  85. type contentHREF struct {
  86. HREF string `json:"href"`
  87. }
  88. type contentItemEnclosure struct {
  89. URL string `json:"url"`
  90. Type string `json:"type"`
  91. }
  92. type contentItemContent struct {
  93. Direction string `json:"direction"`
  94. Content string `json:"content"`
  95. }
  96. type contentItemOrigin struct {
  97. StreamID string `json:"streamId"`
  98. Title string `json:"title"`
  99. HTMLUrl string `json:"htmlUrl"`
  100. }
  101. func sendUnauthorizedResponse(w http.ResponseWriter) {
  102. w.Header().Set("Content-Type", "text/plain")
  103. w.Header().Set("X-Reader-Google-Bad-Token", "true")
  104. w.WriteHeader(http.StatusUnauthorized)
  105. w.Write([]byte("Unauthorized"))
  106. }
  107. func sendOkayResponse(w http.ResponseWriter) {
  108. w.Header().Set("Content-Type", "text/plain")
  109. w.WriteHeader(http.StatusOK)
  110. w.Write([]byte("OK"))
  111. }