@book000/pixivts 0.46.48 → 0.46.50

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 (170) hide show
  1. package/package.json +3 -3
  2. package/dist/checks.d.ts +0 -19
  3. package/dist/checks.d.ts.map +0 -1
  4. package/dist/checks.js +0 -85
  5. package/dist/checks.js.map +0 -1
  6. package/dist/checks.test.d.ts +0 -2
  7. package/dist/checks.test.d.ts.map +0 -1
  8. package/dist/checks.test.js +0 -306
  9. package/dist/checks.test.js.map +0 -1
  10. package/dist/index.d.ts +0 -30
  11. package/dist/index.d.ts.map +0 -1
  12. package/dist/index.js +0 -51
  13. package/dist/index.js.map +0 -1
  14. package/dist/options.d.ts +0 -248
  15. package/dist/options.d.ts.map +0 -1
  16. package/dist/options.js +0 -154
  17. package/dist/options.js.map +0 -1
  18. package/dist/options.test.d.ts +0 -2
  19. package/dist/options.test.d.ts.map +0 -1
  20. package/dist/options.test.js +0 -117
  21. package/dist/options.test.js.map +0 -1
  22. package/dist/pixiv.d.ts +0 -268
  23. package/dist/pixiv.d.ts.map +0 -1
  24. package/dist/pixiv.js +0 -698
  25. package/dist/pixiv.js.map +0 -1
  26. package/dist/pixiv.test.d.ts +0 -2
  27. package/dist/pixiv.test.d.ts.map +0 -1
  28. package/dist/pixiv.test.js +0 -729
  29. package/dist/pixiv.test.js.map +0 -1
  30. package/dist/saving-responses/index.d.ts +0 -119
  31. package/dist/saving-responses/index.d.ts.map +0 -1
  32. package/dist/saving-responses/index.js +0 -263
  33. package/dist/saving-responses/index.js.map +0 -1
  34. package/dist/saving-responses/index.test.d.ts +0 -2
  35. package/dist/saving-responses/index.test.d.ts.map +0 -1
  36. package/dist/saving-responses/index.test.js +0 -469
  37. package/dist/saving-responses/index.test.js.map +0 -1
  38. package/dist/saving-responses/response-entity.d.ts +0 -16
  39. package/dist/saving-responses/response-entity.d.ts.map +0 -1
  40. package/dist/saving-responses/response-entity.js +0 -101
  41. package/dist/saving-responses/response-entity.js.map +0 -1
  42. package/dist/tsconfig.build.tsbuildinfo +0 -1
  43. package/dist/types/endpoints/v1/illust/bookmark/delete.d.ts +0 -14
  44. package/dist/types/endpoints/v1/illust/bookmark/delete.d.ts.map +0 -1
  45. package/dist/types/endpoints/v1/illust/bookmark/delete.js +0 -3
  46. package/dist/types/endpoints/v1/illust/bookmark/delete.js.map +0 -1
  47. package/dist/types/endpoints/v1/illust/detail.d.ts +0 -25
  48. package/dist/types/endpoints/v1/illust/detail.d.ts.map +0 -1
  49. package/dist/types/endpoints/v1/illust/detail.js +0 -20
  50. package/dist/types/endpoints/v1/illust/detail.js.map +0 -1
  51. package/dist/types/endpoints/v1/illust/ranking.d.ts +0 -51
  52. package/dist/types/endpoints/v1/illust/ranking.d.ts.map +0 -1
  53. package/dist/types/endpoints/v1/illust/ranking.js +0 -40
  54. package/dist/types/endpoints/v1/illust/ranking.js.map +0 -1
  55. package/dist/types/endpoints/v1/illust/recommended.d.ts +0 -85
  56. package/dist/types/endpoints/v1/illust/recommended.d.ts.map +0 -1
  57. package/dist/types/endpoints/v1/illust/recommended.js +0 -37
  58. package/dist/types/endpoints/v1/illust/recommended.js.map +0 -1
  59. package/dist/types/endpoints/v1/illust/series.d.ts +0 -45
  60. package/dist/types/endpoints/v1/illust/series.d.ts.map +0 -1
  61. package/dist/types/endpoints/v1/illust/series.js +0 -31
  62. package/dist/types/endpoints/v1/illust/series.js.map +0 -1
  63. package/dist/types/endpoints/v1/illust/ugoira/metadata.d.ts +0 -25
  64. package/dist/types/endpoints/v1/illust/ugoira/metadata.d.ts.map +0 -1
  65. package/dist/types/endpoints/v1/illust/ugoira/metadata.js +0 -20
  66. package/dist/types/endpoints/v1/illust/ugoira/metadata.js.map +0 -1
  67. package/dist/types/endpoints/v1/manga/recommended.d.ts +0 -72
  68. package/dist/types/endpoints/v1/manga/recommended.d.ts.map +0 -1
  69. package/dist/types/endpoints/v1/manga/recommended.js +0 -33
  70. package/dist/types/endpoints/v1/manga/recommended.js.map +0 -1
  71. package/dist/types/endpoints/v1/novel/bookmark/delete.d.ts +0 -14
  72. package/dist/types/endpoints/v1/novel/bookmark/delete.d.ts.map +0 -1
  73. package/dist/types/endpoints/v1/novel/bookmark/delete.js +0 -3
  74. package/dist/types/endpoints/v1/novel/bookmark/delete.js.map +0 -1
  75. package/dist/types/endpoints/v1/novel/ranking.d.ts +0 -47
  76. package/dist/types/endpoints/v1/novel/ranking.d.ts.map +0 -1
  77. package/dist/types/endpoints/v1/novel/ranking.js +0 -39
  78. package/dist/types/endpoints/v1/novel/ranking.js.map +0 -1
  79. package/dist/types/endpoints/v1/novel/recommended.d.ts +0 -72
  80. package/dist/types/endpoints/v1/novel/recommended.d.ts.map +0 -1
  81. package/dist/types/endpoints/v1/novel/recommended.js +0 -32
  82. package/dist/types/endpoints/v1/novel/recommended.js.map +0 -1
  83. package/dist/types/endpoints/v1/novel/related.d.ts +0 -37
  84. package/dist/types/endpoints/v1/novel/related.d.ts.map +0 -1
  85. package/dist/types/endpoints/v1/novel/related.js +0 -24
  86. package/dist/types/endpoints/v1/novel/related.js.map +0 -1
  87. package/dist/types/endpoints/v1/search/illust.d.ts +0 -90
  88. package/dist/types/endpoints/v1/search/illust.d.ts.map +0 -1
  89. package/dist/types/endpoints/v1/search/illust.js +0 -35
  90. package/dist/types/endpoints/v1/search/illust.js.map +0 -1
  91. package/dist/types/endpoints/v1/search/novel.d.ts +0 -90
  92. package/dist/types/endpoints/v1/search/novel.d.ts.map +0 -1
  93. package/dist/types/endpoints/v1/search/novel.js +0 -35
  94. package/dist/types/endpoints/v1/search/novel.js.map +0 -1
  95. package/dist/types/endpoints/v1/user/bookmarks/illust.d.ts +0 -48
  96. package/dist/types/endpoints/v1/user/bookmarks/illust.d.ts.map +0 -1
  97. package/dist/types/endpoints/v1/user/bookmarks/illust.js +0 -31
  98. package/dist/types/endpoints/v1/user/bookmarks/illust.js.map +0 -1
  99. package/dist/types/endpoints/v1/user/bookmarks/novel.d.ts +0 -44
  100. package/dist/types/endpoints/v1/user/bookmarks/novel.d.ts.map +0 -1
  101. package/dist/types/endpoints/v1/user/bookmarks/novel.js +0 -28
  102. package/dist/types/endpoints/v1/user/bookmarks/novel.js.map +0 -1
  103. package/dist/types/endpoints/v1/user/detail.d.ts +0 -44
  104. package/dist/types/endpoints/v1/user/detail.d.ts.map +0 -1
  105. package/dist/types/endpoints/v1/user/detail.js +0 -26
  106. package/dist/types/endpoints/v1/user/detail.js.map +0 -1
  107. package/dist/types/endpoints/v2/illust/bookmark/add.d.ts +0 -28
  108. package/dist/types/endpoints/v2/illust/bookmark/add.d.ts.map +0 -1
  109. package/dist/types/endpoints/v2/illust/bookmark/add.js +0 -3
  110. package/dist/types/endpoints/v2/illust/bookmark/add.js.map +0 -1
  111. package/dist/types/endpoints/v2/illust/related.d.ts +0 -41
  112. package/dist/types/endpoints/v2/illust/related.d.ts.map +0 -1
  113. package/dist/types/endpoints/v2/illust/related.js +0 -29
  114. package/dist/types/endpoints/v2/illust/related.js.map +0 -1
  115. package/dist/types/endpoints/v2/novel/bookmark/add.d.ts +0 -27
  116. package/dist/types/endpoints/v2/novel/bookmark/add.d.ts.map +0 -1
  117. package/dist/types/endpoints/v2/novel/bookmark/add.js +0 -3
  118. package/dist/types/endpoints/v2/novel/bookmark/add.js.map +0 -1
  119. package/dist/types/endpoints/v2/novel/detail.d.ts +0 -25
  120. package/dist/types/endpoints/v2/novel/detail.d.ts.map +0 -1
  121. package/dist/types/endpoints/v2/novel/detail.js +0 -20
  122. package/dist/types/endpoints/v2/novel/detail.js.map +0 -1
  123. package/dist/types/endpoints/v2/novel/series.d.ts +0 -49
  124. package/dist/types/endpoints/v2/novel/series.d.ts.map +0 -1
  125. package/dist/types/endpoints/v2/novel/series.js +0 -31
  126. package/dist/types/endpoints/v2/novel/series.js.map +0 -1
  127. package/dist/types/endpoints/webview/v2/novel.d.ts +0 -21
  128. package/dist/types/endpoints/webview/v2/novel.d.ts.map +0 -1
  129. package/dist/types/endpoints/webview/v2/novel.js +0 -18
  130. package/dist/types/endpoints/webview/v2/novel.js.map +0 -1
  131. package/dist/types/error-response.d.ts +0 -29
  132. package/dist/types/error-response.d.ts.map +0 -1
  133. package/dist/types/error-response.js +0 -3
  134. package/dist/types/error-response.js.map +0 -1
  135. package/dist/types/pixiv-common.d.ts +0 -96
  136. package/dist/types/pixiv-common.d.ts.map +0 -1
  137. package/dist/types/pixiv-common.js +0 -66
  138. package/dist/types/pixiv-common.js.map +0 -1
  139. package/dist/types/pixiv-illust-series.d.ts +0 -56
  140. package/dist/types/pixiv-illust-series.d.ts.map +0 -1
  141. package/dist/types/pixiv-illust-series.js +0 -26
  142. package/dist/types/pixiv-illust-series.js.map +0 -1
  143. package/dist/types/pixiv-illust.d.ts +0 -167
  144. package/dist/types/pixiv-illust.d.ts.map +0 -1
  145. package/dist/types/pixiv-illust.js +0 -53
  146. package/dist/types/pixiv-illust.js.map +0 -1
  147. package/dist/types/pixiv-novel-series.d.ts +0 -84
  148. package/dist/types/pixiv-novel-series.d.ts.map +0 -1
  149. package/dist/types/pixiv-novel-series.js +0 -43
  150. package/dist/types/pixiv-novel-series.js.map +0 -1
  151. package/dist/types/pixiv-novel.d.ts +0 -122
  152. package/dist/types/pixiv-novel.d.ts.map +0 -1
  153. package/dist/types/pixiv-novel.js +0 -42
  154. package/dist/types/pixiv-novel.js.map +0 -1
  155. package/dist/types/pixiv-ugoira.d.ts +0 -50
  156. package/dist/types/pixiv-ugoira.d.ts.map +0 -1
  157. package/dist/types/pixiv-ugoira.js +0 -34
  158. package/dist/types/pixiv-ugoira.js.map +0 -1
  159. package/dist/types/pixiv-user.d.ts +0 -184
  160. package/dist/types/pixiv-user.d.ts.map +0 -1
  161. package/dist/types/pixiv-user.js +0 -97
  162. package/dist/types/pixiv-user.js.map +0 -1
  163. package/dist/utils.d.ts +0 -3
  164. package/dist/utils.d.ts.map +0 -1
  165. package/dist/utils.js +0 -15
  166. package/dist/utils.js.map +0 -1
  167. package/dist/utils.test.d.ts +0 -2
  168. package/dist/utils.test.d.ts.map +0 -1
  169. package/dist/utils.test.js +0 -15
  170. package/dist/utils.test.js.map +0 -1
