support add sat by url

This commit is contained in:
Silent YANG 2024-11-19 19:50:04 +08:00
parent 38c134f2c0
commit 42d5125ec3

View file

@ -500,7 +500,20 @@ const writeIt = async () => {
setLoading(false)
}
const addSelfSat = () => {
const isValidURL = (url: string) => {
const pattern = new RegExp('^(https?:\\/\\/)?' + // (http https)
'((([a-zA-Z\\d]([a-zA-Z\\d-]*[a-zA-Z\\d])*)\\.)+[a-zA-Z]{2,}|' + //
'((\\d{1,3}\\.){3}\\d{1,3}))' + // IP (IPv4)
'(\\:\\d+)?(\\/[-a-zA-Z\\d%_.~+]*)*' + //
'(\\?[;&a-zA-Z\\d%_.~+=-]*)?' + //
'(\\#[-a-zA-Z\\d_]*)?$', 'i'); //
return !!pattern.test(url);
}
const addSelfSat = async () => {
if(isValidURL(state.selfSatInfo)){
state.selfSatInfo = await (await fetch(state.selfSatInfo)).text()
}
const lines = (state.selfSatInfo + "\n").split(/\r?\n/);
const sat = [];
let _sat: any = {};