novel.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package core
  2. import (
  3. "time"
  4. http "codeberg.org/vnpower/pixivfe/v2/core/http"
  5. session "codeberg.org/vnpower/pixivfe/v2/core/session"
  6. "github.com/goccy/go-json"
  7. "github.com/gofiber/fiber/v2"
  8. )
  9. type Novel struct {
  10. Bookmarks int `json:"bookmarkCount"`
  11. CommentCount int `json:"commentCount"`
  12. MarkerCount int `json:"markerCount"`
  13. CreateDate time.Time `json:"createDate"`
  14. UploadDate time.Time `json:"uploadDate"`
  15. Description string `json:"description"`
  16. ID string `json:"id"`
  17. Title string `json:"title"`
  18. Likes int `json:"likeCount"`
  19. Pages int `json:"pageCount"`
  20. UserID string `json:"userId"`
  21. UserName string `json:"userName"`
  22. Views int `json:"viewCount"`
  23. IsOriginal bool `json:"isOriginal"`
  24. IsBungei bool `json:"isBungei"`
  25. XRestrict int `json:"xRestrict"`
  26. Restrict int `json:"restrict"`
  27. Content string `json:"content"`
  28. CoverURL string `json:"coverUrl"`
  29. IsBookmarkable bool `json:"isBookmarkable"`
  30. BookmarkData interface{} `json:"bookmarkData"`
  31. LikeData bool `json:"likeData"`
  32. PollData interface{} `json:"pollData"`
  33. Marker interface{} `json:"marker"`
  34. Tags struct {
  35. AuthorID string `json:"authorId"`
  36. IsLocked bool `json:"isLocked"`
  37. Tags []struct {
  38. Name string `json:"tag"`
  39. } `json:"tags"`
  40. Writable bool `json:"writable"`
  41. } `json:"tags"`
  42. SeriesNavData interface{} `json:"seriesNavData"`
  43. HasGlossary bool `json:"hasGlossary"`
  44. IsUnlisted bool `json:"isUnlisted"`
  45. Language string `json:"language"`
  46. CommentOff int `json:"commentOff"`
  47. CharacterCount int `json:"characterCount"`
  48. WordCount int `json:"wordCount"`
  49. UseWordCount bool `json:"useWordCount"`
  50. ReadingTime int `json:"readingTime"`
  51. AiType int `json:"aiType"`
  52. Genre string `json:"genre"`
  53. }
  54. type NovelBrief struct {
  55. ID string `json:"id"`
  56. Title string `json:"title"`
  57. XRestrict int `json:"xRestrict"`
  58. Restrict int `json:"restrict"`
  59. CoverURL string `json:"url"`
  60. Tags []string `json:"tags"`
  61. UserID string `json:"userId"`
  62. UserName string `json:"userName"`
  63. UserAvatar string `json:"profileImageUrl"`
  64. TextCount int `json:"textCount"`
  65. WordCount int `json:"wordCount"`
  66. ReadingTime int `json:"readingTime"`
  67. Description string `json:"description"`
  68. IsBookmarkable bool `json:"isBookmarkable"`
  69. BookmarkData interface{} `json:"bookmarkData"`
  70. Bookmarks int `json:"bookmarkCount"`
  71. IsOriginal bool `json:"isOriginal"`
  72. CreateDate time.Time `json:"createDate"`
  73. UpdateDate time.Time `json:"updateDate"`
  74. IsMasked bool `json:"isMasked"`
  75. SeriesID string `json:"seriesId"`
  76. SeriesTitle string `json:"seriesTitle"`
  77. IsUnlisted bool `json:"isUnlisted"`
  78. AiType int `json:"aiType"`
  79. Genre string `json:"genre"`
  80. }
  81. func GetNovelByID(c *fiber.Ctx, id string) (Novel, error) {
  82. var novel Novel
  83. URL := http.GetNovelURL(id)
  84. response, err := http.UnwrapWebAPIRequest(c.Context(), URL, "")
  85. if err != nil {
  86. return novel, err
  87. }
  88. response = session.ProxyImageUrl(c, response)
  89. err = json.Unmarshal([]byte(response), &novel)
  90. if err != nil {
  91. return novel, err
  92. }
  93. return novel, nil
  94. }
  95. func GetNovelRelated(c *fiber.Ctx, id string) ([]NovelBrief, error) {
  96. var novels struct {
  97. List []NovelBrief `json:"novels"`
  98. }
  99. // hard-coded value, may change
  100. URL := http.GetNovelRelatedURL(id, 50)
  101. response, err := http.UnwrapWebAPIRequest(c.Context(), URL, "")
  102. if err != nil {
  103. return novels.List, err
  104. }
  105. response = session.ProxyImageUrl(c, response)
  106. err = json.Unmarshal([]byte(response), &novels)
  107. if err != nil {
  108. return novels.List, err
  109. }
  110. return novels.List, nil
  111. }