diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index f150634d..e12fa26c 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -39,7 +39,7 @@ jobs:
with:
envkey_DEBUG: true
envkey_LTOKEN: ${{ secrets.LTOKEN }}
- envkey_LTUID: ${{ secrets.LTUID }}
+ envkey_LTUID_V2: ${{ secrets.LTUID_V2 }}
envkey_ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
envkey_COOKIE_TOKEN: ${{ secrets.COOKIE_TOKEN }}
envkey_ACCOUNT_ID_V2: ${{ secrets.ACCOUNT_ID_V2 }}
diff --git a/README.md b/README.md
index 99abd4cb..5667c3f5 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,7 @@ For Yarn
1. To begin, login with your [HoYoLab](https://www.hoyolab.com/home) Account or from [Battlepass](https://act.hoyolab.com/app/community-game-records-sea/index.html?bbs_presentation_style=fullscreen&bbs_auth_required=true&gid=2&user_id=122516750&utm_source=hoyolab&utm_medium=gamecard&bbs_theme=light&bbs_theme_device=1#/ys).
2. Type `java` in the address bar followed by the script down below.
3. ```javascript
- script: (function(){if(document.cookie.includes('ltoken')&&document.cookie.includes('ltuid')){const e=document.createElement('input');e.value=document.cookie,document.body.appendChild(e),e.focus(),e.select();var t=document.execCommand('copy');document.body.removeChild(e),t?alert('HoYoLAB cookie copied to clipboard'):prompt('Failed to copy cookie. Manually copy the cookie below:\n\n',e.value)}else alert('Please logout and log back in. Cookie is expired/invalid!')})();
+ script: (function(){if(document.cookie.includes('ltoken_v2')&&document.cookie.includes('ltuid_v2')){const e=document.createElement('input');e.value=document.cookie,document.body.appendChild(e),e.focus(),e.select();var t=document.execCommand('copy');document.body.removeChild(e),t?alert('HoYoLAB cookie copied to clipboard'):prompt('Failed to copy cookie. Manually copy the cookie below:\n\n',e.value)}else alert('Please logout and log back in. Cookie is expired/invalid!')})();
```
4. Once you've successfully ran the script, click the Click here to copy! button to copy the cookie.
5. Finally, you can copy your cookie
diff --git a/docs/docs/guide/get-started.md b/docs/docs/guide/get-started.md
index 213e6ee2..0dd34d1f 100644
--- a/docs/docs/guide/get-started.md
+++ b/docs/docs/guide/get-started.md
@@ -32,7 +32,7 @@ $ yarn add hoyoapi
2. Type `java` in the address bar followed by the script down below.
3. ```javascript
script: (function() {
- if (document.cookie.includes('ltoken') && document.cookie.includes('ltuid')) {
+ if (document.cookie.includes('ltoken_v2') && document.cookie.includes('ltuid_v2')) {
const input = document.createElement('input');
input.value = document.cookie;
document.body.appendChild(input);
diff --git a/src/client/hoyolab/hoyolab.interface.ts b/src/client/hoyolab/hoyolab.interface.ts
index 6c2b815e..f0e07a42 100644
--- a/src/client/hoyolab/hoyolab.interface.ts
+++ b/src/client/hoyolab/hoyolab.interface.ts
@@ -17,7 +17,7 @@ export interface IHoyolabOptions {
* The cookie used to authenticate the request. This can be either a string or an {@link ICookie} object.
*/
cookie:
- | Pick
+ | Pick
| string
/**
diff --git a/src/client/hoyolab/hoyolab.ts b/src/client/hoyolab/hoyolab.ts
index 2eb0cb42..8afba8c0 100644
--- a/src/client/hoyolab/hoyolab.ts
+++ b/src/client/hoyolab/hoyolab.ts
@@ -38,7 +38,7 @@ export class Hoyolab {
*
* @constructor
* @param {IHoyolabOptions} options - The options to initialize the `Hoyolab` instance.
- * @throws {HoyoAPIError} If `ltuid` or `ltoken` keys are missing in the `ICookie` object.
+ * @throws {HoyoAPIError} If `ltuidV2` or `ltokenV2` keys are missing in the `ICookie` object.
*
* @remarks
* Because CookieTokenV2 has a short expiration time and cannot be refreshed so far.
@@ -105,7 +105,7 @@ export class Hoyolab {
}
this.request.setQueryParams({
- uid: this.cookie.ltuid,
+ uid: this.cookie.ltuidV2,
sLangKey: this.cookie.mi18nLang,
})
const {
@@ -173,7 +173,7 @@ export class Hoyolab {
/* c8 ignore start */
this.request.setQueryParams({
uid:
- this.cookie.ltuid || this.cookie.accountId || this.cookie.accountIdV2,
+ this.cookie.ltuidV2 || this.cookie.accountId || this.cookie.accountIdV2,
})
const { response: res } = await this.request.send(GAME_RECORD_CARD_API)
diff --git a/src/cookie/cookie.interface.ts b/src/cookie/cookie.interface.ts
index 140e3cd9..7923124b 100644
--- a/src/cookie/cookie.interface.ts
+++ b/src/cookie/cookie.interface.ts
@@ -7,14 +7,14 @@ import { LanguageEnum } from '../language'
*/
export interface ICookie {
/**
- * The value of the "ltoken" cookie.
+ * The value of the "ltoken_v2" cookie.
*/
- ltoken: string
+ ltokenV2: string
/**
- * The value of the "ltuid" cookie.
+ * The value of the "ltuid_v2" cookie.
*/
- ltuid: number
+ ltuidV2: number
/**
* The value of the "cookieToken" cookie, if it exists.
diff --git a/src/cookie/cookie.ts b/src/cookie/cookie.ts
index eccf5116..60ebafc7 100644
--- a/src/cookie/cookie.ts
+++ b/src/cookie/cookie.ts
@@ -21,8 +21,8 @@ export class Cookie {
const cookies: Map = new Map()
const keys: string[] = [
- 'ltoken',
- 'ltuid',
+ 'ltoken_v2',
+ 'ltuid_v2',
'account_id',
'cookie_token',
'account_id_v2',
@@ -44,28 +44,28 @@ export class Cookie {
cookies.set(key, val)
- if (['ltuid', 'account_id', 'account_id_v2'].includes(cookieSplited[0])) {
+ if (['ltuid_v2', 'account_id', 'account_id_v2'].includes(cookieSplited[0])) {
cookies.set(key, parseInt(cookies.get(key), 10))
} else if (cookieSplited[0] === 'mi18nLang') {
cookies.set(key, Language.parseLang(cookies.get(key)))
}
})
- const ltuid = cookies.get('ltuid')
+ const ltuid = cookies.get('ltuidV2')
const accountId = cookies.get('accountId')
const accountIdV2 = cookies.get('accountIdV2')
if (ltuid && !accountId) {
cookies.set('accountId', ltuid)
} else if (!ltuid && accountId) {
- cookies.set('ltuid', accountId)
+ cookies.set('ltuidV2', accountId)
}
if (!accountIdV2 && (accountId || ltuid) !== null) {
cookies.set('accountIdV2', accountId || ltuid)
}
- if (!cookies.get('ltoken') || !cookies.get('ltuid')) {
+ if (!cookies.get('ltokenV2') || !cookies.get('ltuidV2')) {
throw new HoyoAPIError('Cookie key ltuid or ltoken doesnt exist !')
}
@@ -76,11 +76,11 @@ export class Cookie {
* Converts an `ICookie` object into a cookie string.
* @param {ICookie} cookie - The `ICookie` object to convert.
* @returns {string} A string representing the cookie.
- * @throws {HoyoAPIError} If the `ltuid` or `ltoken` key is missing in the `ICookie` object.
+ * @throws {HoyoAPIError} If the `ltuidV2` or `ltokenV2` key is missing in the `ICookie` object.
*/
static parseCookie(cookie: ICookie): string {
if (!cookie.accountId) {
- cookie.accountId = cookie.ltuid
+ cookie.accountId = cookie.ltuidV2
}
const cookies = Object.entries(cookie)
diff --git a/src/request/request.ts b/src/request/request.ts
index 6f160c51..092e714c 100644
--- a/src/request/request.ts
+++ b/src/request/request.ts
@@ -74,7 +74,7 @@ export class HTTPRequest {
}
constructor(cookie?: string) {
- if (cookie) this.headers.Cookie = cookie
+ if (cookie) this.headers.Cookie = cookie.replace("ltokenV2", "ltoken_v2").replace("ltuidV2", "ltuid_v2");
this.cache = new Cache()
}
diff --git a/tests/cookie.test.ts b/tests/cookie.test.ts
index 40b391da..2632235d 100644
--- a/tests/cookie.test.ts
+++ b/tests/cookie.test.ts
@@ -3,8 +3,8 @@ import { Cookie, HoyoAPIError } from '../src'
test('parseCookie return should be valid', (t) => {
const cookie = Cookie.parseCookie({
- ltoken: 'ltoken',
- ltuid: 1,
+ ltokenV2: 'ltoken_v2',
+ ltuidV2: 1,
cookieToken: 'cookieToken',
mi18nLang: 'id-id',
cookieTokenV2: 'cookieTokenV2',
@@ -12,18 +12,18 @@ test('parseCookie return should be valid', (t) => {
t.deepEqual(
cookie,
- 'ltoken=ltoken; ltuid=1; cookie_token=cookieToken; mi18nLang=id-id; cookie_token_v2=cookieTokenV2; account_id=1',
+ 'ltoken_v2=ltoken; ltuid_v2=1; cookie_token=cookieToken; mi18nLang=id-id; cookie_token_v2=cookieTokenV2; account_id=1',
)
})
test('parseCookieString return should be valid', (t) => {
const cookieString = Cookie.parseCookieString(
- 'ltoken=ltoken; ltuid=1; cookie_token=cookieToken; mi18nLang=id-id; cookie_token_v2=cookieTokenV2; account_id=1',
+ 'ltoken_v2=ltokenV2; ltuid_v2=1; cookie_token=cookieToken; mi18nLang=id-id; cookie_token_v2=cookieTokenV2; account_id=1',
)
t.deepEqual(cookieString, {
- ltoken: 'ltoken',
- ltuid: 1,
+ ltokenV2: 'ltokenV2',
+ ltuidV2: 1,
cookieToken: 'cookieToken',
mi18nLang: 'id-id',
cookieTokenV2: 'cookieTokenV2',
@@ -34,12 +34,12 @@ test('parseCookieString return should be valid', (t) => {
test('parseCookieString return should be valid when account_id is null', (t) => {
const cookieString = Cookie.parseCookieString(
- 'ltoken=ltoken; ltuid=1; cookie_token=cookieToken; cookie_token_v2=cookieTokenV2; mi18nLang=id-id',
+ 'ltoken_v2=ltoken; ltuid_v2=1; cookie_token=cookieToken; cookie_token_v2=cookieTokenV2; mi18nLang=id-id',
)
t.deepEqual(cookieString, {
- ltoken: 'ltoken',
- ltuid: 1,
+ ltokenV2: 'ltokenV2',
+ ltuidV2: 1,
cookieToken: 'cookieToken',
mi18nLang: 'id-id',
cookieTokenV2: 'cookieTokenV2',
@@ -48,13 +48,13 @@ test('parseCookieString return should be valid when account_id is null', (t) =>
})
})
-test('parseCookieString return should be valid when ltuid is null', (t) => {
+test('parseCookieString return should be valid when ltuidV2 is null', (t) => {
const cookieString = Cookie.parseCookieString(
- 'ltoken=ltoken; account_id=1; cookie_token_v2=cookieTokenV2; cookie_token=cookieToken; mi18nLang=id-id',
+ 'ltoken_v2=ltokenV2; account_id=1; cookie_token_v2=cookieTokenV2; cookie_token=cookieToken; mi18nLang=id-id',
)
t.deepEqual(cookieString, {
- ltoken: 'ltoken',
+ ltokenV2: 'ltokenV2',
ltuid: 1,
cookieToken: 'cookieToken',
mi18nLang: 'id-id',
diff --git a/tests/genshin_impact/setup.ts b/tests/genshin_impact/setup.ts
index 9e70cdf0..46f72635 100644
--- a/tests/genshin_impact/setup.ts
+++ b/tests/genshin_impact/setup.ts
@@ -5,8 +5,8 @@ config()
export const cookie: ICookie = {
accountId: parseInt(process.env.ACCOUNT_ID ?? '0'),
cookieToken: process.env.COOKIE_TOKEN,
- ltoken: process.env.LTOKEN ?? '',
- ltuid: parseInt(process.env.LTUID ?? '0'),
+ ltokenV2: process.env.LTOKEN_V2 ?? '',
+ ltuidV2: parseInt(process.env.LTUID_V2 ?? '0'),
cookieTokenV2: process.env.COOKIE_TOKEN_V2 ?? '',
accountIdV2: parseInt(process.env.ACCOUNT_ID_V2 ?? '0'),
accountMidV2: process.env.ACCOUNT_MID_V2,
diff --git a/tests/honkai_impact/setup.ts b/tests/honkai_impact/setup.ts
index 843dee39..71ca7868 100644
--- a/tests/honkai_impact/setup.ts
+++ b/tests/honkai_impact/setup.ts
@@ -5,8 +5,8 @@ config()
export const cookie: ICookie = {
accountId: parseInt(process.env.ACCOUNT_ID ?? '0'),
cookieToken: process.env.COOKIE_TOKEN,
- ltoken: process.env.LTOKEN ?? '',
- ltuid: parseInt(process.env.LTUID ?? '0'),
+ ltokenV2: process.env.LTOKEN_V2 ?? '',
+ ltuidV2: parseInt(process.env.LTUID_V2 ?? '0'),
cookieTokenV2: process.env.COOKIE_TOKEN_V2 ?? '',
accountIdV2: parseInt(process.env.ACCOUNT_ID_V2 ?? '0'),
accountMidV2: process.env.ACCOUNT_MID_V2,
diff --git a/tests/honkai_starrail/setup.ts b/tests/honkai_starrail/setup.ts
index 3b09967c..04c75d24 100644
--- a/tests/honkai_starrail/setup.ts
+++ b/tests/honkai_starrail/setup.ts
@@ -5,8 +5,8 @@ config()
export const cookie: ICookie = {
accountId: parseInt(process.env.ACCOUNT_ID ?? '0' ?? '0'),
cookieToken: process.env.COOKIE_TOKEN,
- ltoken: process.env.LTOKEN ?? '',
- ltuid: parseInt(process.env.LTUID ?? '0'),
+ ltokenV2: process.env.LTOKEN_V2 ?? '',
+ ltuidV2: parseInt(process.env.LTUID_V2 ?? '0'),
cookieTokenV2: process.env.COOKIE_TOKEN_V2 ?? '',
accountIdV2: parseInt(process.env.ACCOUNT_ID_V2 ?? '0'),
accountMidV2: process.env.ACCOUNT_MID_V2,