File size: 1,557 Bytes
4117d38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134508d
4117d38
 
 
1279d0f
 
 
 
 
 
 
 
 
 
 
4117d38
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from server.decoder import decode_url_to_configs
from server.utils import config,headers
import random
from fastapi import APIRouter,BackgroundTasks
from randomSubscribeUrl import subscription_link_list,getRandomSubscribeUrl,delete_invalid_url_in_txt


router = APIRouter()
@router.get('/')
def getNode(background_tasks: BackgroundTasks)->str:
    # 返回一个可用的订阅链接信息
    SubscribeUrlList = subscription_link_list(router.fileName)
    # 直接用现成的认为可用然后直接返回,之后再删不可用的
    randomSubscribeUrl= getRandomSubscribeUrl(SubscribeUrlList)
    NodeList = dump_configs(randomSubscribeUrl)
    NodeStr = RandomNode(NodeList)

    #background_tasks.add_task(delete_invalid_url_in_txt, router.fileName)
    return NodeStr

def RandomNode(NodeList:list)->str:
    #返回一个节点信息(优先trojan和vmess,因为ss存活辣鸡)
    # 检查列表中是否存在以'trojan'或'vmess'开头的项
    trojan_vmess_nodes = [node for node in NodeList if node.startswith('trojan') or node.startswith('vmess')]
    
    # 如果存在以'trojan'或'vmess'开头的项,则从这些项中随机选择一个返回
    if trojan_vmess_nodes:
        return random.choice(trojan_vmess_nodes)
    else:
        # 否则从整个列表中随机选择一个返回
        return random.choice(NodeList)



def dump_configs(url:str)->list:
    #返回全部节点信息的列表
    configs = decode_url_to_configs(url)
    return configs