@vtecx/vtecxnext 2.2.2 → 2.2.4
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/vtecxnext.d.ts +19 -2
- package/dist/vtecxnext.js +64 -4
- package/package.json +1 -1
package/dist/vtecxnext.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ export type CreateGroupadminInfo = {
|
|
|
24
24
|
group: string;
|
|
25
25
|
uids: string[];
|
|
26
26
|
};
|
|
27
|
+
export type PaginationInfo = {
|
|
28
|
+
lastPageNumber: number;
|
|
29
|
+
countWithinRange: number;
|
|
30
|
+
hasNext: boolean;
|
|
31
|
+
};
|
|
27
32
|
export declare class VtecxNext {
|
|
28
33
|
/** Request */
|
|
29
34
|
readonly req: NextRequest | undefined;
|
|
@@ -35,6 +40,8 @@ export declare class VtecxNext {
|
|
|
35
40
|
private bufferData;
|
|
36
41
|
/** Access Token (for batch) */
|
|
37
42
|
private accessToken;
|
|
43
|
+
/** login cookies */
|
|
44
|
+
private loginCookies;
|
|
38
45
|
/**
|
|
39
46
|
* constructor
|
|
40
47
|
* @param req Request
|
|
@@ -381,9 +388,9 @@ export declare class VtecxNext {
|
|
|
381
388
|
* @param uri key and conditions
|
|
382
389
|
* @param pagerange page range
|
|
383
390
|
* @param targetService target service name (for service linkage)
|
|
384
|
-
* @return
|
|
391
|
+
* @return Maximum number of pages in the specified page range, and total count.
|
|
385
392
|
*/
|
|
386
|
-
pagination: (uri: string, pagerange: string, targetService?: string) => Promise<
|
|
393
|
+
pagination: (uri: string, pagerange: string, targetService?: string) => Promise<PaginationInfo>;
|
|
387
394
|
/**
|
|
388
395
|
* get page
|
|
389
396
|
* @param uri key and conditions
|
|
@@ -904,6 +911,16 @@ export declare class VtecxNext {
|
|
|
904
911
|
* @param response vte.cxからのレスポンス
|
|
905
912
|
*/
|
|
906
913
|
private setCookie;
|
|
914
|
+
/**
|
|
915
|
+
* ログイン時にレスポンスされたvte.cxからのset-cookieを保持する。
|
|
916
|
+
* @param response vte.cxからのレスポンス
|
|
917
|
+
*/
|
|
918
|
+
private setLoginCookie;
|
|
919
|
+
/**
|
|
920
|
+
* ログイン後のCookie編集
|
|
921
|
+
* @returns cookie
|
|
922
|
+
*/
|
|
923
|
+
private editRequestCookie;
|
|
907
924
|
/**
|
|
908
925
|
* vte.cxからのレスポンスヘッダを、ブラウザへレスポンスする。
|
|
909
926
|
* コンテンツの戻し時に使用。
|
package/dist/vtecxnext.js
CHANGED
|
@@ -56,6 +56,8 @@ class VtecxNext {
|
|
|
56
56
|
bufferData = null;
|
|
57
57
|
/** Access Token (for batch) */
|
|
58
58
|
accessToken;
|
|
59
|
+
/** login cookies */
|
|
60
|
+
loginCookies = {};
|
|
59
61
|
/**
|
|
60
62
|
* constructor
|
|
61
63
|
* @param req Request
|
|
@@ -383,6 +385,8 @@ class VtecxNext {
|
|
|
383
385
|
}
|
|
384
386
|
// vte.cxからのset-cookieを転記
|
|
385
387
|
this.setCookie(response);
|
|
388
|
+
// 引き続きAPIで処理を行う場合のため、set-cookie情報を保持しておく
|
|
389
|
+
this.setLoginCookie(response);
|
|
386
390
|
const data = await response.json();
|
|
387
391
|
return { status: response.status, message: data.feed.title };
|
|
388
392
|
};
|
|
@@ -1352,7 +1356,7 @@ class VtecxNext {
|
|
|
1352
1356
|
* @param uri key and conditions
|
|
1353
1357
|
* @param pagerange page range
|
|
1354
1358
|
* @param targetService target service name (for service linkage)
|
|
1355
|
-
* @return
|
|
1359
|
+
* @return Maximum number of pages in the specified page range, and total count.
|
|
1356
1360
|
*/
|
|
1357
1361
|
pagination = async (uri, pagerange, targetService) => {
|
|
1358
1362
|
//console.log('[vtecxnext pagination] start.')
|
|
@@ -1373,8 +1377,18 @@ class VtecxNext {
|
|
|
1373
1377
|
this.setCookie(response);
|
|
1374
1378
|
// レスポンスのエラーチェック
|
|
1375
1379
|
await checkVtecxResponse(response);
|
|
1376
|
-
//
|
|
1377
|
-
|
|
1380
|
+
// 戻り値編集
|
|
1381
|
+
const respJson = await getJson(response);
|
|
1382
|
+
let hasNext = false;
|
|
1383
|
+
if (respJson.feed.link && respJson.feed.link[0]?.___rel === 'next') {
|
|
1384
|
+
hasNext = true;
|
|
1385
|
+
}
|
|
1386
|
+
const pagenationInfo = {
|
|
1387
|
+
'lastPageNumber': Number(respJson.feed.title),
|
|
1388
|
+
'countWithinRange': Number(respJson.feed.subtitle),
|
|
1389
|
+
'hasNext': hasNext
|
|
1390
|
+
};
|
|
1391
|
+
return pagenationInfo;
|
|
1378
1392
|
};
|
|
1379
1393
|
/**
|
|
1380
1394
|
* get page
|
|
@@ -3589,7 +3603,8 @@ class VtecxNext {
|
|
|
3589
3603
|
*/
|
|
3590
3604
|
requestVtecx = async (method, url, body, additionalHeaders, targetService, mode) => {
|
|
3591
3605
|
// cookieの値をvte.cxへのリクエストヘッダに設定
|
|
3592
|
-
const cookie = this.
|
|
3606
|
+
const cookie = this.editRequestCookie();
|
|
3607
|
+
//console.log(`[requestVtecx] cookie = ${cookie}`)
|
|
3593
3608
|
const headers = cookie ? { 'Cookie': cookie } : {};
|
|
3594
3609
|
if (this.accessToken) {
|
|
3595
3610
|
headers.Authorization = `Token ${this.accessToken}`;
|
|
@@ -3634,6 +3649,50 @@ class VtecxNext {
|
|
|
3634
3649
|
this.resHeaders['set-cookie'] = setCookieVal;
|
|
3635
3650
|
}
|
|
3636
3651
|
};
|
|
3652
|
+
/**
|
|
3653
|
+
* ログイン時にレスポンスされたvte.cxからのset-cookieを保持する。
|
|
3654
|
+
* @param response vte.cxからのレスポンス
|
|
3655
|
+
*/
|
|
3656
|
+
setLoginCookie = (response) => {
|
|
3657
|
+
// set-cookieの値をレスポンスヘッダ格納変数にセット
|
|
3658
|
+
let setCookieVal = response.headers.get('set-cookie');
|
|
3659
|
+
if (setCookieVal) {
|
|
3660
|
+
const tmpCookies = setCookieVal.split(';');
|
|
3661
|
+
for (const tmpCookie of tmpCookies) {
|
|
3662
|
+
const tmpKeyVal = tmpCookie.split('=');
|
|
3663
|
+
this.loginCookies[tmpKeyVal[0]] = tmpKeyVal[1];
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
};
|
|
3667
|
+
/**
|
|
3668
|
+
* ログイン後のCookie編集
|
|
3669
|
+
* @returns cookie
|
|
3670
|
+
*/
|
|
3671
|
+
editRequestCookie = () => {
|
|
3672
|
+
let cookie = this.req ? this.req.headers.get('cookie') : null;
|
|
3673
|
+
if (!this.loginCookies) {
|
|
3674
|
+
return cookie;
|
|
3675
|
+
}
|
|
3676
|
+
let retCookie = '';
|
|
3677
|
+
if (cookie) {
|
|
3678
|
+
const tmpCookies = cookie.split(';');
|
|
3679
|
+
for (const tmpCookie of tmpCookies) {
|
|
3680
|
+
const tmpKeyVal = tmpCookie.trim().split('=');
|
|
3681
|
+
const tmpName = tmpKeyVal[0];
|
|
3682
|
+
const tmpVal = tmpKeyVal[1];
|
|
3683
|
+
if (!this.loginCookies.hasOwnProperty(tmpName)) {
|
|
3684
|
+
retCookie = `${retCookie}${tmpName}=${tmpVal}; `;
|
|
3685
|
+
//} else {
|
|
3686
|
+
//console.log(`[editRequestCookie] hasOwnProperty (not set) : ${tmpName}=${tmpVal}`)
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
for (const tmpName in this.loginCookies) {
|
|
3691
|
+
const tmpVal = this.loginCookies[tmpName];
|
|
3692
|
+
retCookie = `${retCookie}${tmpName}=${tmpVal};`;
|
|
3693
|
+
}
|
|
3694
|
+
return retCookie;
|
|
3695
|
+
};
|
|
3637
3696
|
/**
|
|
3638
3697
|
* vte.cxからのレスポンスヘッダを、ブラウザへレスポンスする。
|
|
3639
3698
|
* コンテンツの戻し時に使用。
|
|
@@ -3967,6 +4026,7 @@ const fetchVtecx = async (method, url, pHeaders, body, mode) => {
|
|
|
3967
4026
|
const headers = [];
|
|
3968
4027
|
if (pHeaders) {
|
|
3969
4028
|
for (const key in pHeaders) {
|
|
4029
|
+
//console.log(`[vtecxnext fetchVtecx] request header = ${key}: ${pHeaders[key]}`)
|
|
3970
4030
|
headers.push([key, pHeaders[key]]);
|
|
3971
4031
|
}
|
|
3972
4032
|
}
|