package/dist/pixiv.js DELETED
@@ -1,698 +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 axios_1 = __importDefault(require("axios"));
8
- const qs_1 = __importDefault(require("qs"));
9
- const options_1 = require("./options");
10
- const saving_responses_1 = require("./saving-responses");
11
- /**
12
- * pixiv API
13
- */
14
- class Pixiv {
15
- /**
16
- * コンストラクタ。外部からインスタンス化できないので、of メソッドを使うこと。
17
- *
18
- * @param userId ユーザー ID
19
- * @param accessToken アクセストークン
20
- * @param refreshToken リフレッシュトークン
21
- * @param pixivTsOptions Pixivts オプション
22
- */
23
- constructor(userId, accessToken, refreshToken, responseDatabase) {
24
- this.hosts = 'https://app-api.pixiv.net';
25
- this.userId = userId;
26
- this.accessToken = accessToken;
27
- this.refreshToken = refreshToken;
28
- this.responseDatabase = responseDatabase ?? null;
29
- this.axios = axios_1.default.create({
30
- baseURL: this.hosts,
31
- headers: {
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
- Authorization: `Bearer ${this.accessToken}`,
37
- },
38
- validateStatus: () => true,
39
- });
40
- }
41
- /**
42
- * リフレッシュトークンからインスタンスを生成する。
43
- *
44
- * @param refreshToken リフレッシュトークン
45
- * @returns Pixiv インスタンス
46
- */
47
- static async of(refreshToken, pixivTsOptions) {
48
- // @see https://github.com/upbit/pixivpy/blob/master/pixivpy3/api.py#L120
49
- // UTCで YYYY-MM-DDTHH:mm:ss+00:00 の形式で現在時刻を取得
50
- const localTime = new Date().toISOString().replace(/Z$/, '+00:00');
51
- const headers = {
52
- 'x-client-time': localTime,
53
- 'x-client-hash': this.hash(localTime),
54
- 'app-os': 'ios',
55
- 'app-os-version': '16.4.1',
56
- 'user-agent': ' PixivIOSApp/7.16.9 (iOS 16.4.1; iPad13,4)',
57
- header: 'application/x-www-form-urlencoded',
58
- };
59
- const authUrl = 'https://oauth.secure.pixiv.net/auth/token';
60
- const data = qs_1.default.stringify({
61
- client_id: this.clientId,
62
- client_secret: this.clientSecret,
63
- get_secure_url: 1,
64
- grant_type: 'refresh_token',
65
- refresh_token: refreshToken,
66
- });
67
- const response = await axios_1.default.post(authUrl, data, {
68
- headers,
69
- validateStatus: () => true,
70
- });
71
- if (response.status !== 200) {
72
- throw new Error('Failed to refresh token');
73
- }
74
- const options = {
75
- userId: response.data.user.id,
76
- accessToken: response.data.response.access_token,
77
- refreshToken: response.data.response.refresh_token,
78
- };
79
- const responseDatabase = pixivTsOptions?.debugOptions?.outputResponse
80
- ?.enable
81
- ? new saving_responses_1.ResponseDatabase(pixivTsOptions.debugOptions.outputResponse.db)
82
- : null;
83
- if (responseDatabase) {
84
- await responseDatabase.init();
85
- await responseDatabase.migrate();
86
- await responseDatabase.sync();
87
- }
88
- return new Pixiv(options.userId, options.accessToken, options.refreshToken, responseDatabase);
89
- }
90
- /**
91
- * 画像のaxiosストリームを取得する。
92
- */
93
- static async getAxiosImageStream(url) {
94
- return axios_1.default.get(url, {
95
- headers: {
96
- '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',
97
- Referer: 'https://www.pixiv.net/',
98
- },
99
- responseType: 'stream',
100
- });
101
- }
102
- // ---------- イラスト ---------- //
103
- /**
104
- * イラストの詳細情報を取得する。
105
- *
106
- * @param options オプション
107
- * @returns レスポンス
108
- */
109
- async illustDetail(options) {
110
- const parameters = {
111
- ...this.convertCamelToSnake(options),
112
- illust_id: options.illustId,
113
- };
114
- return this.request({
115
- method: 'GET',
116
- path: '/v1/illust/detail',
117
- params: parameters,
118
- });
119
- }
120
- /**
121
- * イラストの関連イラストを取得する。
122
- *
123
- * @param options オプション
124
- * @returns レスポンス
125
- */
126
- async illustRelated(options) {
127
- this.checkRequiredOptions(options, ['illustId']);
128
- const parameters = {
129
- ...this.convertCamelToSnake(options),
130
- illust_id: options.illustId,
131
- seed_illust_ids: options.seedIllustIds,
132
- viewed: options.viewed,
133
- offset: options.offset,
134
- };
135
- return this.request({
136
- method: 'GET',
137
- path: '/v2/illust/related',
138
- params: parameters,
139
- });
140
- }
141
- /**
142
- * イラストを検索する。
143
- *
144
- * @param options オプション
145
- * @returns レスポンス
146
- */
147
- async searchIllust(options) {
148
- this.checkRequiredOptions(options, ['word']);
149
- const parameters = {
150
- ...this.convertCamelToSnake(options),
151
- word: options.word, // required
152
- search_target: options.searchTarget ?? options_1.SearchTarget.PARTIAL_MATCH_FOR_TAGS,
153
- sort: options.sort ?? options_1.SearchSort.DATE_DESC,
154
- start_date: options.startDate,
155
- end_date: options.endDate,
156
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
157
- offset: options.offset,
158
- merge_plain_keyword_results: options.mergePlainKeywordResults ?? true,
159
- include_translated_tag_results: options.includeTranslatedTagResults ?? true,
160
- };
161
- return this.request({
162
- method: 'GET',
163
- path: '/v1/search/illust',
164
- params: parameters,
165
- });
166
- }
167
- /**
168
- * イラストランキングを取得する。
169
- *
170
- * @param options オプション
171
- * @returns レスポンス
172
- */
173
- async illustRanking(options = {}) {
174
- const parameters = {
175
- ...this.convertCamelToSnake(options),
176
- mode: options.mode ?? options_1.RankingMode.DAY,
177
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
178
- date: options.date ?? undefined,
179
- offset: options.offset ?? undefined,
180
- };
181
- return this.request({
182
- method: 'GET',
183
- path: '/v1/illust/ranking',
184
- params: parameters,
185
- });
186
- }
187
- /**
188
- * おすすめイラストを取得する。
189
- *
190
- * @param options オプション
191
- * @returns レスポンス
192
- */
193
- async illustRecommended(options = {}) {
194
- const parameters = {
195
- ...this.convertCamelToSnake(options),
196
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
197
- include_ranking_illusts: options.includeRankingIllusts ?? true,
198
- min_bookmark_id_for_recent_illust: options.minBookmarkIdForRecentIllust ?? undefined,
199
- max_bookmark_id_for_recommend: options.maxBookmarkIdForRecommend ?? undefined,
200
- offset: options.offset ?? undefined,
201
- include_privacy_policy: options.includePrivacyPolicy ?? true,
202
- };
203
- return this.request({
204
- method: 'GET',
205
- path: '/v1/illust/recommended',
206
- params: parameters,
207
- });
208
- }
209
- /**
210
- * イラストシリーズの詳細情報を取得する。
211
- *
212
- * @param options オプション
213
- * @returns レスポンス
214
- */
215
- async illustSeries(options) {
216
- this.checkRequiredOptions(options, ['illustSeriesId']);
217
- const parameters = {
218
- ...this.convertCamelToSnake(options),
219
- illust_series_id: options.illustSeriesId,
220
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
221
- // offset: options.offset,
222
- };
223
- return this.request({
224
- method: 'GET',
225
- path: '/v1/illust/series',
226
- params: parameters,
227
- });
228
- }
229
- /**
230
- * イラストをブックマークする。
231
- *
232
- * @param options オプション
233
- * @returns レスポンス
234
- */
235
- async illustBookmarkAdd(options) {
236
- this.checkRequiredOptions(options, ['illustId']);
237
- const data = {
238
- ...this.convertCamelToSnake(options),
239
- illust_id: options.illustId,
240
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
241
- tags: options.tags ?? [],
242
- };
243
- return this.request({
244
- method: 'POST',
245
- path: '/v2/illust/bookmark/add',
246
- data,
247
- });
248
- }
249
- /**
250
- * イラストのブックマークを削除する。
251
- *
252
- * @param options オプション
253
- * @returns レスポンス
254
- */
255
- async illustBookmarkDelete(options) {
256
- this.checkRequiredOptions(options, ['illustId']);
257
- const data = {
258
- ...this.convertCamelToSnake(options),
259
- illust_id: options.illustId,
260
- };
261
- return this.request({
262
- method: 'POST',
263
- path: '/v1/illust/bookmark/delete',
264
- data,
265
- });
266
- }
267
- // ---------- マンガ ---------- //
268
- async mangaRecommended(options = {}) {
269
- const parameters = {
270
- ...this.convertCamelToSnake(options),
271
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
272
- include_ranking_illusts: options.includeRankingIllusts ?? true,
273
- max_bookmark_id: options.maxBookmarkId ?? undefined,
274
- offset: options.offset ?? undefined,
275
- include_privacy_policy: options.includePrivacyPolicy ?? true,
276
- };
277
- return this.request({
278
- method: 'GET',
279
- path: '/v1/manga/recommended',
280
- params: parameters,
281
- });
282
- }
283
- // ---------- うごイラ ---------- //
284
- /**
285
- * うごイラの詳細情報を取得する。
286
- *
287
- * @param options オプション
288
- * @returns レスポンス
289
- */
290
- async ugoiraMetadata(options) {
291
- const parameters = {
292
- ...this.convertCamelToSnake(options),
293
- illust_id: options.illustId,
294
- };
295
- return this.request({
296
- method: 'GET',
297
- path: '/v1/ugoira/metadata',
298
- params: parameters,
299
- });
300
- }
301
- // ---------- 小説 ---------- //
302
- /**
303
- * 小説の詳細情報を取得する。
304
- *
305
- * @param options オプション
306
- * @returns レスポンス
307
- */
308
- async novelDetail(options) {
309
- this.checkRequiredOptions(options, ['novelId']);
310
- const parameters = {
311
- ...this.convertCamelToSnake(options),
312
- novel_id: options.novelId,
313
- };
314
- return this.request({
315
- method: 'GET',
316
- path: '/v2/novel/detail',
317
- params: parameters,
318
- });
319
- }
320
- /**
321
- * 小説の本文を取得する。
322
- *
323
- * @param options オプション
324
- * @returns レスポンス
325
- */
326
- async novelText(options) {
327
- this.checkRequiredOptions(options, ['id']);
328
- const parameters = {
329
- ...this.convertCamelToSnake(options),
330
- id: options.id,
331
- };
332
- return await this.request({
333
- method: 'GET',
334
- path: '/webview/v2/novel',
335
- params: parameters,
336
- });
337
- }
338
- /**
339
- * 小説の関連小説を取得する。
340
- *
341
- * @param options オプション
342
- * @returns レスポンス
343
- */
344
- async novelRelated(options) {
345
- this.checkRequiredOptions(options, ['novelId']);
346
- const parameters = {
347
- ...this.convertCamelToSnake(options),
348
- novel_id: options.novelId,
349
- seed_novel_ids: options.seedNovelIds,
350
- viewed: options.viewed,
351
- };
352
- return this.request({
353
- method: 'GET',
354
- path: '/v1/novel/related',
355
- params: parameters,
356
- });
357
- }
358
- /**
359
- * 小説を検索する。
360
- *
361
- * @param options オプション
362
- * @returns レスポンス
363
- */
364
- async searchNovel(options) {
365
- this.checkRequiredOptions(options, ['word']);
366
- const parameters = {
367
- ...this.convertCamelToSnake(options),
368
- word: options.word, // required
369
- search_target: options.searchTarget ?? options_1.SearchTarget.PARTIAL_MATCH_FOR_TAGS,
370
- sort: options.sort ?? options_1.SearchSort.DATE_DESC,
371
- startDate: options.startDate,
372
- endDate: options.endDate,
373
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
374
- offset: options.offset,
375
- merge_plain_keyword_results: options.mergePlainKeywordResults ?? true,
376
- include_translated_tag_results: options.includeTranslatedTagResults ?? true,
377
- };
378
- return this.request({
379
- method: 'GET',
380
- path: '/v1/search/novel',
381
- params: parameters,
382
- });
383
- }
384
- /**
385
- * 小説ランキングを取得する。
386
- */
387
- async novelRanking(options = {}) {
388
- const parameters = {
389
- ...this.convertCamelToSnake(options),
390
- mode: options.mode ?? options_1.RankingMode.DAY,
391
- date: options.date ?? undefined,
392
- offset: options.offset ?? undefined,
393
- };
394
- return this.request({
395
- method: 'GET',
396
- path: '/v1/novel/ranking',
397
- params: parameters,
398
- });
399
- }
400
- /**
401
- * おすすめ小説を取得する。
402
- *
403
- * @param options オプション
404
- * @returns レスポンス
405
- */
406
- async novelRecommended(options = {}) {
407
- const parameters = {
408
- ...this.convertCamelToSnake(options),
409
- // filter: options.filter ?? 'for_ios',
410
- include_ranking_novels: options.includeRankingNovels ?? true,
411
- already_recommended: options.alreadyRecommended
412
- ? options.alreadyRecommended.join(',')
413
- : undefined,
414
- max_bookmark_id_for_recommend: options.maxBookmarkIdForRecommend ?? undefined,
415
- offset: options.offset ?? undefined,
416
- include_privacy_policy: options.includePrivacyPolicy ?? true,
417
- };
418
- return this.request({
419
- method: 'GET',
420
- path: '/v1/novel/recommended',
421
- params: parameters,
422
- });
423
- }
424
- /**
425
- * 小説シリーズの詳細情報を取得する。
426
- *
427
- * @param options オプション
428
- * @returns レスポンス
429
- */
430
- async novelSeries(options) {
431
- this.checkRequiredOptions(options, ['seriesId']);
432
- const parameters = {
433
- ...this.convertCamelToSnake(options),
434
- series_id: options.seriesId,
435
- // filter: options.filter ?? 'for_ios',
436
- last_order: options.lastOrder ?? undefined,
437
- };
438
- return this.request({
439
- method: 'GET',
440
- path: '/v2/novel/series',
441
- params: parameters,
442
- });
443
- }
444
- /**
445
- * 小説をブックマークする。
446
- *
447
- * @param options オプション
448
- * @returns レスポンス
449
- */
450
- async novelBookmarkAdd(options) {
451
- this.checkRequiredOptions(options, ['novelId']);
452
- const data = {
453
- ...this.convertCamelToSnake(options),
454
- novel_id: options.novelId,
455
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
456
- tags: options.tags ?? [],
457
- };
458
- return this.request({
459
- method: 'POST',
460
- path: '/v2/novel/bookmark/add',
461
- data,
462
- });
463
- }
464
- /**
465
- * 小説のブックマークを削除する。
466
- *
467
- * @param options オプション
468
- * @returns レスポンス
469
- */
470
- async novelBookmarkDelete(options) {
471
- this.checkRequiredOptions(options, ['novelId']);
472
- const data = {
473
- ...this.convertCamelToSnake(options),
474
- novel_id: options.novelId,
475
- };
476
- return this.request({
477
- method: 'POST',
478
- path: '/v1/novel/bookmark/delete',
479
- data,
480
- });
481
- }
482
- // ---------- ユーザ ---------- //
483
- /**
484
- * ユーザの詳細情報を取得する。
485
- *
486
- * @param options オプション
487
- * @returns レスポンス
488
- */
489
- async userDetail(options) {
490
- this.checkRequiredOptions(options, ['userId']);
491
- const parameters = {
492
- ...this.convertCamelToSnake(options),
493
- user_id: options.userId,
494
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
495
- };
496
- return this.request({
497
- method: 'GET',
498
- path: '/v1/user/detail',
499
- params: parameters,
500
- });
501
- }
502
- /**
503
- * ユーザのイラストブックマークを取得する。
504
- *
505
- * @param options オプション
506
- * @returns レスポンス
507
- */
508
- async userBookmarksIllust(options) {
509
- this.checkRequiredOptions(options, ['userId']);
510
- const parameters = {
511
- ...this.convertCamelToSnake(options),
512
- user_id: options.userId,
513
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
514
- filter: options.filter ?? options_1.OSFilter.FOR_IOS,
515
- max_bookmark_id: options.maxBookmarkId ?? undefined,
516
- tag: options.tag ?? undefined,
517
- };
518
- return this.request({
519
- method: 'GET',
520
- path: '/v1/user/bookmarks/illust',
521
- params: parameters,
522
- });
523
- }
524
- /**
525
- * ユーザの小説ブックマークを取得する。
526
- *
527
- * @param options オプション
528
- * @returns レスポンス
529
- */
530
- async userBookmarksNovel(options) {
531
- this.checkRequiredOptions(options, ['userId']);
532
- const parameters = {
533
- ...this.convertCamelToSnake(options),
534
- user_id: options.userId,
535
- restrict: options.restrict ?? options_1.BookmarkRestrict.PUBLIC,
536
- max_bookmark_id: options.maxBookmarkId ?? undefined,
537
- tag: options.tag ?? undefined,
538
- };
539
- return this.request({
540
- method: 'GET',
541
- path: '/v1/user/bookmarks/novel',
542
- params: parameters,
543
- });
544
- }
545
- // ---------- その他 ---------- //
546
- /**
547
- * 接続を閉じる。
548
- */
549
- async close() {
550
- if (this.responseDatabase) {
551
- await this.responseDatabase.close();
552
- }
553
- }
554
- // ---------- ユーティリティ ---------- //
555
- /**
556
- * クエリストリングをパースする。
557
- *
558
- * @param url URL
559
- * @returns パースしたクエリストリングオブジェクト
560
- */
561
- static parseQueryString(url) {
562
- let query = url;
563
- if (url.includes('?')) {
564
- query = url.split('?')[1];
565
- }
566
- return qs_1.default.parse(query);
567
- }
568
- /**
569
- * レスポンスがエラーかどうかを判定する。
570
- *
571
- * @param response Axios レスポンス
572
- * @returns エラーかどうか
573
- */
574
- static isError(response) {
575
- return (
576
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
577
- response.error !== undefined &&
578
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
579
- response.error.user_message !== undefined &&
580
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
581
- response.error.message !== undefined &&
582
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
583
- response.error.reason !== undefined);
584
- }
585
- /**
586
- * MD5ハッシュを生成する。
587
- *
588
- * @param str 文字列
589
- * @returns ハッシュ
590
- */
591
- static hash(string) {
592
- const hash = node_crypto_1.default.createHash('md5');
593
- return hash.update(string + this.hashSecret).digest('hex');
594
- }
595
- /**
596
- * リクエストを送信する。
597
- *
598
- * ジェネリクスの順番は、T: リクエスト、U: レスポンス。
599
- *
600
- * @param options オプション
601
- * @returns レスポンス
602
- */
603
- async request(options) {
604
- if (options.method === 'GET') {
605
- return await this.saveResponse(options, await this.axios.get(options.path, {
606
- params: options.params,
607
- paramsSerializer: { indexes: true },
608
- }));
609
- }
610
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
611
- if (options.method === 'POST') {
612
- return await this.saveResponse(options, await this.axios.post(options.path, qs_1.default.stringify(options.data), {
613
- headers: {
614
- 'Content-Type': 'application/x-www-form-urlencoded',
615
- },
616
- paramsSerializer: { indexes: true },
617
- }));
618
- }
619
- throw new Error('Invalid method');
620
- }
621
- async saveResponse(request, response) {
622
- if (this.responseDatabase === null) {
623
- return response;
624
- }
625
- const method = request.method;
626
- const path = request.path;
627
- const rawUrl = [
628
- this.hosts,
629
- path,
630
- method === 'GET'
631
- ? qs_1.default.stringify(request.params, { addQueryPrefix: true })
632
- : '',
633
- ].join('');
634
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
635
- const url = response.request.res.responseUrl ?? rawUrl;
636
- const responseType = this.isJSON(response.data) ? 'JSON' : 'TEXT';
637
- const responseBody = responseType === 'JSON'
638
- ? JSON.stringify(response.data)
639
- : response.data;
640
- await this.responseDatabase.addResponse({
641
- method,
642
- endpoint: path,
643
- url,
644
- requestHeaders: JSON.stringify(response.config.headers),
645
- requestBody: response.config.data,
646
- responseType,
647
- statusCode: response.status,
648
- responseHeaders: JSON.stringify(response.headers),
649
- responseBody,
650
- });
651
- return response;
652
- }
653
- isJSON(value) {
654
- if (typeof value === 'object') {
655
- return true;
656
- }
657
- try {
658
- JSON.parse(value);
659
- return true;
660
- }
661
- catch {
662
- return false;
663
- }
664
- }
665
- /**
666
- * 必須のオプションが含まれているかどうかをチェックする。
667
- *
668
- * @param options オプション
669
- * @param required 必須のオプションキー
670
- * @throws 必須のオプションが含まれていない場合
671
- */
672
- checkRequiredOptions(options, required) {
673
- for (const key of required) {
674
- if (options[key] === undefined) {
675
- throw new Error(`Missing required option: ${key}`);
676
- }
677
- }
678
- }
679
- /**
680
- * キャメルケースのオブジェクトキーをスネークケースなオブジェクトキーに変換する。
681
- *
682
- * @param object オブジェクト
683
- * @returns 変換後のオブジェクト
684
- */
685
- convertCamelToSnake(object) {
686
- const result = {};
687
- for (const key of Object.keys(object)) {
688
- const snakeKey = key.replaceAll(/([A-Z])/g, (m) => `_${m[0].toLowerCase()}`);
689
- result[snakeKey] = object[key];
690
- }
691
- return result;
692
- }
693
- }
694
- Pixiv.clientId = 'MOBrBDS8blbauoSck0ZfDbtuzpyT';
695
- Pixiv.clientSecret = 'lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj';
696
- Pixiv.hashSecret = '28c1fdd170a5204386cb1313c7077b34f83e4aaf4aa829ce78c231e05b0bae2c';
697
- exports.default = Pixiv;
698
- //# sourceMappingURL=pixiv.js.map