From 686f9337de9670a098b71783b085b2cd1e094049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Tue, 3 Dec 2024 22:15:28 +0800 Subject: [PATCH] [*] Migrate all v1 API to v2 --- src/api/index.ts | 2 -- src/api/v1/Donate/GetDonateInfo.ts | 15 -------- src/api/v1/Donate/index.ts | 5 --- src/api/v1/Proxies/GetRandomPort.ts | 21 ------------ src/api/v1/Proxies/index.ts | 5 --- src/api/v1/index.ts | 7 ---- src/api/v2/donate/index.ts | 2 ++ src/api/v2/donate/info.api.ts | 16 +++++++++ src/api/v2/node/all.api.ts | 6 ++-- src/api/v2/node/index.ts | 4 ++- src/api/v2/node/port/index.ts | 5 +++ src/api/v2/node/port/random.api.ts | 13 +++++++ src/views/DonateView.vue | 6 ++-- src/views/auth/oauth/AppAuthView.vue | 51 +++++++++++++--------------- src/views/games/MinecraftView.vue | 2 ++ src/views/proxies/AddView.vue | 6 ++-- src/views/proxies/ConfigView.vue | 2 +- src/views/proxies/ProxiesView.vue | 2 +- 18 files changed, 77 insertions(+), 93 deletions(-) delete mode 100644 src/api/v1/Donate/GetDonateInfo.ts delete mode 100644 src/api/v1/Donate/index.ts delete mode 100644 src/api/v1/Proxies/GetRandomPort.ts delete mode 100644 src/api/v1/Proxies/index.ts delete mode 100644 src/api/v1/index.ts create mode 100644 src/api/v2/donate/info.api.ts create mode 100644 src/api/v2/node/port/index.ts create mode 100644 src/api/v2/node/port/random.api.ts diff --git a/src/api/index.ts b/src/api/index.ts index 242338f..9d64fa4 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,8 +1,6 @@ -import v1 from './v1' import v2 from './v2' const api = { - v1: v1, v2: v2 } diff --git a/src/api/v1/Donate/GetDonateInfo.ts b/src/api/v1/Donate/GetDonateInfo.ts deleted file mode 100644 index 7b6748f..0000000 --- a/src/api/v1/Donate/GetDonateInfo.ts +++ /dev/null @@ -1,15 +0,0 @@ -import base from '@/api/base' -//@ts-ignore -import { get } from '@/utils/request' - -/** - * 列出赞助列表 - */ -const GetDonateInfo = async (trade_no: string) => { - const rs = get(`${base.api_v1_url}/Donate/GetDonateInfo`, { - trade_no: trade_no - }) - return base.buildResponse(await rs, false) -} - -export default GetDonateInfo diff --git a/src/api/v1/Donate/index.ts b/src/api/v1/Donate/index.ts deleted file mode 100644 index cef8189..0000000 --- a/src/api/v1/Donate/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import GetDonateInfo from './GetDonateInfo' - -export default { - GetDonateInfo: GetDonateInfo -} diff --git a/src/api/v1/Proxies/GetRandomPort.ts b/src/api/v1/Proxies/GetRandomPort.ts deleted file mode 100644 index 384be6e..0000000 --- a/src/api/v1/Proxies/GetRandomPort.ts +++ /dev/null @@ -1,21 +0,0 @@ -import base from '@/api/base' -//@ts-ignore -import { get } from '@/utils/request' - -/** - * 获取随机端口 - * @returns { - * status: int, - * data: { - * port: string - * } - * } - */ -const GetRandomPort = async (id: number) => { - const rs = await get(`${base.api_v1_url}/Proxies/GetRandomPort`, { - id: id - }) - return base.buildResponse(rs, false) -} - -export default GetRandomPort diff --git a/src/api/v1/Proxies/index.ts b/src/api/v1/Proxies/index.ts deleted file mode 100644 index df75618..0000000 --- a/src/api/v1/Proxies/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import GetRandomPort from './GetRandomPort' - -export default { - GetRandomPort: GetRandomPort -} diff --git a/src/api/v1/index.ts b/src/api/v1/index.ts deleted file mode 100644 index a0ad471..0000000 --- a/src/api/v1/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Proxies from './Proxies' -import Donate from './Donate' - -export default { - Proxies: Proxies, - Donate: Donate -} diff --git a/src/api/v2/donate/index.ts b/src/api/v2/donate/index.ts index 7f9b0d6..35f53b1 100644 --- a/src/api/v2/donate/index.ts +++ b/src/api/v2/donate/index.ts @@ -1,9 +1,11 @@ import root from './root.api' import list from './list.api' +import info from './info.api' import say from './say' export default { root: root, list: list, + info: info, say: say } diff --git a/src/api/v2/donate/info.api.ts b/src/api/v2/donate/info.api.ts new file mode 100644 index 0000000..84ceca5 --- /dev/null +++ b/src/api/v2/donate/info.api.ts @@ -0,0 +1,16 @@ +import base from '@/api/base' +//@ts-ignore +import { get } from '@/utils/request' + +/** + * 获取捐赠订单信息 + */ +const list = async (user_id: number, trade_no: string) => { + const rs = get(`${base.api_v2_url}/donate/info`, { + user_id: user_id, + trade_no: trade_no + }) + return base.buildResponse(await rs) +} + +export default list diff --git a/src/api/v2/node/all.api.ts b/src/api/v2/node/all.api.ts index efcbc41..a4b2059 100644 --- a/src/api/v2/node/all.api.ts +++ b/src/api/v2/node/all.api.ts @@ -2,8 +2,10 @@ import base from '@/api/base' //@ts-ignore import { get } from '@/utils/request' -const all = async () => { - const rs = get(`${base.api_v2_url}/node/all`, {}) +const all = async (user_id: number) => { + const rs = get(`${base.api_v2_url}/node/all`, { + user_id: user_id + }) return base.buildResponse(await rs) } diff --git a/src/api/v2/node/index.ts b/src/api/v2/node/index.ts index b597983..bb895da 100644 --- a/src/api/v2/node/index.ts +++ b/src/api/v2/node/index.ts @@ -1,5 +1,7 @@ import all from './all.api' +import port from './port' export default { - all: all + all: all, + port: port } diff --git a/src/api/v2/node/port/index.ts b/src/api/v2/node/port/index.ts new file mode 100644 index 0000000..d3fd61b --- /dev/null +++ b/src/api/v2/node/port/index.ts @@ -0,0 +1,5 @@ +import random from './random.api' + +export default { + random: random +} diff --git a/src/api/v2/node/port/random.api.ts b/src/api/v2/node/port/random.api.ts new file mode 100644 index 0000000..fbaf054 --- /dev/null +++ b/src/api/v2/node/port/random.api.ts @@ -0,0 +1,13 @@ +import base from '@/api/base' +//@ts-ignore +import { get } from '@/utils/request' + +const random = async (user_id: number, node_id: number) => { + const rs = get(`${base.api_v2_url}/node/port/random`, { + user_id: user_id, + node_id: node_id + }) + return base.buildResponse(await rs) +} + +export default random diff --git a/src/views/DonateView.vue b/src/views/DonateView.vue index 069acfb..229fdce 100644 --- a/src/views/DonateView.vue +++ b/src/views/DonateView.vue @@ -147,7 +147,6 @@ const displayMessagesDefault = ref(5) const displayAllMessages = ref(false) const tradeInfo = ref({ id: 1, - username: '', message: null, trade_name: '', trade_no: '', @@ -170,14 +169,13 @@ onMounted(async () => { showModal.value = true let rs try { - rs = await api.v2.Donate.GetDonateInfo(inputTradeNo) + rs = await api.v2.donate.info(userData.getters.get_user_id, inputTradeNo) } catch (e) { sendErrorMessage('请求列表失败: ' + e) } if (!rs) return if (rs.status === 200) { - if (rs.data) tradeInfo.value = rs.data - else sendErrorMessage('返回数据无效') + tradeInfo.value = rs.data } else { sendErrorMessage(rs.message) } diff --git a/src/views/auth/oauth/AppAuthView.vue b/src/views/auth/oauth/AppAuthView.vue index 0ecddc0..ed7c79a 100644 --- a/src/views/auth/oauth/AppAuthView.vue +++ b/src/views/auth/oauth/AppAuthView.vue @@ -126,13 +126,12 @@ async function doAuthorize() { acceptLoading.value = false return } - if (rs != null) { - if (rs.status === 200) { - sendSuccessMessage('授权成功,正在重定向,请不要刷新浏览器') - window.location.href = `${urlKeys.redirectUrl}?refresh_token=${rs.data.refresh_token}` - } else { - sendErrorMessage('授权失败: ' + rs.message) - } + if (!rs) return + if (rs.status === 200) { + sendSuccessMessage('授权成功,正在重定向,请不要刷新浏览器') + window.location.href = `${urlKeys.redirectUrl}?refresh_token=${rs.data.refresh_token}` + } else { + sendErrorMessage('授权失败: ' + rs.message) } acceptLoading.value = false } @@ -153,18 +152,17 @@ onMounted(async () => { sendErrorMessage(e) return false } - if (rs != null) { - if (rs.status === 200) { - applicationName.value = rs.data.name - applicationDescription.value = rs.data.description - return true - } else if (rs.status === 404) { - sendErrorMessage('未找到此应用程序') - valid.value = false - return true - } else { - sendErrorMessage(rs.message) - } + if (rs) return false + if (rs.status === 200) { + applicationName.value = rs.data.name + applicationDescription.value = rs.data.description + return true + } else if (rs.status === 404) { + sendErrorMessage('未找到此应用程序') + valid.value = false + return true + } else { + sendErrorMessage(rs.message) } return false } @@ -178,14 +176,13 @@ onMounted(async () => { sendErrorMessage(e) return false } - if (rs != null) { - if (rs.status === 200) { - // logger.info(rs.data) - permissionList = rs.data.list - return true - } else { - sendErrorMessage(rs.message) - } + if (!rs) return false + if (rs.status === 200) { + // logger.info(rs.data) + permissionList = rs.data.list + return true + } else { + sendErrorMessage(rs.message) } return false } diff --git a/src/views/games/MinecraftView.vue b/src/views/games/MinecraftView.vue index f1c7c4c..64e392b 100644 --- a/src/views/games/MinecraftView.vue +++ b/src/views/games/MinecraftView.vue @@ -102,6 +102,8 @@ async function initProxyList() { }) }) if (proxies.length !== 0) selected.value = proxies[0].id + } else if (rs.status === 404) { + // Nothing to do here } else { sendErrorMessage(rs.message) } diff --git a/src/views/proxies/AddView.vue b/src/views/proxies/AddView.vue index fe0e4a8..db348f9 100644 --- a/src/views/proxies/AddView.vue +++ b/src/views/proxies/AddView.vue @@ -287,7 +287,7 @@ async function randomPort() { } let rs try { - rs = await api.v1.Proxies.GetRandomPort(proxyInfo.value.nodeId) + rs = await api.v2.node.port.random(userData.getters.get_user_id, proxyInfo.value.nodeId) } catch (e) { logger.error(e) sendErrorMessage('请求隧道端口失败: ' + e) @@ -295,6 +295,8 @@ async function randomPort() { if (!rs) return if (rs.status === 200) { proxyInfo.value.remotePort = rs.data.port + } else { + sendErrorMessage(rs.message) } } @@ -351,7 +353,7 @@ onMounted(async () => { loading.value = true let rs try { - rs = await api.v2.node.all() + rs = await api.v2.node.all(userData.getters.get_user_id) } catch (e) { logger.error(e) sendErrorMessage('请求节点列表失败: ' + e) diff --git a/src/views/proxies/ConfigView.vue b/src/views/proxies/ConfigView.vue index 0438c3f..811ba19 100644 --- a/src/views/proxies/ConfigView.vue +++ b/src/views/proxies/ConfigView.vue @@ -99,7 +99,7 @@ const code = ref('') onMounted(async () => { let rs try { - rs = await api.v2.node.all() + rs = await api.v2.node.all(userData.getters.get_user_id) } catch (e) { logger.error(e) sendErrorMessage('请求节点列表失败: ' + e) diff --git a/src/views/proxies/ProxiesView.vue b/src/views/proxies/ProxiesView.vue index 8721289..55fc35a 100644 --- a/src/views/proxies/ProxiesView.vue +++ b/src/views/proxies/ProxiesView.vue @@ -528,7 +528,7 @@ const serverList = ref([ async function initList() { let rs1 try { - rs1 = await api.v2.node.all() + rs1 = await api.v2.node.all(userData.getters.get_user_id) } catch (e) { sendErrorMessage('请求节点列表失败: ' + e) }