From afa54d0984d9d49156f8b6a181f6b036b80ced53 Mon Sep 17 00:00:00 2001 From: daydreamer-json Date: Thu, 5 Feb 2026 09:49:44 +0900 Subject: [PATCH] Move api source code files --- src/cmds/authTest.ts | 24 +++++++++---------- src/cmds/test.ts | 14 +++++------ src/utils/api.ts | 9 ------- .../api/{ => akEndfield}/accountService.ts | 4 ++-- src/utils/api/{ => akEndfield}/binding.ts | 4 ++-- .../api/{ => akEndfield}/defaultSettings.ts | 2 +- src/utils/api/akEndfield/index.ts | 15 ++++++++++++ src/utils/api/{ => akEndfield}/launcher.ts | 4 ++-- src/utils/api/{ => akEndfield}/launcherWeb.ts | 4 ++-- src/utils/api/{ => akEndfield}/u8.ts | 4 ++-- src/utils/api/{ => akEndfield}/webview.ts | 4 ++-- src/utils/api/index.ts | 5 ++++ 12 files changed, 52 insertions(+), 41 deletions(-) delete mode 100644 src/utils/api.ts rename src/utils/api/{ => akEndfield}/accountService.ts (95%) rename src/utils/api/{ => akEndfield}/binding.ts (90%) rename src/utils/api/{ => akEndfield}/defaultSettings.ts (91%) create mode 100644 src/utils/api/akEndfield/index.ts rename src/utils/api/{ => akEndfield}/launcher.ts (95%) rename src/utils/api/{ => akEndfield}/launcherWeb.ts (97%) rename src/utils/api/{ => akEndfield}/u8.ts (95%) rename src/utils/api/{ => akEndfield}/webview.ts (92%) create mode 100644 src/utils/api/index.ts diff --git a/src/cmds/authTest.ts b/src/cmds/authTest.ts index 06d89e2..02401c5 100644 --- a/src/cmds/authTest.ts +++ b/src/cmds/authTest.ts @@ -3,7 +3,7 @@ import CliTable3 from 'cli-table3'; import { HTTPError } from 'ky'; import { DateTime } from 'luxon'; import prompts from 'prompts'; -import apiUtils from '../utils/api.js'; +import apiUtils from '../utils/api/index.js'; import argvUtils from '../utils/argv.js'; import appConfig from '../utils/config.js'; import exitUtils from '../utils/exit.js'; @@ -40,7 +40,7 @@ async function mainCmdHandler() { if (needRetrieveToken === false) { try { logger.debug('Retrieving account service OAuth 2.0 code ...'); - oauth2TokenPreRsp = await apiUtils.apiAkEndfield.accountService.user.oauth2.v2.grant( + oauth2TokenPreRsp = await apiUtils.akEndfield.accountService.user.oauth2.v2.grant( cfg.appCode.accountService.osWinRel, argvUtils.getArgv()['token'], ); @@ -86,7 +86,7 @@ async function mainCmdHandler() { } })(); logger.debug('Retrieving account service token ...'); - const accSrvTokenRsp = await apiUtils.apiAkEndfield.accountService.user.auth.v1.tokenByEmailPassword( + const accSrvTokenRsp = await apiUtils.akEndfield.accountService.user.auth.v1.tokenByEmailPassword( argvUtils.getArgv()['email'], argvUtils.getArgv()['password'], ); @@ -96,18 +96,18 @@ async function mainCmdHandler() { oauth2TokenPreRsp === null ? logger.debug('Retrieving account service OAuth 2.0 code ...') : undefined; const oauth2TokenRsp = oauth2TokenPreRsp === null - ? await apiUtils.apiAkEndfield.accountService.user.oauth2.v2.grant( + ? await apiUtils.akEndfield.accountService.user.oauth2.v2.grant( cfg.appCode.accountService.osWinRel, argvUtils.getArgv()['token'], ) : oauth2TokenPreRsp; - const oauth2TokenBindRsp = await apiUtils.apiAkEndfield.accountService.user.oauth2.v2.grant( + const oauth2TokenBindRsp = await apiUtils.akEndfield.accountService.user.oauth2.v2.grant( cfg.appCode.accountService.binding, argvUtils.getArgv()['token'], 1, ); logger.debug('Retrieving u8 access token ...'); - const u8TokenRsp = await apiUtils.apiAkEndfield.u8.user.auth.v2.tokenByChToken( + const u8TokenRsp = await apiUtils.akEndfield.u8.user.auth.v2.tokenByChToken( cfg.appCode.u8.osWinRel, cfg.channel.osWinRel, oauth2TokenRsp.data.code, @@ -119,13 +119,13 @@ async function mainCmdHandler() { logger.info('Retrieving user information data ...'); logger.debug('Retrieving user account data ...'); - const userAccData = await apiUtils.apiAkEndfield.accountService.user.info.v1.basic( + const userAccData = await apiUtils.akEndfield.accountService.user.info.v1.basic( cfg.appCode.accountService.osWinRel, argvUtils.getArgv()['token'], ); logger.debug('Retrieving user game server data ...'); - const userGameData = await apiUtils.apiAkEndfield.u8.game.server.v1.serverList(u8TokenRsp.data.token); - const userGameBindingData = await apiUtils.apiAkEndfield.binding.account.binding.v1.bindingList( + const userGameData = await apiUtils.akEndfield.u8.game.server.v1.serverList(u8TokenRsp.data.token); + const userGameBindingData = await apiUtils.akEndfield.binding.account.binding.v1.bindingList( oauth2TokenBindRsp.data.token, ); @@ -138,7 +138,7 @@ async function mainCmdHandler() { if (!selectedServerAccData) throw new Error('Game account not found'); const id = selectedServerAccData.serverId; logger.debug('Confirming server availability ...'); - const confirmServerRsp = await apiUtils.apiAkEndfield.u8.game.role.v1.confirmServer( + const confirmServerRsp = await apiUtils.akEndfield.u8.game.role.v1.confirmServer( u8TokenRsp.data.token, parseInt(id), ); @@ -157,7 +157,7 @@ async function mainCmdHandler() { for (const poolTypeEntry of poolTypeList) { let seqId: string | null = null; while (true) { - const rsp = await apiUtils.apiAkEndfield.webview.record.char( + const rsp = await apiUtils.akEndfield.webview.record.char( u8TokenRsp.data.token, parseInt(selectedServerId), poolTypeEntry, @@ -179,7 +179,7 @@ async function mainCmdHandler() { const arr = []; const poolIdList = [...new Set(gachaRecordRsp.map((e) => e.poolId))]; for (const poolId of poolIdList) { - const rsp = await apiUtils.apiAkEndfield.webview.content(parseInt(selectedServerId), poolId, 'ja-jp'); + const rsp = await apiUtils.akEndfield.webview.content(parseInt(selectedServerId), poolId, 'ja-jp'); arr.push({ poolId, ...rsp.data.pool }); } return arr; diff --git a/src/cmds/test.ts b/src/cmds/test.ts index 1c5e7d9..7fe86f9 100644 --- a/src/cmds/test.ts +++ b/src/cmds/test.ts @@ -2,7 +2,7 @@ import path from 'node:path'; import { DateTime } from 'luxon'; import PQueue from 'p-queue'; import semver from 'semver'; -import apiUtils from '../utils/api.js'; +import apiUtils from '../utils/api/index.js'; import argvUtils from '../utils/argv.js'; import appConfig from '../utils/config.js'; import logger from '../utils/logger.js'; @@ -99,7 +99,7 @@ async function mainCmdHandler() { for (const target of gameTargets) { await (async () => { logger.debug(`Fetching latestGame (${target.name}) ...`); - const rsp = await apiUtils.apiAkEndfield.launcher.latestGame( + const rsp = await apiUtils.akEndfield.launcher.latestGame( cfg.appCode.game.osWinRel, target.launcherAppCode, cfg.channel.osWinRel, @@ -170,7 +170,7 @@ async function mainCmdHandler() { const queue = new PQueue({ concurrency: appConfig.threadCount.network }); for (const ver of versionList) { queue.add(async () => { - const rsp = await apiUtils.apiAkEndfield.launcher.latestGame( + const rsp = await apiUtils.akEndfield.launcher.latestGame( cfg.appCode.game.osWinRel, target.launcherAppCode, cfg.channel.osWinRel, @@ -244,7 +244,7 @@ async function mainCmdHandler() { const versionInfoList = ( (await Bun.file(gameAllJsonPath).json()).map((e: any) => e.rsp) as Awaited< - ReturnType + ReturnType >[] ) .map((e) => ({ @@ -258,7 +258,7 @@ async function mainCmdHandler() { let isLatestWrote: boolean = false; for (const versionInfoEntry of versionInfoList) { if (!versionInfoEntry.randStr) throw new Error('version rand_str not found'); - const rsp = await apiUtils.apiAkEndfield.launcher.latestGameResources( + const rsp = await apiUtils.akEndfield.launcher.latestGameResources( cfg.appCode.game.osWinRel, versionInfoEntry.versionMinor, versionInfoEntry.version, @@ -292,7 +292,7 @@ async function mainCmdHandler() { logger.debug('Fetching latestLauncher ...'); const launcherTargetAppList = ['EndField', 'official'] as const; for (const launcherTargetAppEntry of launcherTargetAppList) { - const rsp = await apiUtils.apiAkEndfield.launcher.latestLauncher( + const rsp = await apiUtils.akEndfield.launcher.latestLauncher( cfg.appCode.launcher.osWinRel, cfg.channel.osWinRel, cfg.channel.osWinRel, @@ -468,7 +468,7 @@ async function mainCmdHandler() { ).json(); const resVersionSet: { resVersion: string; - rsp: { rsp: Awaited> }; + rsp: { rsp: Awaited> }; versions: string[]; }[] = (() => { const resVersions: string[] = [...new Set(gameAllJson.map((e: any) => e.rsp.res_version))] as string[]; diff --git a/src/utils/api.ts b/src/utils/api.ts deleted file mode 100644 index 2b6b18d..0000000 --- a/src/utils/api.ts +++ /dev/null @@ -1,9 +0,0 @@ -import accountService from './api/accountService.js'; -import binding from './api/binding.js'; -import launcher from './api/launcher.js'; -import u8 from './api/u8.js'; -import webview from './api/webview.js'; - -export default { - apiAkEndfield: { launcher, accountService, u8, binding, webview }, -}; diff --git a/src/utils/api/accountService.ts b/src/utils/api/akEndfield/accountService.ts similarity index 95% rename from src/utils/api/accountService.ts rename to src/utils/api/akEndfield/accountService.ts index 5dade9a..722ff7e 100644 --- a/src/utils/api/accountService.ts +++ b/src/utils/api/akEndfield/accountService.ts @@ -1,6 +1,6 @@ import ky from 'ky'; -import * as TypesApiAkEndfield from '../../types/api/akEndfield/Api.js'; -import appConfig from '../config.js'; +import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js'; +import appConfig from '../../config.js'; import defaultSettings from './defaultSettings.js'; export default { diff --git a/src/utils/api/binding.ts b/src/utils/api/akEndfield/binding.ts similarity index 90% rename from src/utils/api/binding.ts rename to src/utils/api/akEndfield/binding.ts index 44b7016..66b2b12 100644 --- a/src/utils/api/binding.ts +++ b/src/utils/api/akEndfield/binding.ts @@ -1,6 +1,6 @@ import ky from 'ky'; -import * as TypesApiAkEndfield from '../../types/api/akEndfield/Api.js'; -import appConfig from '../config.js'; +import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js'; +import appConfig from '../../config.js'; import defaultSettings from './defaultSettings.js'; export default { diff --git a/src/utils/api/defaultSettings.ts b/src/utils/api/akEndfield/defaultSettings.ts similarity index 91% rename from src/utils/api/defaultSettings.ts rename to src/utils/api/akEndfield/defaultSettings.ts index 01aabcd..9f0a86c 100644 --- a/src/utils/api/defaultSettings.ts +++ b/src/utils/api/akEndfield/defaultSettings.ts @@ -1,4 +1,4 @@ -import appConfig from '../config.js'; +import appConfig from '../../config.js'; export default { ky: { diff --git a/src/utils/api/akEndfield/index.ts b/src/utils/api/akEndfield/index.ts new file mode 100644 index 0000000..c402bb4 --- /dev/null +++ b/src/utils/api/akEndfield/index.ts @@ -0,0 +1,15 @@ +import accountService from './accountService.js'; +import binding from './binding.js'; +import launcher from './launcher.js'; +import launcherWeb from './launcherWeb.js'; +import u8 from './u8.js'; +import webview from './webview.js'; + +export default { + accountService, + binding, + launcher, + launcherWeb, + u8, + webview, +}; diff --git a/src/utils/api/launcher.ts b/src/utils/api/akEndfield/launcher.ts similarity index 95% rename from src/utils/api/launcher.ts rename to src/utils/api/akEndfield/launcher.ts index af25c41..742e186 100644 --- a/src/utils/api/launcher.ts +++ b/src/utils/api/akEndfield/launcher.ts @@ -1,7 +1,7 @@ import ky from 'ky'; import semver from 'semver'; -import * as TypesApiAkEndfield from '../../types/api/akEndfield/Api.js'; -import appConfig from '../config.js'; +import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js'; +import appConfig from '../../config.js'; import defaultSettings from './defaultSettings.js'; import launcherWeb from './launcherWeb.js'; diff --git a/src/utils/api/launcherWeb.ts b/src/utils/api/akEndfield/launcherWeb.ts similarity index 97% rename from src/utils/api/launcherWeb.ts rename to src/utils/api/akEndfield/launcherWeb.ts index fbb8ca0..f2e110c 100644 --- a/src/utils/api/launcherWeb.ts +++ b/src/utils/api/akEndfield/launcherWeb.ts @@ -1,6 +1,6 @@ import ky from 'ky'; -import * as TypesApiAkEndfield from '../../types/api/akEndfield/Api.js'; -import appConfig from '../config.js'; +import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js'; +import appConfig from '../../config.js'; import defaultSettings from './defaultSettings.js'; export default { diff --git a/src/utils/api/u8.ts b/src/utils/api/akEndfield/u8.ts similarity index 95% rename from src/utils/api/u8.ts rename to src/utils/api/akEndfield/u8.ts index af54a9d..16f15b4 100644 --- a/src/utils/api/u8.ts +++ b/src/utils/api/akEndfield/u8.ts @@ -1,6 +1,6 @@ import ky from 'ky'; -import * as TypesApiAkEndfield from '../../types/api/akEndfield/Api.js'; -import appConfig from '../config.js'; +import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js'; +import appConfig from '../../config.js'; import defaultSettings from './defaultSettings.js'; export default { diff --git a/src/utils/api/webview.ts b/src/utils/api/akEndfield/webview.ts similarity index 92% rename from src/utils/api/webview.ts rename to src/utils/api/akEndfield/webview.ts index 8f5e928..9851f5f 100644 --- a/src/utils/api/webview.ts +++ b/src/utils/api/akEndfield/webview.ts @@ -1,6 +1,6 @@ import ky from 'ky'; -import * as TypesApiAkEndfield from '../../types/api/akEndfield/Api.js'; -import appConfig from '../config.js'; +import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js'; +import appConfig from '../../config.js'; import defaultSettings from './defaultSettings.js'; export default { diff --git a/src/utils/api/index.ts b/src/utils/api/index.ts new file mode 100644 index 0000000..f636b4a --- /dev/null +++ b/src/utils/api/index.ts @@ -0,0 +1,5 @@ +import akEndfield from './akEndfield/index.js'; + +export default { + akEndfield, +};