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