import
os
from
flask
import
Flask, request, render_template, jsonify
app
=
Flask(__name__)
config_path
=
os.path.abspath(
"URL_config.ini"
)
def
read_config():
if
not
os.path.exists(config_path):
with
open
(config_path,
'w'
) as f:
pass
with
open
(config_path,
'r'
, encoding
=
'utf-8'
) as f:
return
f.read()
def
save_config(content):
with
open
(config_path,
'w'
, encoding
=
'utf-8'
) as f:
f.write(content)
@app
.route(
'/'
)
def
index():
return
render_template(
'index.html'
)
@app
.route(
'/api/config'
, methods
=
[
'GET'
,
'POST'
])
def
config_api():
if
request.method
=
=
'GET'
:
return
jsonify({
"code"
:
0
,
"data"
: read_config()
})
elif
request.method
=
=
'POST'
:
content
=
request.json.get(
'content'
, '')
save_config(content.strip())
return
jsonify({
"code"
:
0
,
"msg"
:
"保存成功"
})
if
__name__
=
=
'__main__'
:
app.run(host
=
'0.0.0.0'
, port
=
5000
, debug
=
True
)