Skip to content

Commit

Permalink
添加服务端
Browse files Browse the repository at this point in the history
  • Loading branch information
yitong-ovo committed Dec 27, 2019
1 parent b806c00 commit acbbcc6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mtdl-api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask import Flask, render_template, Response, request, jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)
download_list = {}

@app.route('/', methods=['GET'])
def index():
return render_template('index.html')

@app.route('/<secret>/getDownload.xml', methods=['GET'])
def make_download_xml(secret):
if secret not in download_list:
download_list[secret] = []

xml_template = render_template('download.xml', data=download_list[secret])
xml_template = app.make_response(xml_template)
xml_template.headers['Content-Type'] = 'text/xml'
return xml_template

@app.route('/<secret>/addDownload', methods=['POST'])
def addDownload(secret):
if secret not in download_list:
download_list[secret] = []

_title = request.get_json()['title']
_url = request.get_json()['url']

download_list[secret].append({'title': _title , 'download': _url})

return jsonify({'status':0})

if __name__ == '__main__':
app.run(host='0.0.0.0')

0 comments on commit acbbcc6

Please sign in to comment.