@book000/pixivts 0.58.1 → 0.59.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 +42 -7
- package/dist/index.d.cts +142 -119
- package/dist/index.d.ts +142 -119
- package/dist/index.js +42 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -219,12 +219,12 @@ var PaginatedResultAsync = class _PaginatedResultAsync extends ResultAsync {
|
|
|
219
219
|
const first = await Promise.resolve(this);
|
|
220
220
|
if (first.isErr) throw new PixivFetchError(first.error);
|
|
221
221
|
yield first.value;
|
|
222
|
-
let nextUrl = first.value.
|
|
222
|
+
let nextUrl = first.value.nextUrl;
|
|
223
223
|
while (nextUrl !== null) {
|
|
224
224
|
const pageResult = await this.#http.getAbsolute(nextUrl);
|
|
225
225
|
if (pageResult.isErr) throw new PixivFetchError(pageResult.error);
|
|
226
226
|
yield pageResult.value;
|
|
227
|
-
nextUrl = pageResult.value.
|
|
227
|
+
nextUrl = pageResult.value.nextUrl;
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
/**
|
|
@@ -281,6 +281,18 @@ function buildSearchParams(params) {
|
|
|
281
281
|
function buildParams(params) {
|
|
282
282
|
return buildSearchParams(toSnakeKeys(params));
|
|
283
283
|
}
|
|
284
|
+
function snakeToCamel(key) {
|
|
285
|
+
return key.replaceAll(/_([a-z0-9])/g, (_m, c) => c.toUpperCase());
|
|
286
|
+
}
|
|
287
|
+
function camelizeKeys(value) {
|
|
288
|
+
if (value === null || typeof value !== "object") return value;
|
|
289
|
+
if (Array.isArray(value)) return value.map((v) => camelizeKeys(v));
|
|
290
|
+
const out = {};
|
|
291
|
+
for (const [k, v] of Object.entries(value)) {
|
|
292
|
+
out[snakeToCamel(k)] = camelizeKeys(v);
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
284
296
|
function parseNextUrl(url) {
|
|
285
297
|
const usp = new URL(url).searchParams;
|
|
286
298
|
const result = {};
|
|
@@ -753,7 +765,7 @@ var HttpClient = class {
|
|
|
753
765
|
const isJson = contentType.includes("application/json");
|
|
754
766
|
if (isJson) {
|
|
755
767
|
try {
|
|
756
|
-
data = JSON.parse(text);
|
|
768
|
+
data = camelizeKeys(JSON.parse(text));
|
|
757
769
|
} catch {
|
|
758
770
|
data = text;
|
|
759
771
|
}
|
|
@@ -778,7 +790,7 @@ var HttpClient = class {
|
|
|
778
790
|
responseType: isJson ? "JSON" : "TEXT",
|
|
779
791
|
statusCode: response.status,
|
|
780
792
|
responseHeaders: JSON.stringify(responseHeaders),
|
|
781
|
-
responseBody:
|
|
793
|
+
responseBody: text
|
|
782
794
|
};
|
|
783
795
|
Promise.resolve(this.#interceptor(record)).catch(() => void 0);
|
|
784
796
|
}
|
|
@@ -1185,8 +1197,8 @@ var UserBookmarksResource = class {
|
|
|
1185
1197
|
* // Resume from a saved cursor
|
|
1186
1198
|
* import { parseNextUrl } from '@book000/pixivts'
|
|
1187
1199
|
* const page = await client.users.bookmarks.illusts({ userId: client.userId })
|
|
1188
|
-
* if (page.isOk && page.value.
|
|
1189
|
-
* const cursor = parseNextUrl(page.value.
|
|
1200
|
+
* if (page.isOk && page.value.nextUrl) {
|
|
1201
|
+
* const cursor = parseNextUrl(page.value.nextUrl)
|
|
1190
1202
|
* const next = await client.users.bookmarks.illusts({
|
|
1191
1203
|
* userId: client.userId,
|
|
1192
1204
|
* maxBookmarkId: cursor.maxBookmarkId,
|
|
@@ -1321,7 +1333,7 @@ var UserResource = class {
|
|
|
1321
1333
|
})
|
|
1322
1334
|
),
|
|
1323
1335
|
this.#http,
|
|
1324
|
-
(page) => page.
|
|
1336
|
+
(page) => page.userPreviews
|
|
1325
1337
|
);
|
|
1326
1338
|
}
|
|
1327
1339
|
/**
|
|
@@ -1468,6 +1480,29 @@ var PixivClient = class _PixivClient {
|
|
|
1468
1480
|
}
|
|
1469
1481
|
return id;
|
|
1470
1482
|
}
|
|
1483
|
+
/**
|
|
1484
|
+
* Returns the current OAuth access token.
|
|
1485
|
+
*
|
|
1486
|
+
* The access token is short-lived and changes after each call to
|
|
1487
|
+
* {@link PixivClient.of} and after each automatic token refresh triggered
|
|
1488
|
+
* by a 401 response.
|
|
1489
|
+
*
|
|
1490
|
+
* @returns The current bearer access token string
|
|
1491
|
+
*/
|
|
1492
|
+
getAccessToken() {
|
|
1493
|
+
return this.#auth.accessToken;
|
|
1494
|
+
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Returns the current OAuth refresh token.
|
|
1497
|
+
*
|
|
1498
|
+
* The refresh token is long-lived and is used to obtain new access tokens.
|
|
1499
|
+
* It may rotate after a successful token refresh.
|
|
1500
|
+
*
|
|
1501
|
+
* @returns The current refresh token string
|
|
1502
|
+
*/
|
|
1503
|
+
getRefreshToken() {
|
|
1504
|
+
return this.#auth.refreshToken;
|
|
1505
|
+
}
|
|
1471
1506
|
/**
|
|
1472
1507
|
* Creates a PixivClient by refreshing the given token.
|
|
1473
1508
|
*
|