@book000/pixivts 0.57.1 → 0.58.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.
- package/dist/index.cjs +214 -31
- package/dist/index.d.cts +252 -46
- package/dist/index.d.ts +252 -46
- package/dist/index.js +205 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -255,6 +255,115 @@ function failedPaginated(error, http, getItems) {
|
|
|
255
255
|
);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
// src/params.ts
|
|
259
|
+
function camelToSnake(key) {
|
|
260
|
+
return key.replaceAll(/([A-Z])/g, (m) => `_${m.toLowerCase()}`);
|
|
261
|
+
}
|
|
262
|
+
function toSnakeKeys(obj) {
|
|
263
|
+
const out = {};
|
|
264
|
+
for (const key of Object.keys(obj)) {
|
|
265
|
+
out[camelToSnake(key)] = obj[key];
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
function buildSearchParams(params) {
|
|
270
|
+
const usp = new URLSearchParams();
|
|
271
|
+
for (const [key, value] of Object.entries(params)) {
|
|
272
|
+
if (value === null || value === void 0) continue;
|
|
273
|
+
if (Array.isArray(value)) {
|
|
274
|
+
for (const item of value) usp.append(`${key}[]`, String(item));
|
|
275
|
+
} else {
|
|
276
|
+
usp.set(key, String(value));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return usp;
|
|
280
|
+
}
|
|
281
|
+
function buildParams(params) {
|
|
282
|
+
return buildSearchParams(toSnakeKeys(params));
|
|
283
|
+
}
|
|
284
|
+
function parseNextUrl(url) {
|
|
285
|
+
const usp = new URL(url).searchParams;
|
|
286
|
+
const result = {};
|
|
287
|
+
const toNum = (key) => {
|
|
288
|
+
const v = usp.get(key);
|
|
289
|
+
if (v === null || v === "") return void 0;
|
|
290
|
+
const n = Number(v);
|
|
291
|
+
return Number.isNaN(n) ? void 0 : n;
|
|
292
|
+
};
|
|
293
|
+
const maxBookmarkId = toNum("max_bookmark_id");
|
|
294
|
+
if (maxBookmarkId !== void 0) result.maxBookmarkId = maxBookmarkId;
|
|
295
|
+
const maxBookmarkIdForRecommend = toNum("max_bookmark_id_for_recommend");
|
|
296
|
+
if (maxBookmarkIdForRecommend !== void 0)
|
|
297
|
+
result.maxBookmarkIdForRecommend = maxBookmarkIdForRecommend;
|
|
298
|
+
const minBookmarkIdForRecentIllust = toNum("min_bookmark_id_for_recent_illust");
|
|
299
|
+
if (minBookmarkIdForRecentIllust !== void 0)
|
|
300
|
+
result.minBookmarkIdForRecentIllust = minBookmarkIdForRecentIllust;
|
|
301
|
+
const offset = toNum("offset");
|
|
302
|
+
if (offset !== void 0) result.offset = offset;
|
|
303
|
+
const lastOrder = toNum("last_order");
|
|
304
|
+
if (lastOrder !== void 0) result.lastOrder = lastOrder;
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/options.ts
|
|
309
|
+
var SearchTarget = {
|
|
310
|
+
PARTIAL_MATCH_FOR_TAGS: "partial_match_for_tags",
|
|
311
|
+
EXACT_MATCH_FOR_TAGS: "exact_match_for_tags",
|
|
312
|
+
TITLE_AND_CAPTION: "title_and_caption",
|
|
313
|
+
KEYWORD: "keyword"
|
|
314
|
+
};
|
|
315
|
+
var SearchSort = {
|
|
316
|
+
DATE_DESC: "date_desc",
|
|
317
|
+
DATE_ASC: "date_asc",
|
|
318
|
+
POPULAR_DESC: "popular_desc"
|
|
319
|
+
};
|
|
320
|
+
var SearchDuration = {
|
|
321
|
+
WITHIN_LAST_DAY: "within_last_day",
|
|
322
|
+
WITHIN_LAST_WEEK: "within_last_week",
|
|
323
|
+
WITHIN_LAST_MONTH: "within_last_month"
|
|
324
|
+
};
|
|
325
|
+
var RankingMode = {
|
|
326
|
+
DAY: "day",
|
|
327
|
+
DAY_MALE: "day_male",
|
|
328
|
+
DAY_FEMALE: "day_female",
|
|
329
|
+
WEEK_ORIGINAL: "week_original",
|
|
330
|
+
WEEK_ROOKIE: "week_rookie",
|
|
331
|
+
WEEK: "week",
|
|
332
|
+
MONTH: "month",
|
|
333
|
+
DAY_AI: "day_ai",
|
|
334
|
+
DAY_R18: "day_r18",
|
|
335
|
+
WEEK_R18: "week_r18",
|
|
336
|
+
DAY_MALE_R18: "day_male_r18",
|
|
337
|
+
DAY_FEMALE_R18: "day_female_r18",
|
|
338
|
+
DAY_R18_AI: "day_r18_ai"
|
|
339
|
+
};
|
|
340
|
+
var NovelRankingMode = {
|
|
341
|
+
DAY: "day",
|
|
342
|
+
WEEK: "week",
|
|
343
|
+
DAY_MALE: "day_male",
|
|
344
|
+
DAY_FEMALE: "day_female",
|
|
345
|
+
WEEK_ROOKIE: "week_rookie",
|
|
346
|
+
DAY_R18: "day_r18",
|
|
347
|
+
WEEK_R18: "week_r18",
|
|
348
|
+
DAY_R18_AI: "day_r18_ai"
|
|
349
|
+
};
|
|
350
|
+
var BookmarkRestrict = {
|
|
351
|
+
PUBLIC: "public",
|
|
352
|
+
PRIVATE: "private"
|
|
353
|
+
};
|
|
354
|
+
var FollowRestrict = {
|
|
355
|
+
PUBLIC: "public",
|
|
356
|
+
PRIVATE: "private"
|
|
357
|
+
};
|
|
358
|
+
var OSFilter = {
|
|
359
|
+
FOR_IOS: "for_ios",
|
|
360
|
+
FOR_ANDROID: "for_android"
|
|
361
|
+
};
|
|
362
|
+
var UserIllustType = {
|
|
363
|
+
ILLUST: "illust",
|
|
364
|
+
MANGA: "manga"
|
|
365
|
+
};
|
|
366
|
+
|
|
258
367
|
// src/auth.ts
|
|
259
368
|
var T = Array.from(
|
|
260
369
|
{ length: 64 },
|
|
@@ -679,33 +788,6 @@ var HttpClient = class {
|
|
|
679
788
|
}
|
|
680
789
|
};
|
|
681
790
|
|
|
682
|
-
// src/params.ts
|
|
683
|
-
function camelToSnake(key) {
|
|
684
|
-
return key.replaceAll(/([A-Z])/g, (m) => `_${m.toLowerCase()}`);
|
|
685
|
-
}
|
|
686
|
-
function toSnakeKeys(obj) {
|
|
687
|
-
const out = {};
|
|
688
|
-
for (const key of Object.keys(obj)) {
|
|
689
|
-
out[camelToSnake(key)] = obj[key];
|
|
690
|
-
}
|
|
691
|
-
return out;
|
|
692
|
-
}
|
|
693
|
-
function buildSearchParams(params) {
|
|
694
|
-
const usp = new URLSearchParams();
|
|
695
|
-
for (const [key, value] of Object.entries(params)) {
|
|
696
|
-
if (value === null || value === void 0) continue;
|
|
697
|
-
if (Array.isArray(value)) {
|
|
698
|
-
for (const item of value) usp.append(`${key}[]`, String(item));
|
|
699
|
-
} else {
|
|
700
|
-
usp.set(key, String(value));
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return usp;
|
|
704
|
-
}
|
|
705
|
-
function buildParams(params) {
|
|
706
|
-
return buildSearchParams(toSnakeKeys(params));
|
|
707
|
-
}
|
|
708
|
-
|
|
709
791
|
// src/resources/illusts.ts
|
|
710
792
|
var IllustResource = class {
|
|
711
793
|
#http;
|
|
@@ -717,6 +799,16 @@ var IllustResource = class {
|
|
|
717
799
|
* GET /v1/illust/detail
|
|
718
800
|
*
|
|
719
801
|
* @param params - Request parameters
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```ts
|
|
805
|
+
* const result = await client.illusts.detail({ illustId: 12345 })
|
|
806
|
+
* if (result.isOk) {
|
|
807
|
+
* console.log(result.value.illust.title)
|
|
808
|
+
* } else {
|
|
809
|
+
* console.error(result.error)
|
|
810
|
+
* }
|
|
811
|
+
* ```
|
|
720
812
|
*/
|
|
721
813
|
detail(params) {
|
|
722
814
|
return this.#http.get(
|
|
@@ -749,6 +841,20 @@ var IllustResource = class {
|
|
|
749
841
|
* GET /v1/search/illust
|
|
750
842
|
*
|
|
751
843
|
* @param params - Request parameters
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* ```ts
|
|
847
|
+
* // Iterate all results across pages
|
|
848
|
+
* for await (const illust of client.illusts.search({ word: 'cat' }).items()) {
|
|
849
|
+
* console.log(illust.title)
|
|
850
|
+
* }
|
|
851
|
+
*
|
|
852
|
+
* // Fetch only the first page
|
|
853
|
+
* const page = await client.illusts.search({ word: 'cat' })
|
|
854
|
+
* if (page.isOk) {
|
|
855
|
+
* console.log(page.value.illusts.length)
|
|
856
|
+
* }
|
|
857
|
+
* ```
|
|
752
858
|
*/
|
|
753
859
|
search(params) {
|
|
754
860
|
return PaginatedResultAsync.fromResultAsync(
|
|
@@ -806,7 +912,9 @@ var IllustResource = class {
|
|
|
806
912
|
includeRankingLabel: true,
|
|
807
913
|
includeRankingIllusts: true,
|
|
808
914
|
includePrivacyPolicy: true,
|
|
809
|
-
offset: params.offset
|
|
915
|
+
offset: params.offset,
|
|
916
|
+
maxBookmarkIdForRecommend: params.maxBookmarkIdForRecommend,
|
|
917
|
+
minBookmarkIdForRecentIllust: params.minBookmarkIdForRecentIllust
|
|
810
918
|
})
|
|
811
919
|
),
|
|
812
920
|
this.#http,
|
|
@@ -875,6 +983,16 @@ var NovelResource = class {
|
|
|
875
983
|
* GET /v2/novel/detail
|
|
876
984
|
*
|
|
877
985
|
* @param params - Request parameters
|
|
986
|
+
*
|
|
987
|
+
* @example
|
|
988
|
+
* ```ts
|
|
989
|
+
* const result = await client.novels.detail({ novelId: 67890 })
|
|
990
|
+
* if (result.isOk) {
|
|
991
|
+
* console.log(result.value.novel.title)
|
|
992
|
+
* } else {
|
|
993
|
+
* console.error(result.error)
|
|
994
|
+
* }
|
|
995
|
+
* ```
|
|
878
996
|
*/
|
|
879
997
|
detail(params) {
|
|
880
998
|
return this.#http.get(
|
|
@@ -919,6 +1037,20 @@ var NovelResource = class {
|
|
|
919
1037
|
* GET /v1/search/novel
|
|
920
1038
|
*
|
|
921
1039
|
* @param params - Request parameters
|
|
1040
|
+
*
|
|
1041
|
+
* @example
|
|
1042
|
+
* ```ts
|
|
1043
|
+
* // Iterate all results across pages
|
|
1044
|
+
* for await (const novel of client.novels.search({ word: 'fantasy' }).items()) {
|
|
1045
|
+
* console.log(novel.title)
|
|
1046
|
+
* }
|
|
1047
|
+
*
|
|
1048
|
+
* // Fetch only the first page
|
|
1049
|
+
* const page = await client.novels.search({ word: 'fantasy' })
|
|
1050
|
+
* if (page.isOk) {
|
|
1051
|
+
* console.log(page.value.novels.length)
|
|
1052
|
+
* }
|
|
1053
|
+
* ```
|
|
922
1054
|
*/
|
|
923
1055
|
search(params) {
|
|
924
1056
|
return PaginatedResultAsync.fromResultAsync(
|
|
@@ -975,7 +1107,8 @@ var NovelResource = class {
|
|
|
975
1107
|
filter: params.filter ?? "for_ios",
|
|
976
1108
|
includeRankingNovels: true,
|
|
977
1109
|
includePrivacyPolicy: true,
|
|
978
|
-
offset: params.offset
|
|
1110
|
+
offset: params.offset,
|
|
1111
|
+
maxBookmarkIdForRecommend: params.maxBookmarkIdForRecommend
|
|
979
1112
|
})
|
|
980
1113
|
),
|
|
981
1114
|
this.#http,
|
|
@@ -1041,6 +1174,25 @@ var UserBookmarksResource = class {
|
|
|
1041
1174
|
* GET /v1/user/bookmarks/illust
|
|
1042
1175
|
*
|
|
1043
1176
|
* @param params - Request parameters
|
|
1177
|
+
*
|
|
1178
|
+
* @example
|
|
1179
|
+
* ```ts
|
|
1180
|
+
* // Iterate all bookmarked illusts across pages
|
|
1181
|
+
* for await (const illust of client.users.bookmarks.illusts({ userId: client.userId }).items()) {
|
|
1182
|
+
* console.log(illust.title)
|
|
1183
|
+
* }
|
|
1184
|
+
*
|
|
1185
|
+
* // Resume from a saved cursor
|
|
1186
|
+
* import { parseNextUrl } from '@book000/pixivts'
|
|
1187
|
+
* const page = await client.users.bookmarks.illusts({ userId: client.userId })
|
|
1188
|
+
* if (page.isOk && page.value.next_url) {
|
|
1189
|
+
* const cursor = parseNextUrl(page.value.next_url)
|
|
1190
|
+
* const next = await client.users.bookmarks.illusts({
|
|
1191
|
+
* userId: client.userId,
|
|
1192
|
+
* maxBookmarkId: cursor.maxBookmarkId,
|
|
1193
|
+
* })
|
|
1194
|
+
* }
|
|
1195
|
+
* ```
|
|
1044
1196
|
*/
|
|
1045
1197
|
illusts(params) {
|
|
1046
1198
|
return PaginatedResultAsync.fromResultAsync(
|
|
@@ -1064,6 +1216,14 @@ var UserBookmarksResource = class {
|
|
|
1064
1216
|
* GET /v1/user/bookmarks/novel
|
|
1065
1217
|
*
|
|
1066
1218
|
* @param params - Request parameters
|
|
1219
|
+
*
|
|
1220
|
+
* @example
|
|
1221
|
+
* ```ts
|
|
1222
|
+
* // Iterate all bookmarked novels across pages
|
|
1223
|
+
* for await (const novel of client.users.bookmarks.novels({ userId: client.userId }).items()) {
|
|
1224
|
+
* console.log(novel.title)
|
|
1225
|
+
* }
|
|
1226
|
+
* ```
|
|
1067
1227
|
*/
|
|
1068
1228
|
novels(params) {
|
|
1069
1229
|
return PaginatedResultAsync.fromResultAsync(
|
|
@@ -1288,12 +1448,25 @@ var PixivClient = class _PixivClient {
|
|
|
1288
1448
|
this.images = new ImageResource(http);
|
|
1289
1449
|
}
|
|
1290
1450
|
/**
|
|
1291
|
-
* Numeric user ID of the authenticated account
|
|
1451
|
+
* Numeric user ID of the authenticated account.
|
|
1292
1452
|
*
|
|
1293
1453
|
* Available immediately after {@link PixivClient.of} resolves.
|
|
1454
|
+
* The pixiv OAuth endpoint returns the ID as a string; this getter
|
|
1455
|
+
* normalises it to `number` for consistency with resource method params
|
|
1456
|
+
* (e.g. `UserBookmarksIllustParams.userId`).
|
|
1457
|
+
*
|
|
1458
|
+
* @example
|
|
1459
|
+
* ```ts
|
|
1460
|
+
* const client = await PixivClient.of(refreshToken)
|
|
1461
|
+
* const bookmarks = await client.users.bookmarks.illusts({ userId: client.userId })
|
|
1462
|
+
* ```
|
|
1294
1463
|
*/
|
|
1295
1464
|
get userId() {
|
|
1296
|
-
|
|
1465
|
+
const id = Number(this.#auth.userId);
|
|
1466
|
+
if (Number.isNaN(id)) {
|
|
1467
|
+
throw new TypeError(`Invalid userId: "${this.#auth.userId}"`);
|
|
1468
|
+
}
|
|
1469
|
+
return id;
|
|
1297
1470
|
}
|
|
1298
1471
|
/**
|
|
1299
1472
|
* Creates a PixivClient by refreshing the given token.
|
|
@@ -1309,4 +1482,4 @@ var PixivClient = class _PixivClient {
|
|
|
1309
1482
|
}
|
|
1310
1483
|
};
|
|
1311
1484
|
|
|
1312
|
-
export { PaginatedResultAsync, PixivClient, PixivFetchError, ResultAsync, apiError, authFailedError, err, failedPaginated, networkError, ok, rateLimitError };
|
|
1485
|
+
export { BookmarkRestrict, FollowRestrict, NovelRankingMode, OSFilter, PaginatedResultAsync, PixivClient, PixivFetchError, RankingMode, ResultAsync, SearchDuration, SearchSort, SearchTarget, UserIllustType, apiError, authFailedError, err, failedPaginated, networkError, ok, parseNextUrl, rateLimitError };
|