Skip to content

Commit

Permalink
[*] Migrate all v1 API to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 3, 2024
1 parent bed812a commit 686f933
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 93 deletions.
2 changes: 0 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import v1 from './v1'
import v2 from './v2'

const api = {
v1: v1,
v2: v2
}

Expand Down
15 changes: 0 additions & 15 deletions src/api/v1/Donate/GetDonateInfo.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/api/v1/Donate/index.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/api/v1/Proxies/GetRandomPort.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/api/v1/Proxies/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/api/v1/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/api/v2/donate/index.ts
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions src/api/v2/donate/info.api.ts
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions src/api/v2/node/all.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion src/api/v2/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import all from './all.api'
import port from './port'

export default {
all: all
all: all,
port: port
}
5 changes: 5 additions & 0 deletions src/api/v2/node/port/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import random from './random.api'

export default {
random: random
}
13 changes: 13 additions & 0 deletions src/api/v2/node/port/random.api.ts
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions src/views/DonateView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const displayMessagesDefault = ref(5)
const displayAllMessages = ref(false)
const tradeInfo = ref({
id: 1,
username: '',
message: null,
trade_name: '',
trade_no: '',
Expand All @@ -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)
}
Expand Down
51 changes: 24 additions & 27 deletions src/views/auth/oauth/AppAuthView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions src/views/games/MinecraftView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions src/views/proxies/AddView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,16 @@ 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)
}
if (!rs) return
if (rs.status === 200) {
proxyInfo.value.remotePort = rs.data.port
} else {
sendErrorMessage(rs.message)
}
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/views/proxies/ConfigView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/views/proxies/ProxiesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 686f933

Please sign in to comment.