Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Toperlock authored Nov 5, 2023
1 parent 7fb1ab5 commit 0a4757f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

app = Flask(__name__, template_folder='../templates') # 指定模板文件夹的路径
app.secret_key = 'sing-box' # 替换为实际的密钥
os.environ['TEMP_JSON_DATA'] = '{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exlude_protocol":"ssr","config_template":"","Only-nodes":false}'
os.environ['TEMP_JSON_DATA'] = '{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exclude_protocol":"ssr","config_template":"","Only-nodes":false}'

# 获取系统默认的临时目录路径
TEMP_DIR = tempfile.gettempdir()
Expand Down Expand Up @@ -214,7 +214,7 @@ def config(url):
config_file_path = os.path.join('/tmp/', CONFIG_FILE_NAME)
if not os.path.exists(config_file_path):
config_file_path = CONFIG_FILE_NAME # 使用相对于当前工作目录的路径
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exlude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exclude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
# 读取配置文件内容
with open(config_file_path, 'r', encoding='utf-8') as config_file:
config_content = config_file.read()
Expand All @@ -224,7 +224,7 @@ def config(url):
config_data = json.loads(config_content)
return Response(config_content, content_type='text/plain; charset=utf-8')
except subprocess.CalledProcessError as e:
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exlude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exclude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
return Response(json.dumps({'status': 'error', 'message_CN': '执行子进程时出错,获取链接内容超时,请尝试本地运行脚本或者把订阅链接内容放到gist; 你的订阅链接可能需要使用 越南 ip才能打开,很抱歉vercel做不到,请你把订阅链接里的node内容保存到gist里再尝试解析它。或者请你在本地运行脚本;', 'message_VN': 'Có lỗi khi thực hiện tiến trình con, vượt quá thời gian để lấy nội dung liên kết, vui lòng thử chạy kịch bản cục bộ hoặc đặt nội dung liên kết đăng ký vào Github Gist; Liên kết đăng ký của bạn có thể cần sử dụng IP Việt Nam để mở, xin lỗi Vercel không thể làm điều đó, vui lòng lưu nội dung nút trong liên kết đăng ký vào Github Gist trước khi cố gắng phân tích nó. Hoặc vui lòng chạy kịch bản cục bộ;', 'message_EN': 'Fetching the link content is timing out, please try running the script locally or putting the subscription link content into Github Gist; Your subscription link may need to use Vietnam ip to open, sorry Vercel can not do that, please save the node content in the subscription link to Github Gist before trying to parse it. Or please run the script locally;'}, indent=4,ensure_ascii=False), content_type='application/json; charset=utf-8', status=500)
#return jsonify({'status': 'error', 'message': str(e)})
except Exception as e:
Expand All @@ -249,7 +249,7 @@ def generate_config():
config_file_path = os.path.join('/tmp/', CONFIG_FILE_NAME)
if not os.path.exists(config_file_path):
config_file_path = CONFIG_FILE_NAME # 使用相对于当前工作目录的路径
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exlude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exclude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
# 读取配置文件内容
with open(config_file_path, 'r', encoding='utf-8') as config_file:
config_content = config_file.read()
Expand All @@ -259,7 +259,7 @@ def generate_config():
config_data = json.loads(config_content)
return Response(config_content, content_type='text/plain; charset=utf-8')
except subprocess.CalledProcessError as e:
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exlude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
os.environ['TEMP_JSON_DATA'] = json.dumps(json.loads('{"subscribes":[{"url":"URL LINK","tag":"tag_1","enabled":true,"emoji":1,"prefix":"","User-Agent":"clashmeta"},{"url":"URL LINK","tag":"tag_2","enabled":false,"emoji":0,"prefix":"❤️","User-Agent":"clashmeta"}],"auto_set_outbounds_dns":{"proxy":"","direct":""},"save_config_path":"./config.json","auto_backup":false,"exclude_protocol":"ssr","config_template":"","Only-nodes":false}'), indent=4, ensure_ascii=False)
return Response(json.dumps({'status': 'error', 'message_CN': '执行子进程时出错,获取链接内容超时,请尝试本地运行脚本或者把订阅链接内容放到gist; 你的订阅链接可能需要使用 越南 ip才能打开,很抱歉vercel做不到,请你把订阅链接里的node内容保存到gist里再尝试解析它。或者请你在本地运行脚本;', 'message_VN': 'Có lỗi khi thực hiện tiến trình con, vượt quá thời gian để lấy nội dung liên kết, vui lòng thử chạy kịch bản cục bộ hoặc đặt nội dung liên kết đăng ký vào Github Gist; Liên kết đăng ký của bạn có thể cần sử dụng IP Việt Nam để mở, xin lỗi Vercel không thể làm điều đó, vui lòng lưu nội dung nút trong liên kết đăng ký vào Github Gist trước khi cố gắng phân tích nó. Hoặc vui lòng chạy kịch bản cục bộ;', 'message_EN': 'Fetching the link content is timing out, please try running the script locally or putting the subscription link content into Github Gist; Your subscription link may need to use Vietnam ip to open, sorry Vercel can not do that, please save the node content in the subscription link to Github Gist before trying to parse it. Or please run the script locally;'}, indent=4,ensure_ascii=False), content_type='application/json; charset=utf-8', status=500)
except Exception as e:
#flash(f'Error occurred while generating the configuration file: {str(e)}', 'error')
Expand Down

0 comments on commit 0a4757f

Please sign in to comment.