Browse Source

Add: Default route for index.

pull/2/head
Q01 4 years ago committed by GitHub
parent
commit
88aaef4832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      app.py

28
app.py

@ -1,9 +1,7 @@
#/usr/bin/env python3 #/usr/bin/env python3
import os, sys, zipfile import os, sys, zipfile
from flask import Flask from flask import Flask, request, send_file, redirect, url_for
from flask import request
from flask import send_file
import os.path import os.path
app = Flask(__name__) app = Flask(__name__)
@ -102,34 +100,44 @@ def GenerateLicense(Type : LicenseType, Count : int, UserName : str, MajorVersio
return FileName return FileName
@app.route('/gen') #@app.route('/gen')
def get_lc(): def get_lc():
name = request.args.get('name', '') name = request.args.get('name', '')
version = request.args.get('ver', '') version = request.args.get('ver', '')
count = int(request.args.get('count', '1')) count = int(request.args.get('count', '1'))
try:
MajorVersion, MinorVersion = version.split('.')[0:2] MajorVersion, MinorVersion = version.split('.')[0:2]
except:
return
MajorVersion = int(MajorVersion) MajorVersion = int(MajorVersion)
MinorVersion = int(MinorVersion) MinorVersion = int(MinorVersion)
lc = GenerateLicense(LicenseType.Professional, count, name, MajorVersion, MinorVersion) lc = GenerateLicense(LicenseType.Professional, count, name, MajorVersion, MinorVersion)
return lc return lc
@app.route('/download/<lc>') #@app.route('/download/<lc>')
def download_lc(lc): def download_lc(lc):
if lc and len(lc) > 5 and os.path.exists('./' + lc): if lc and len(lc) > 5 and os.path.exists('./' + lc):
return send_file(lc, return send_file(lc,
as_attachment=True, as_attachment=True,
attachment_filename='Custom.mxtpro') attachment_filename='Custom.mxtpro')
else: else:
return "确保生成成功后再来下载!检查用户名版本号是否正确!" return "请检查用户名版本号是否正确!"
@app.route('/') @app.route('/gen')
def get(): def get():
lc = get_lc() lc = get_lc()
return download_lc(lc) return download_lc(lc)
@app.route('/')
def index():
return send_file('index.html')
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True) app.run(host='0.0.0.0', port=5000, debug=False)

Loading…
Cancel
Save