加入自动测试服务器是否在线

This commit is contained in:
lingling 2023-03-20 02:14:37 +08:00
parent ec57506803
commit 68129cd5d0
3 changed files with 35 additions and 7 deletions

View File

@ -3,8 +3,8 @@ class getdata {
async get_server() {
return await api.get('https://api.shagain.club/api.php?type=list');
}
async text_server() {
return await api.get('https://api.shagain.club/api.php?type=list');
async text_server(url: string) {
return await api.post('http://149.129.107.38:1323/textserver', { url });
}
}
export { getdata };

View File

@ -1,8 +1,9 @@
<template>
<div class="row">
<div class="col-12">
<h6 style="text-align: center;margin: 1rem;">{{ props.serve.tips }} <q-icon title="在线" name="check_circle_outline"
style="color: green;" /> <q-icon title="离线" name="hide_source" style="color: red;" /></h6>
<h6 style="text-align: center;margin: 1rem;">{{ props.serve.tips }} <q-icon v-show="online" title="在线"
name="check_circle_outline" style="color: green;" /> <q-icon v-show="!online" title="离线" name="hide_source"
style="color: red;" /></h6>
<q-input v-model="outtext" filled autogrow />
<div style="text-align: center;margin-top: 1rem;">
<q-btn color="white" text-color="black" @click="copy" label="复制" />
@ -21,6 +22,7 @@ import {
import { copyToClipboard } from 'quasar'
import { encode, decode } from 'js-base64';
import { useQuasar } from 'quasar'
import { getdata } from 'src/api/api'
export default defineComponent({
name: 'LinkItem',
props: {
@ -33,6 +35,17 @@ export default defineComponent({
}
},
setup(props) {
const online = ref(false);
const isonline = () => {
let obj = JSON.parse(decode(props.text!.replace('vmess://', '')));
let http = props.serve.istls == 0 ? 'http' : 'https'
let reg = new RegExp(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/);
let ip = obj.ps.match(reg)[0];
api.text_server(`${http}://${props.serve.ip}:${props.serve.port}/${ip}`).then(res => {
online.value = res.data.sataus == 400
})
}
const api = new getdata;
const $q = useQuasar()
const outtext = computed(() => {
let obj = JSON.parse(decode(props.text!.replace('vmess://', '')));
@ -42,9 +55,12 @@ export default defineComponent({
obj.tls = props.serve.istls == 0 ? '' : 'tls'
let reg = new RegExp(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/);
obj.path = '/' + obj.ps.match(reg)[0];
isonline()
return 'vmess://' + encode(JSON.stringify(obj))
})
const copy = () => {
// api.text_server('http://uszz.giaogiao.uk:8080/34.125.44.195').then(res => { console.log(res.data) })
copyToClipboard(outtext.value)
.then(() => {
// success!
@ -62,7 +78,7 @@ export default defineComponent({
})
})
}
return { props, outtext, copy };
return { props, outtext, copy, online };
},
});
</script>

View File

@ -3,7 +3,8 @@
<div class="row">
<div class="col-xs-1 col-md-4"></div>
<div class="col-xs-10 col-md-4">
<h6 style="text-align: center;margin: 1rem;">节点</h6>
<h6 style="text-align: center;margin: 1rem;">节点<q-icon v-show="online" title="在线" name="check_circle_outline"
style="color: green;" /> <q-icon v-show="!online" title="离线" name="hide_source" style="color: red;" /></h6>
<q-input v-model="text" filled autogrow />
</div>
</div>
@ -34,6 +35,7 @@ export default defineComponent({
const serve = ref(<server[]>[])
const api = new getdata;
const text = ref('');
const online = ref(false);
onMounted(() => {
api.get_server().then((res) => {
for (let index = 0; index < res.data.length; index++) {
@ -47,6 +49,7 @@ export default defineComponent({
if (obj.id != '2ee57806-f6e4-482a-ef08-7360c04cd3e5' || obj.net != 'ws') {
return false
}
isonline()
} catch (error) {
console.log(error);
return false
@ -54,10 +57,19 @@ export default defineComponent({
return true
})
const isonline = () => {
let obj = JSON.parse(decode(text.value!.replace('vmess://', '')));
let reg = new RegExp(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/);
let ip = obj.ps.match(reg)[0];
api.text_server(`http://${ip}:9000/`).then(res => {
online.value = res.data.sataus == 400
})
}
return {
serve,
text,
isobj
isobj,
online
};
}
});