@book000/pixivts 0.55.1 → 0.56.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +115 -19
  2. package/dist/index.cjs +1321 -0
  3. package/dist/index.d.cts +1662 -0
  4. package/dist/index.d.ts +1662 -45
  5. package/dist/index.js +1308 -65
  6. package/package.json +35 -72
  7. package/dist/checks.d.ts +0 -19
  8. package/dist/checks.d.ts.map +0 -1
  9. package/dist/checks.js +0 -85
  10. package/dist/checks.js.map +0 -1
  11. package/dist/checks.test.d.ts +0 -2
  12. package/dist/checks.test.d.ts.map +0 -1
  13. package/dist/checks.test.js +0 -306
  14. package/dist/checks.test.js.map +0 -1
  15. package/dist/http-client.d.ts +0 -66
  16. package/dist/http-client.d.ts.map +0 -1
  17. package/dist/http-client.js +0 -138
  18. package/dist/http-client.js.map +0 -1
  19. package/dist/http-client.test.d.ts +0 -2
  20. package/dist/http-client.test.d.ts.map +0 -1
  21. package/dist/http-client.test.js +0 -149
  22. package/dist/http-client.test.js.map +0 -1
  23. package/dist/index.d.ts.map +0 -1
  24. package/dist/index.js.map +0 -1
  25. package/dist/options.d.ts +0 -317
  26. package/dist/options.d.ts.map +0 -1
  27. package/dist/options.js +0 -222
  28. package/dist/options.js.map +0 -1
  29. package/dist/options.test.d.ts +0 -2
  30. package/dist/options.test.d.ts.map +0 -1
  31. package/dist/options.test.js +0 -117
  32. package/dist/options.test.js.map +0 -1
  33. package/dist/pixiv.d.ts +0 -317
  34. package/dist/pixiv.d.ts.map +0 -1
  35. package/dist/pixiv.js +0 -810
  36. package/dist/pixiv.js.map +0 -1
  37. package/dist/pixiv.test.d.ts +0 -2
  38. package/dist/pixiv.test.d.ts.map +0 -1
  39. package/dist/pixiv.test.js +0 -883
  40. package/dist/pixiv.test.js.map +0 -1
  41. package/dist/saving-responses/index.d.ts +0 -130
  42. package/dist/saving-responses/index.d.ts.map +0 -1
  43. package/dist/saving-responses/index.js +0 -263
  44. package/dist/saving-responses/index.js.map +0 -1
  45. package/dist/saving-responses/index.test.d.ts +0 -2
  46. package/dist/saving-responses/index.test.d.ts.map +0 -1
  47. package/dist/saving-responses/index.test.js +0 -468
  48. package/dist/saving-responses/index.test.js.map +0 -1
  49. package/dist/saving-responses/response-entity.d.ts +0 -16
  50. package/dist/saving-responses/response-entity.d.ts.map +0 -1
  51. package/dist/saving-responses/response-entity.js +0 -101
  52. package/dist/saving-responses/response-entity.js.map +0 -1
  53. package/dist/types/endpoints/v1/illust/bookmark/delete.d.ts +0 -14
  54. package/dist/types/endpoints/v1/illust/bookmark/delete.d.ts.map +0 -1
  55. package/dist/types/endpoints/v1/illust/bookmark/delete.js +0 -3
  56. package/dist/types/endpoints/v1/illust/bookmark/delete.js.map +0 -1
  57. package/dist/types/endpoints/v1/illust/detail.d.ts +0 -25
  58. package/dist/types/endpoints/v1/illust/detail.d.ts.map +0 -1
  59. package/dist/types/endpoints/v1/illust/detail.js +0 -20
  60. package/dist/types/endpoints/v1/illust/detail.js.map +0 -1
  61. package/dist/types/endpoints/v1/illust/ranking.d.ts +0 -51
  62. package/dist/types/endpoints/v1/illust/ranking.d.ts.map +0 -1
  63. package/dist/types/endpoints/v1/illust/ranking.js +0 -40
  64. package/dist/types/endpoints/v1/illust/ranking.js.map +0 -1
  65. package/dist/types/endpoints/v1/illust/recommended.d.ts +0 -104
  66. package/dist/types/endpoints/v1/illust/recommended.d.ts.map +0 -1
  67. package/dist/types/endpoints/v1/illust/recommended.js +0 -44
  68. package/dist/types/endpoints/v1/illust/recommended.js.map +0 -1
  69. package/dist/types/endpoints/v1/illust/series.d.ts +0 -45
  70. package/dist/types/endpoints/v1/illust/series.d.ts.map +0 -1
  71. package/dist/types/endpoints/v1/illust/series.js +0 -31
  72. package/dist/types/endpoints/v1/illust/series.js.map +0 -1
  73. package/dist/types/endpoints/v1/illust/ugoira/metadata.d.ts +0 -25
  74. package/dist/types/endpoints/v1/illust/ugoira/metadata.d.ts.map +0 -1
  75. package/dist/types/endpoints/v1/illust/ugoira/metadata.js +0 -20
  76. package/dist/types/endpoints/v1/illust/ugoira/metadata.js.map +0 -1
  77. package/dist/types/endpoints/v1/manga/recommended.d.ts +0 -72
  78. package/dist/types/endpoints/v1/manga/recommended.d.ts.map +0 -1
  79. package/dist/types/endpoints/v1/manga/recommended.js +0 -33
  80. package/dist/types/endpoints/v1/manga/recommended.js.map +0 -1
  81. package/dist/types/endpoints/v1/novel/bookmark/delete.d.ts +0 -14
  82. package/dist/types/endpoints/v1/novel/bookmark/delete.d.ts.map +0 -1
  83. package/dist/types/endpoints/v1/novel/bookmark/delete.js +0 -3
  84. package/dist/types/endpoints/v1/novel/bookmark/delete.js.map +0 -1
  85. package/dist/types/endpoints/v1/novel/ranking.d.ts +0 -47
  86. package/dist/types/endpoints/v1/novel/ranking.d.ts.map +0 -1
  87. package/dist/types/endpoints/v1/novel/ranking.js +0 -39
  88. package/dist/types/endpoints/v1/novel/ranking.js.map +0 -1
  89. package/dist/types/endpoints/v1/novel/recommended.d.ts +0 -72
  90. package/dist/types/endpoints/v1/novel/recommended.d.ts.map +0 -1
  91. package/dist/types/endpoints/v1/novel/recommended.js +0 -32
  92. package/dist/types/endpoints/v1/novel/recommended.js.map +0 -1
  93. package/dist/types/endpoints/v1/novel/related.d.ts +0 -37
  94. package/dist/types/endpoints/v1/novel/related.d.ts.map +0 -1
  95. package/dist/types/endpoints/v1/novel/related.js +0 -24
  96. package/dist/types/endpoints/v1/novel/related.js.map +0 -1
  97. package/dist/types/endpoints/v1/search/illust.d.ts +0 -109
  98. package/dist/types/endpoints/v1/search/illust.d.ts.map +0 -1
  99. package/dist/types/endpoints/v1/search/illust.js +0 -40
  100. package/dist/types/endpoints/v1/search/illust.js.map +0 -1
  101. package/dist/types/endpoints/v1/search/novel.d.ts +0 -103
  102. package/dist/types/endpoints/v1/search/novel.d.ts.map +0 -1
  103. package/dist/types/endpoints/v1/search/novel.js +0 -38
  104. package/dist/types/endpoints/v1/search/novel.js.map +0 -1
  105. package/dist/types/endpoints/v1/user/bookmarks/illust.d.ts +0 -48
  106. package/dist/types/endpoints/v1/user/bookmarks/illust.d.ts.map +0 -1
  107. package/dist/types/endpoints/v1/user/bookmarks/illust.js +0 -31
  108. package/dist/types/endpoints/v1/user/bookmarks/illust.js.map +0 -1
  109. package/dist/types/endpoints/v1/user/bookmarks/novel.d.ts +0 -44
  110. package/dist/types/endpoints/v1/user/bookmarks/novel.d.ts.map +0 -1
  111. package/dist/types/endpoints/v1/user/bookmarks/novel.js +0 -28
  112. package/dist/types/endpoints/v1/user/bookmarks/novel.js.map +0 -1
  113. package/dist/types/endpoints/v1/user/detail.d.ts +0 -44
  114. package/dist/types/endpoints/v1/user/detail.d.ts.map +0 -1
  115. package/dist/types/endpoints/v1/user/detail.js +0 -26
  116. package/dist/types/endpoints/v1/user/detail.js.map +0 -1
  117. package/dist/types/endpoints/v1/user/follow/add.d.ts +0 -24
  118. package/dist/types/endpoints/v1/user/follow/add.d.ts.map +0 -1
  119. package/dist/types/endpoints/v1/user/follow/add.js +0 -3
  120. package/dist/types/endpoints/v1/user/follow/add.js.map +0 -1
  121. package/dist/types/endpoints/v1/user/follow/delete.d.ts +0 -14
  122. package/dist/types/endpoints/v1/user/follow/delete.d.ts.map +0 -1
  123. package/dist/types/endpoints/v1/user/follow/delete.js +0 -3
  124. package/dist/types/endpoints/v1/user/follow/delete.js.map +0 -1
  125. package/dist/types/endpoints/v1/user/following.d.ts +0 -38
  126. package/dist/types/endpoints/v1/user/following.d.ts.map +0 -1
  127. package/dist/types/endpoints/v1/user/following.js +0 -26
  128. package/dist/types/endpoints/v1/user/following.js.map +0 -1
  129. package/dist/types/endpoints/v1/user/illusts.d.ts +0 -51
  130. package/dist/types/endpoints/v1/user/illusts.d.ts.map +0 -1
  131. package/dist/types/endpoints/v1/user/illusts.js +0 -31
  132. package/dist/types/endpoints/v1/user/illusts.js.map +0 -1
  133. package/dist/types/endpoints/v1/user/novels.d.ts +0 -43
  134. package/dist/types/endpoints/v1/user/novels.d.ts.map +0 -1
  135. package/dist/types/endpoints/v1/user/novels.js +0 -29
  136. package/dist/types/endpoints/v1/user/novels.js.map +0 -1
  137. package/dist/types/endpoints/v2/illust/bookmark/add.d.ts +0 -28
  138. package/dist/types/endpoints/v2/illust/bookmark/add.d.ts.map +0 -1
  139. package/dist/types/endpoints/v2/illust/bookmark/add.js +0 -3
  140. package/dist/types/endpoints/v2/illust/bookmark/add.js.map +0 -1
  141. package/dist/types/endpoints/v2/illust/related.d.ts +0 -48
  142. package/dist/types/endpoints/v2/illust/related.d.ts.map +0 -1
  143. package/dist/types/endpoints/v2/illust/related.js +0 -32
  144. package/dist/types/endpoints/v2/illust/related.js.map +0 -1
  145. package/dist/types/endpoints/v2/novel/bookmark/add.d.ts +0 -27
  146. package/dist/types/endpoints/v2/novel/bookmark/add.d.ts.map +0 -1
  147. package/dist/types/endpoints/v2/novel/bookmark/add.js +0 -3
  148. package/dist/types/endpoints/v2/novel/bookmark/add.js.map +0 -1
  149. package/dist/types/endpoints/v2/novel/detail.d.ts +0 -25
  150. package/dist/types/endpoints/v2/novel/detail.d.ts.map +0 -1
  151. package/dist/types/endpoints/v2/novel/detail.js +0 -20
  152. package/dist/types/endpoints/v2/novel/detail.js.map +0 -1
  153. package/dist/types/endpoints/v2/novel/series.d.ts +0 -49
  154. package/dist/types/endpoints/v2/novel/series.d.ts.map +0 -1
  155. package/dist/types/endpoints/v2/novel/series.js +0 -31
  156. package/dist/types/endpoints/v2/novel/series.js.map +0 -1
  157. package/dist/types/endpoints/webview/v2/novel.d.ts +0 -21
  158. package/dist/types/endpoints/webview/v2/novel.d.ts.map +0 -1
  159. package/dist/types/endpoints/webview/v2/novel.js +0 -18
  160. package/dist/types/endpoints/webview/v2/novel.js.map +0 -1
  161. package/dist/types/error-response.d.ts +0 -31
  162. package/dist/types/error-response.d.ts.map +0 -1
  163. package/dist/types/error-response.js +0 -3
  164. package/dist/types/error-response.js.map +0 -1
  165. package/dist/types/errors.d.ts +0 -7
  166. package/dist/types/errors.d.ts.map +0 -1
  167. package/dist/types/errors.js +0 -14
  168. package/dist/types/errors.js.map +0 -1
  169. package/dist/types/pixiv-common.d.ts +0 -103
  170. package/dist/types/pixiv-common.d.ts.map +0 -1
  171. package/dist/types/pixiv-common.js +0 -68
  172. package/dist/types/pixiv-common.js.map +0 -1
  173. package/dist/types/pixiv-illust-series.d.ts +0 -56
  174. package/dist/types/pixiv-illust-series.d.ts.map +0 -1
  175. package/dist/types/pixiv-illust-series.js +0 -26
  176. package/dist/types/pixiv-illust-series.js.map +0 -1
  177. package/dist/types/pixiv-illust.d.ts +0 -180
  178. package/dist/types/pixiv-illust.d.ts.map +0 -1
  179. package/dist/types/pixiv-illust.js +0 -56
  180. package/dist/types/pixiv-illust.js.map +0 -1
  181. package/dist/types/pixiv-novel-series.d.ts +0 -84
  182. package/dist/types/pixiv-novel-series.d.ts.map +0 -1
  183. package/dist/types/pixiv-novel-series.js +0 -43
  184. package/dist/types/pixiv-novel-series.js.map +0 -1
  185. package/dist/types/pixiv-novel.d.ts +0 -131
  186. package/dist/types/pixiv-novel.d.ts.map +0 -1
  187. package/dist/types/pixiv-novel.js +0 -44
  188. package/dist/types/pixiv-novel.js.map +0 -1
  189. package/dist/types/pixiv-ugoira.d.ts +0 -50
  190. package/dist/types/pixiv-ugoira.d.ts.map +0 -1
  191. package/dist/types/pixiv-ugoira.js +0 -34
  192. package/dist/types/pixiv-ugoira.js.map +0 -1
  193. package/dist/types/pixiv-user.d.ts +0 -212
  194. package/dist/types/pixiv-user.d.ts.map +0 -1
  195. package/dist/types/pixiv-user.js +0 -118
  196. package/dist/types/pixiv-user.js.map +0 -1
  197. package/dist/utils.d.ts +0 -3
  198. package/dist/utils.d.ts.map +0 -1
  199. package/dist/utils.js +0 -15
  200. package/dist/utils.js.map +0 -1
  201. package/dist/utils.test.d.ts +0 -2
  202. package/dist/utils.test.d.ts.map +0 -1
  203. package/dist/utils.test.js +0 -15
  204. package/dist/utils.test.js.map +0 -1
