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