package/dist/pixiv.js DELETED
@@ -1,810 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_crypto_1 = __importDefault(require("node:crypto"));
7
- const qs_1 = __importDefault(require("qs"));
8
- const options_1 = require("./options");
9
- const http_client_1 = require("./http-client");
10
- const saving_responses_1 = require("./saving-responses");
11
- /**
12
- * pixiv API
13
- */
14
- class Pixiv {
15
- /**
16
- * Constructor. Cannot be instantiated externally; use the `of` method instead.
17
- *
18
- * @param userId User ID
19
- * @param accessToken Access token
20
- * @param refreshToken Refresh token
21
- * @param responseDatabase Database for saving responses (null if not used)
22
- * @param rateLimitRetryOptions Retry settings for 429 errors
23
- */
24
- constructor(userId, accessToken, refreshToken, responseDatabase, rateLimitRetryOptions) {
25
- this.hosts = 'https://app-api.pixiv.net';
26
- this.userId = userId;
27
- this.accessToken = accessToken;
28
- this.refreshToken = refreshToken;
29
- this.responseDatabase = responseDatabase ?? null;
30
- this.rateLimitRetryOptions = rateLimitRetryOptions ?? null;
31
- this.http = new http_client_1.PixivHttpClient(this.hosts, {
32
- Host: 'app-api.pixiv.net',
33
- 'App-OS': 'ios',
34
- 'App-OS-Version': '14.6',
35
- 'User-Agent': 'PixivIOSApp/7.13.3 (iOS 14.6; iPhone13,2)',
36
- 'Accept-Language': 'ja',
37
- Authorization: `Bearer ${this.accessToken}`,
38
- }, this.rateLimitRetryOptions);
39
- }
40
- /**
41
- * Creates an instance from a refresh token.
42
- *
43
- * @param refreshToken Refresh token
44
- * @returns Pixiv instance
45
- */
46
- static async of(refreshToken, pixivTsOptions) {
47
- // @see https://github.com/upbit/pixivpy/blob/master/pixivpy3/api.py#L120
48
- // Get the current time in UTC, formatted as YYYY-MM-DDTHH:mm:ss+00:00
49
- const localTime = new Date().toISOString().replace(/Z$/, '+00:00');
50
- const headers = {
51
- 'x-client-time': localTime,
52
- 'x-client-hash': this.hash(localTime),
53
- 'app-os': 'ios',
54
- 'app-os-version': '16.4.1',
55
- 'user-agent': ' PixivIOSApp/7.16.9 (iOS 16.4.1; iPad13,4)',
56
- header: 'application/x-www-form-urlencoded',
57
- };
58
- const authUrl = 'https://oauth.secure.pixiv.net/auth/token';
59
- const data = qs_1.default.stringify({
60
- client_id: this.clientId,
61
- client_secret: this.clientSecret,
62
- get_secure_url: 1,
63
- grant_type: 'refresh_token',
64
- refresh_token: refreshToken,
65
- });
66
- const response = await fetch(authUrl, {
67
- method: 'POST',
68
- headers: {
69
- ...headers,
70
- 'Content-Type': 'application/x-www-form-urlencoded',
71
- },
72
- body: data,
73
- });
74
- if (response.status !== 200) {
75
- throw new Error('Failed to refresh token');
76
- }
77
- const responseData = (await response.json());
78
- const options = {
79
- userId: responseData.user.id,
80
- accessToken: responseData.response.access_token,
81
- refreshToken: responseData.response.refresh_token,
82
- };
83
- const responseDatabase = pixivTsOptions?.debugOptions?.outputResponse
84
- ?.enable
85
- ? new saving_responses_1.ResponseDatabase(pixivTsOptions.debugOptions.outputResponse.db)
86
- : null;
87
- if (responseDatabase) {
88
- await responseDatabase.init();
89
- await responseDatabase.migrate();
90
- await responseDatabase.sync();
91
- }
92
- return new Pixiv(options.userId, options.accessToken, options.refreshToken, responseDatabase, pixivTsOptions?.rateLimitRetryOptions);
93
- }
94
- /**
95
- * Returns a `Response` for fetching an image.
96
- *
97
- * The return value is a `Response` object, not the stream itself;
98
- * to read it as a stream, refer to `response.body`.
99
- * Other `Response` APIs such as `arrayBuffer()` can also be used as needed.
100
- *
101
- * @param url Image URL
102
- * @returns The `Response` from fetching the image
103
- */
104
- static async getImageStream(url) {
105
- return fetch(url, {
106
- headers: {
107
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
108
- Referer: 'https://www.pixiv.net/',
109
- },
110
- });
111
- }
112
- // ---------- Illust ---------- //
113
- /**
114
- * Gets the details of an illust.
115
- *
116
- * @param options Options
117
- * @returns Response
118
- */
119
- async illustDetail(options) {
120
- const parameters = {
121
- ...this.convertCamelToSnake(options),
122
- illust_id: options.illustId,
123
- };
124
- return this.request({
125
- method: 'GET',
126
- path: '/v1/illust/detail',
127
- params: parameters,
128
- });
129
- }
130
- /**
131
- * Gets illusts related to an illust.
132
- *
133
- * @param options Options
134
- * @returns Response
135
- */
136
- async illustRelated(options) {
137
- this.checkRequiredOptions(options, ['illustId']);
138
- const parameters = {
139
- ...this.convertCamelToSnake(options),
140
- illust_id: options.illustId,
141
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
142
- seed_illust_ids: options.seedIllustIds,
143
- viewed: options.viewed,
144
- offset: options.offset,
145
- };
146
- return this.request({
147
- method: 'GET',
148
- path: '/v2/illust/related',
149
- params: parameters,
150
- });
151
- }
152
- /**
153
- * Searches for illusts.
154
- *
155
- * @param options Options
156
- * @returns Response
157
- */
158
- async searchIllust(options) {
159
- this.checkRequiredOptions(options, ['word']);
160
- const parameters = {
161
- ...this.convertCamelToSnake(options),
162
- word: options.word, // required
163
- search_target: options.searchTarget ?? options_1.SearchTarget.PARTIAL_MATCH_FOR_TAGS,
164
- sort: options.sort ?? options_1.SearchSort.DATE_DESC,
165
- start_date: options.startDate,
166
- end_date: options.endDate,
167
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
168
- offset: options.offset,
169
- merge_plain_keyword_results: options.mergePlainKeywordResults ?? true,
170
- include_translated_tag_results: options.includeTranslatedTagResults ?? true,
171
- duration: options.duration,
172
- search_ai_type: options.searchAiType,
173
- };
174
- return this.request({
175
- method: 'GET',
176
- path: '/v1/search/illust',
177
- params: parameters,
178
- });
179
- }
180
- /**
181
- * Gets the illust ranking.
182
- *
183
- * @param options Options
184
- * @returns Response
185
- */
186
- async illustRanking(options = {}) {
187
- const parameters = {
188
- ...this.convertCamelToSnake(options),
189
- mode: options.mode ?? options_1.RankingMode.DAY,
190
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
191
- date: options.date ?? undefined,
192
- offset: options.offset ?? undefined,
193
- };
194
- return this.request({
195
- method: 'GET',
196
- path: '/v1/illust/ranking',
197
- params: parameters,
198
- });
199
- }
200
- /**
201
- * Gets recommended illusts.
202
- *
203
- * @param options Options
204
- * @returns Response
205
- */
206
- async illustRecommended(options = {}) {
207
- const parameters = {
208
- ...this.convertCamelToSnake(options),
209
- content_type: options.contentType ?? options_1.IllustContentType.ILLUST,
210
- include_ranking_label: options.includeRankingLabel ?? true,
211
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
212
- include_ranking_illusts: options.includeRankingIllusts ?? true,
213
- min_bookmark_id_for_recent_illust: options.minBookmarkIdForRecentIllust ?? undefined,
214
- max_bookmark_id_for_recommend: options.maxBookmarkIdForRecommend ?? undefined,
215
- offset: options.offset ?? undefined,
216
- include_privacy_policy: options.includePrivacyPolicy ?? true,
217
- viewed: options.viewed,
218
- };
219
- return this.request({
220
- method: 'GET',
221
- path: '/v1/illust/recommended',
222
- params: parameters,
223
- });
224
- }
225
- /**
226
- * Gets the details of an illust series.
227
- *
228
- * @param options Options
229
- * @returns Response
230
- */
231
- async illustSeries(options) {
232
- this.checkRequiredOptions(options, ['illustSeriesId']);
233
- const parameters = {
234
- ...this.convertCamelToSnake(options),
235
- illust_series_id: options.illustSeriesId,
236
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
237
- // offset: options.offset,
238
- };
239
- return this.request({
240
- method: 'GET',
241
- path: '/v1/illust/series',
242
- params: parameters,
243
- });
244
- }
245
- /**
246
- * Bookmarks an illust.
247
- *
248
- * @param options Options
249
- * @returns Response
250
- */
251
- async illustBookmarkAdd(options) {
252
- this.checkRequiredOptions(options, ['illustId']);
253
- const data = {
254
- ...this.convertCamelToSnake(options),
255
- illust_id: options.illustId,
256
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
257
- tags: options.tags ?? [],
258
- };
259
- return this.request({
260
- method: 'POST',
261
- path: '/v2/illust/bookmark/add',
262
- data,
263
- });
264
- }
265
- /**
266
- * Removes an illust bookmark.
267
- *
268
- * @param options Options
269
- * @returns Response
270
- */
271
- async illustBookmarkDelete(options) {
272
- this.checkRequiredOptions(options, ['illustId']);
273
- const data = {
274
- ...this.convertCamelToSnake(options),
275
- illust_id: options.illustId,
276
- };
277
- return this.request({
278
- method: 'POST',
279
- path: '/v1/illust/bookmark/delete',
280
- data,
281
- });
282
- }
283
- // ---------- Manga ---------- //
284
- async mangaRecommended(options = {}) {
285
- const parameters = {
286
- ...this.convertCamelToSnake(options),
287
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
288
- include_ranking_illusts: options.includeRankingIllusts ?? true,
289
- max_bookmark_id: options.maxBookmarkId ?? undefined,
290
- offset: options.offset ?? undefined,
291
- include_privacy_policy: options.includePrivacyPolicy ?? true,
292
- };
293
- return this.request({
294
- method: 'GET',
295
- path: '/v1/manga/recommended',
296
- params: parameters,
297
- });
298
- }
299
- // ---------- Ugoira ---------- //
300
- /**
301
- * Gets the details of an ugoira.
302
- *
303
- * @param options Options
304
- * @returns Response
305
- */
306
- async ugoiraMetadata(options) {
307
- const parameters = {
308
- ...this.convertCamelToSnake(options),
309
- illust_id: options.illustId,
310
- };
311
- return this.request({
312
- method: 'GET',
313
- path: '/v1/ugoira/metadata',
314
- params: parameters,
315
- });
316
- }
317
- // ---------- Novel ---------- //
318
- /**
319
- * Gets the details of a novel.
320
- *
321
- * @param options Options
322
- * @returns Response
323
- */
324
- async novelDetail(options) {
325
- this.checkRequiredOptions(options, ['novelId']);
326
- const parameters = {
327
- ...this.convertCamelToSnake(options),
328
- novel_id: options.novelId,
329
- };
330
- return this.request({
331
- method: 'GET',
332
- path: '/v2/novel/detail',
333
- params: parameters,
334
- });
335
- }
336
- /**
337
- * Gets the text of a novel.
338
- *
339
- * @param options Options
340
- * @returns Response
341
- */
342
- async novelText(options) {
343
- this.checkRequiredOptions(options, ['id']);
344
- const parameters = {
345
- ...this.convertCamelToSnake(options),
346
- id: options.id,
347
- };
348
- return await this.request({
349
- method: 'GET',
350
- path: '/webview/v2/novel',
351
- params: parameters,
352
- });
353
- }
354
- /**
355
- * Gets novels related to a novel.
356
- *
357
- * @param options Options
358
- * @returns Response
359
- */
360
- async novelRelated(options) {
361
- this.checkRequiredOptions(options, ['novelId']);
362
- const parameters = {
363
- ...this.convertCamelToSnake(options),
364
- novel_id: options.novelId,
365
- seed_novel_ids: options.seedNovelIds,
366
- viewed: options.viewed,
367
- };
368
- return this.request({
369
- method: 'GET',
370
- path: '/v1/novel/related',
371
- params: parameters,
372
- });
373
- }
374
- /**
375
- * Searches for novels.
376
- *
377
- * @param options Options
378
- * @returns Response
379
- */
380
- async searchNovel(options) {
381
- this.checkRequiredOptions(options, ['word']);
382
- const parameters = {
383
- ...this.convertCamelToSnake(options),
384
- word: options.word, // required
385
- search_target: options.searchTarget ?? options_1.SearchTarget.PARTIAL_MATCH_FOR_TAGS,
386
- sort: options.sort ?? options_1.SearchSort.DATE_DESC,
387
- start_date: options.startDate,
388
- end_date: options.endDate,
389
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
390
- offset: options.offset,
391
- merge_plain_keyword_results: options.mergePlainKeywordResults ?? true,
392
- include_translated_tag_results: options.includeTranslatedTagResults ?? true,
393
- search_ai_type: options.searchAiType,
394
- };
395
- return this.request({
396
- method: 'GET',
397
- path: '/v1/search/novel',
398
- params: parameters,
399
- });
400
- }
401
- /**
402
- * Gets the novel ranking.
403
- */
404
- async novelRanking(options = {}) {
405
- const parameters = {
406
- ...this.convertCamelToSnake(options),
407
- mode: options.mode ?? options_1.RankingMode.DAY,
408
- date: options.date ?? undefined,
409
- offset: options.offset ?? undefined,
410
- };
411
- return this.request({
412
- method: 'GET',
413
- path: '/v1/novel/ranking',
414
- params: parameters,
415
- });
416
- }
417
- /**
418
- * Gets recommended novels.
419
- *
420
- * @param options Options
421
- * @returns Response
422
- */
423
- async novelRecommended(options = {}) {
424
- const parameters = {
425
- ...this.convertCamelToSnake(options),
426
- // filter: options.filter ?? 'for_ios',
427
- include_ranking_novels: options.includeRankingNovels ?? true,
428
- already_recommended: options.alreadyRecommended
429
- ? options.alreadyRecommended.join(',')
430
- : undefined,
431
- max_bookmark_id_for_recommend: options.maxBookmarkIdForRecommend ?? undefined,
432
- offset: options.offset ?? undefined,
433
- include_privacy_policy: options.includePrivacyPolicy ?? true,
434
- };
435
- return this.request({
436
- method: 'GET',
437
- path: '/v1/novel/recommended',
438
- params: parameters,
439
- });
440
- }
441
- /**
442
- * Gets the details of a novel series.
443
- *
444
- * @param options Options
445
- * @returns Response
446
- */
447
- async novelSeries(options) {
448
- this.checkRequiredOptions(options, ['seriesId']);
449
- const parameters = {
450
- ...this.convertCamelToSnake(options),
451
- series_id: options.seriesId,
452
- // filter: options.filter ?? 'for_ios',
453
- last_order: options.lastOrder ?? undefined,
454
- };
455
- return this.request({
456
- method: 'GET',
457
- path: '/v2/novel/series',
458
- params: parameters,
459
- });
460
- }
461
- /**
462
- * Bookmarks a novel.
463
- *
464
- * @param options Options
465
- * @returns Response
466
- */
467
- async novelBookmarkAdd(options) {
468
- this.checkRequiredOptions(options, ['novelId']);
469
- const data = {
470
- ...this.convertCamelToSnake(options),
471
- novel_id: options.novelId,
472
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
473
- tags: options.tags ?? [],
474
- };
475
- return this.request({
476
- method: 'POST',
477
- path: '/v2/novel/bookmark/add',
478
- data,
479
- });
480
- }
481
- /**
482
- * Removes a novel bookmark.
483
- *
484
- * @param options Options
485
- * @returns Response
486
- */
487
- async novelBookmarkDelete(options) {
488
- this.checkRequiredOptions(options, ['novelId']);
489
- const data = {
490
- ...this.convertCamelToSnake(options),
491
- novel_id: options.novelId,
492
- };
493
- return this.request({
494
- method: 'POST',
495
- path: '/v1/novel/bookmark/delete',
496
- data,
497
- });
498
- }
499
- // ---------- User ---------- //
500
- /**
501
- * Gets the details of a user.
502
- *
503
- * @param options Options
504
- * @returns Response
505
- */
506
- async userDetail(options) {
507
- this.checkRequiredOptions(options, ['userId']);
508
- const parameters = {
509
- ...this.convertCamelToSnake(options),
510
- user_id: options.userId,
511
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
512
- };
513
- return this.request({
514
- method: 'GET',
515
- path: '/v1/user/detail',
516
- params: parameters,
517
- });
518
- }
519
- /**
520
- * Gets a user's illusts or manga.
521
- *
522
- * @param options Options
523
- * @returns Response
524
- */
525
- async userIllusts(options) {
526
- this.checkRequiredOptions(options, ['userId']);
527
- const parameters = {
528
- ...this.convertCamelToSnake(options),
529
- user_id: options.userId,
530
- type: options.type ?? undefined,
531
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
532
- offset: options.offset ?? undefined,
533
- };
534
- return this.request({
535
- method: 'GET',
536
- path: '/v1/user/illusts',
537
- params: parameters,
538
- });
539
- }
540
- /**
541
- * Gets a user's novels.
542
- *
543
- * @param options Options
544
- * @returns Response
545
- */
546
- async userNovels(options) {
547
- this.checkRequiredOptions(options, ['userId']);
548
- const parameters = {
549
- ...this.convertCamelToSnake(options),
550
- user_id: options.userId,
551
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
552
- offset: options.offset ?? undefined,
553
- };
554
- return this.request({
555
- method: 'GET',
556
- path: '/v1/user/novels',
557
- params: parameters,
558
- });
559
- }
560
- /**
561
- * Gets a user's illust bookmarks.
562
- *
563
- * @param options Options
564
- * @returns Response
565
- */
566
- async userBookmarksIllust(options) {
567
- this.checkRequiredOptions(options, ['userId']);
568
- const parameters = {
569
- ...this.convertCamelToSnake(options),
570
- user_id: options.userId,
571
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
572
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
573
- max_bookmark_id: options.maxBookmarkId ?? undefined,
574
- tag: options.tag ?? undefined,
575
- };
576
- return this.request({
577
- method: 'GET',
578
- path: '/v1/user/bookmarks/illust',
579
- params: parameters,
580
- });
581
- }
582
- /**
583
- * Gets a user's novel bookmarks.
584
- *
585
- * @param options Options
586
- * @returns Response
587
- */
588
- async userBookmarksNovel(options) {
589
- this.checkRequiredOptions(options, ['userId']);
590
- const parameters = {
591
- ...this.convertCamelToSnake(options),
592
- user_id: options.userId,
593
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
594
- max_bookmark_id: options.maxBookmarkId ?? undefined,
595
- tag: options.tag ?? undefined,
596
- };
597
- return this.request({
598
- method: 'GET',
599
- path: '/v1/user/bookmarks/novel',
600
- params: parameters,
601
- });
602
- }
603
- /**
604
- * Gets the list of users a user is following.
605
- *
606
- * @param options Options
607
- * @returns Response
608
- */
609
- async userFollowing(options) {
610
- this.checkRequiredOptions(options, ['userId']);
611
- const parameters = {
612
- ...this.convertCamelToSnake(options),
613
- user_id: options.userId,
614
- restrict: options.restrict ?? options_1.FollowRestrict.PUBLIC,
615
- offset: options.offset ?? undefined,
616
- };
617
- return this.request({
618
- method: 'GET',
619
- path: '/v1/user/following',
620
- params: parameters,
621
- });
622
- }
623
- /**
624
- * Follows a user.
625
- *
626
- * @param options Options
627
- * @returns Response
628
- */
629
- async userFollowAdd(options) {
630
- this.checkRequiredOptions(options, ['userId']);
631
- const data = {
632
- ...this.convertCamelToSnake(options),
633
- user_id: options.userId,
634
- restrict: options.restrict ?? options_1.FollowRestrict.PUBLIC,
635
- };
636
- return this.request({
637
- method: 'POST',
638
- path: '/v1/user/follow/add',
639
- data,
640
- });
641
- }
642
- /**
643
- * Unfollows a user.
644
- *
645
- * @param options Options
646
- * @returns Response
647
- */
648
- async userFollowDelete(options) {
649
- this.checkRequiredOptions(options, ['userId']);
650
- const data = {
651
- ...this.convertCamelToSnake(options),
652
- user_id: options.userId,
653
- };
654
- return this.request({
655
- method: 'POST',
656
- path: '/v1/user/follow/delete',
657
- data,
658
- });
659
- }
660
- // ---------- Others ---------- //
661
- /**
662
- * Closes the connection.
663
- */
664
- async close() {
665
- if (this.responseDatabase) {
666
- await this.responseDatabase.close();
667
- }
668
- }
669
- // ---------- Utilities ---------- //
670
- /**
671
- * Parses a query string.
672
- *
673
- * @param url URL
674
- * @returns The parsed query string object
675
- */
676
- static parseQueryString(url) {
677
- let query = url;
678
- if (url.includes('?')) {
679
- query = url.split('?', 2)[1];
680
- }
681
- return qs_1.default.parse(query);
682
- }
683
- /**
684
- * Determines whether the response is an error.
685
- *
686
- * @param response Axios response
687
- * @returns Whether it is an error
688
- */
689
- static isError(response) {
690
- return (
691
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
692
- response.error !== undefined &&
693
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
694
- response.error.user_message !== undefined &&
695
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
696
- response.error.message !== undefined &&
697
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
698
- response.error.reason !== undefined);
699
- }
700
- /**
701
- * Generates an MD5 hash.
702
- *
703
- * @param str String
704
- * @returns Hash
705
- */
706
- static hash(string) {
707
- const hash = node_crypto_1.default.createHash('md5');
708
- return hash.update(string + this.hashSecret).digest('hex');
709
- }
710
- /**
711
- * Sends a request.
712
- *
713
- * The order of generics is T: request, U: response.
714
- *
715
- * @param options Options
716
- * @returns Response
717
- */
718
- async request(options) {
719
- if (options.method === 'GET') {
720
- return await this.saveResponse(options, await this.http.get(options.path, {
721
- params: options.params,
722
- }));
723
- }
724
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
725
- if (options.method === 'POST') {
726
- return await this.saveResponse(options, await this.http.post(options.path, qs_1.default.stringify(options.data), {
727
- headers: {
728
- 'Content-Type': 'application/x-www-form-urlencoded',
729
- },
730
- }));
731
- }
732
- throw new Error('Invalid method');
733
- }
734
- async saveResponse(request, response) {
735
- if (this.responseDatabase === null) {
736
- return response;
737
- }
738
- const method = request.method;
739
- const path = request.path;
740
- const rawUrl = [
741
- this.hosts,
742
- path,
743
- method === 'GET'
744
- ? qs_1.default.stringify(request.params, { addQueryPrefix: true })
745
- : '',
746
- ].join('');
747
- const url = response.responseUrl ?? rawUrl;
748
- const responseType = this.isJSON(response.data) ? 'JSON' : 'TEXT';
749
- const responseBody = responseType === 'JSON'
750
- ? JSON.stringify(response.data)
751
- : response.data;
752
- await this.responseDatabase.addResponse({
753
- method,
754
- endpoint: path,
755
- url,
756
- requestHeaders: JSON.stringify(response.requestHeaders),
757
- requestBody: response.requestBody,
758
- responseType,
759
- statusCode: response.status,
760
- responseHeaders: JSON.stringify(response.headers),
761
- responseBody,
762
- });
763
- return response;
764
- }
765
- isJSON(value) {
766
- if (typeof value === 'object') {
767
- return true;
768
- }
769
- try {
770
- JSON.parse(value);
771
- return true;
772
- }
773
- catch {
774
- return false;
775
- }
776
- }
777
- /**
778
- * Checks whether the required options are included.
779
- *
780
- * @param options Options
781
- * @param required Required option keys
782
- * @throws If a required option is missing
783
- */
784
- checkRequiredOptions(options, required) {
785
- for (const key of required) {
786
- if (options[key] === undefined) {
787
- throw new Error(`Missing required option: ${key}`);
788
- }
789
- }
790
- }
791
- /**
792
- * Converts camelCase object keys to snake_case object keys.
793
- *
794
- * @param object Object
795
- * @returns The converted object
796
- */
797
- convertCamelToSnake(object) {
798
- const result = {};
799
- for (const key of Object.keys(object)) {
800
- const snakeKey = key.replaceAll(/([A-Z])/g, (m) => `_${m[0].toLowerCase()}`);
801
- result[snakeKey] = object[key];
802
- }
803
- return result;
804
- }
805
- }
806
- Pixiv.clientId = 'MOBrBDS8blbauoSck0ZfDbtuzpyT';
807
- Pixiv.clientSecret = 'lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj';
808
- Pixiv.hashSecret = '28c1fdd170a5204386cb1313c7077b34f83e4aaf4aa829ce78c231e05b0bae2c';
809
- exports.default = Pixiv;
810
- //# sourceMappingURL=pixiv.js.map