精简接口
This commit is contained in:
parent
fdd809fdc2
commit
0f71209fe8
26
Common.py
26
Common.py
@ -384,3 +384,29 @@ def encodeVideo(name):
|
|||||||
return False
|
return False
|
||||||
Common.modifyLastEncodeStatus("Encode >{}< Finished".format(name))
|
Common.modifyLastEncodeStatus("Encode >{}< Finished".format(name))
|
||||||
uploadQueue.put(_new_name)
|
uploadQueue.put(_new_name)
|
||||||
|
|
||||||
|
|
||||||
|
def collectInfomation():
|
||||||
|
return {
|
||||||
|
"download": downloadStatus,
|
||||||
|
"encode": encodeStatus,
|
||||||
|
"encodeQueueSize": encodeQueue.qsize(),
|
||||||
|
"upload": uploadStatus,
|
||||||
|
"uploadQueueSize": uploadQueue.qsize(),
|
||||||
|
"error": errors,
|
||||||
|
"operation": operations,
|
||||||
|
"broadcast": {
|
||||||
|
"broadcaster": broadcaster.__str__(),
|
||||||
|
"isBroadcasting": isBroadcasting,
|
||||||
|
"streamUrl": streamUrl,
|
||||||
|
"updateTime": updateTime,
|
||||||
|
"delayTime": delay.strftime(dt_format)
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"forceNotBroadcasting": forceNotBroadcasting,
|
||||||
|
"forceNotDownload": forceNotDownload,
|
||||||
|
"forceNotUpload": forceNotUpload,
|
||||||
|
"forceNotEncode": forceNotEncode,
|
||||||
|
"downloadOnly": config['dlO'],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
100
WebMain.py
100
WebMain.py
@ -30,14 +30,14 @@ def writeConfig():
|
|||||||
# TODO : 完善
|
# TODO : 完善
|
||||||
Common.appendOperation("更新配置")
|
Common.appendOperation("更新配置")
|
||||||
Common.reloadConfig()
|
Common.reloadConfig()
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":request.form})
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": request.form})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/force/not/upload", methods=["POST"])
|
@app.route("/force/not/upload", methods=["POST"])
|
||||||
def toggleForceNotUpload():
|
def toggleForceNotUpload():
|
||||||
Common.forceNotUpload = not Common.forceNotUpload
|
Common.forceNotUpload = not Common.forceNotUpload
|
||||||
Common.appendOperation("将强制不上传的值改为:{}".format(Common.forceNotUpload))
|
Common.appendOperation("将强制不上传的值改为:{}".format(Common.forceNotUpload))
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
"forceNotUpload": Common.forceNotUpload,
|
"forceNotUpload": Common.forceNotUpload,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ def toggleForceNotUpload():
|
|||||||
def toggleForceNotEncode():
|
def toggleForceNotEncode():
|
||||||
Common.forceNotEncode = not Common.forceNotEncode
|
Common.forceNotEncode = not Common.forceNotEncode
|
||||||
Common.appendOperation("将强制不编码的值改为:{}".format(Common.forceNotEncode))
|
Common.appendOperation("将强制不编码的值改为:{}".format(Common.forceNotEncode))
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
"forceNotEncode": Common.forceNotEncode,
|
"forceNotEncode": Common.forceNotEncode,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ def toggleForceNotEncode():
|
|||||||
def toggleForceNotDownload():
|
def toggleForceNotDownload():
|
||||||
Common.forceNotDownload = not Common.forceNotDownload
|
Common.forceNotDownload = not Common.forceNotDownload
|
||||||
Common.appendOperation("将强制不下载的值改为:{}".format(Common.forceNotDownload))
|
Common.appendOperation("将强制不下载的值改为:{}".format(Common.forceNotDownload))
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
"forceNotDownload": Common.forceNotDownload,
|
"forceNotDownload": Common.forceNotDownload,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ def toggleForceNotDownload():
|
|||||||
@app.route("/force/not/broadcast", methods=["POST"])
|
@app.route("/force/not/broadcast", methods=["POST"])
|
||||||
def toggleForceNotBroadcast():
|
def toggleForceNotBroadcast():
|
||||||
Common.forceNotBroadcasting = not Common.forceNotBroadcasting
|
Common.forceNotBroadcasting = not Common.forceNotBroadcasting
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ def toggleForceNotBroadcast():
|
|||||||
def toggleForceStartEncodeThread():
|
def toggleForceStartEncodeThread():
|
||||||
Common.forceStartEncodeThread = True
|
Common.forceStartEncodeThread = True
|
||||||
Common.appendOperation("强制运行编码线程")
|
Common.appendOperation("强制运行编码线程")
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ def toggleForceStartEncodeThread():
|
|||||||
def toggleForceStartUploadThread():
|
def toggleForceStartUploadThread():
|
||||||
Common.forceStartUploadThread = True
|
Common.forceStartUploadThread = True
|
||||||
Common.appendOperation("强制运行上传线程")
|
Common.appendOperation("强制运行上传线程")
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ def toggleForceStartUploadThread():
|
|||||||
def startForceCleanDisk():
|
def startForceCleanDisk():
|
||||||
Common.doClean(True)
|
Common.doClean(True)
|
||||||
Common.appendOperation("强制执行清理程序")
|
Common.appendOperation("强制执行清理程序")
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
||||||
@ -97,9 +97,9 @@ def insertEncode():
|
|||||||
if "filename" in request.form and os.path.exists(request.form["filename"]):
|
if "filename" in request.form and os.path.exists(request.form["filename"]):
|
||||||
Common.appendOperation("添加编码文件:{}".format(request.form["filename"]))
|
Common.appendOperation("添加编码文件:{}".format(request.form["filename"]))
|
||||||
Common.encodeQueue.put(request.form["filename"])
|
Common.encodeQueue.put(request.form["filename"])
|
||||||
return jsonify({"message":"ok","code":200,"status":0})
|
return jsonify({"message": "ok", "code": 200, "status": 0})
|
||||||
else:
|
else:
|
||||||
return jsonify({"message":"no filename specific","code":400,"status":1})
|
return jsonify({"message": "no filename specific", "code": 400, "status": 1})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/upload/insert", methods=["POST"])
|
@app.route("/upload/insert", methods=["POST"])
|
||||||
@ -107,68 +107,33 @@ def insertUpload():
|
|||||||
if "filename" in request.form and os.path.exists(request.form["filename"]):
|
if "filename" in request.form and os.path.exists(request.form["filename"]):
|
||||||
Common.appendOperation("添加上传文件:{}".format(request.form["filename"]))
|
Common.appendOperation("添加上传文件:{}".format(request.form["filename"]))
|
||||||
Common.uploadQueue.put(request.form["filename"])
|
Common.uploadQueue.put(request.form["filename"])
|
||||||
return jsonify({"message":"ok","code":200,"status":0})
|
return jsonify({"message": "ok", "code": 200, "status": 0})
|
||||||
else:
|
else:
|
||||||
return jsonify({"message":"no filename specific","code":400,"status":1})
|
return jsonify({"message": "no filename specific", "code": 400, "status": 1})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/upload/finish", methods=["POST"])
|
@app.route("/upload/finish", methods=["POST"])
|
||||||
def finishUpload():
|
def finishUpload():
|
||||||
Common.appendOperation("设置当前已完成上传")
|
Common.appendOperation("设置当前已完成上传")
|
||||||
Common.uploadQueue.put(True)
|
Common.uploadQueue.put(True)
|
||||||
return jsonify({"message":"ok","code":200,"status":0})
|
return jsonify({"message": "ok", "code": 200, "status": 0})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/stats", methods=["GET"])
|
@app.route("/stats", methods=["GET"])
|
||||||
def getAllStats():
|
def getAllStats():
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": Common.collectInfomation()})
|
||||||
"download":Common.downloadStatus,
|
|
||||||
"encode": Common.encodeStatus,
|
|
||||||
"encodeQueueSize": Common.encodeQueue.qsize(),
|
|
||||||
"upload": Common.uploadStatus,
|
|
||||||
"uploadQueueSize": Common.uploadQueue.qsize(),
|
|
||||||
"error": Common.errors,
|
|
||||||
"operation": Common.operations,
|
|
||||||
"broadcast": {
|
|
||||||
"broadcaster": Common.broadcaster.__str__(),
|
|
||||||
"isBroadcasting": Common.isBroadcasting,
|
|
||||||
"streamUrl": Common.streamUrl,
|
|
||||||
"updateTime": Common.updateTime,
|
|
||||||
"delayTime": Common.delay
|
|
||||||
},
|
|
||||||
"config": {
|
|
||||||
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
|
||||||
"forceNotDownload": Common.forceNotDownload,
|
|
||||||
"forceNotUpload": Common.forceNotUpload,
|
|
||||||
"forceNotEncode": Common.forceNotEncode,
|
|
||||||
"downloadOnly": Common.config['dlO'],
|
|
||||||
},
|
|
||||||
}})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/stats/device", methods=["GET"])
|
@app.route("/stats/device", methods=["GET"])
|
||||||
def getDeviceStatus():
|
def getDeviceStatus():
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
"status": Common.getCurrentStatus(),
|
"status": Common.getCurrentStatus(),
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/stats/broadcast", methods=["GET"])
|
|
||||||
def getBroadcastStats():
|
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
|
||||||
"broadcast": {
|
|
||||||
"broadcaster": Common.broadcaster.__str__(),
|
|
||||||
"isBroadcasting": Common.isBroadcasting,
|
|
||||||
"streamUrl": Common.streamUrl,
|
|
||||||
"updateTime": Common.updateTime,
|
|
||||||
"delayTime": Common.delay
|
|
||||||
}
|
|
||||||
}})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/stats/config", methods=["GET"])
|
@app.route("/stats/config", methods=["GET"])
|
||||||
def getConfigStats():
|
def getConfigStats():
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {
|
||||||
"config": {
|
"config": {
|
||||||
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
"forceNotBroadcasting": Common.forceNotBroadcasting,
|
||||||
"forceNotDownload": Common.forceNotDownload,
|
"forceNotDownload": Common.forceNotDownload,
|
||||||
@ -179,33 +144,10 @@ def getConfigStats():
|
|||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/stats/download", methods=["GET"])
|
|
||||||
def getDownloadStats():
|
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
|
||||||
"download":Common.downloadStatus,
|
|
||||||
}})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/stats/encode", methods=["GET"])
|
|
||||||
def getEncodeStats():
|
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
|
||||||
"encode": Common.encodeStatus,
|
|
||||||
"encodeQueueSize": Common.encodeQueue.qsize(),
|
|
||||||
}})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/stats/upload", methods=["GET"])
|
|
||||||
def getUploadStats():
|
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{
|
|
||||||
"upload": Common.uploadStatus,
|
|
||||||
"uploadQueueSize": Common.uploadQueue.qsize(),
|
|
||||||
}})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/account/reLogin", methods=["POST"])
|
@app.route("/account/reLogin", methods=["POST"])
|
||||||
def accountRelogin():
|
def accountRelogin():
|
||||||
res = Common.loginBilibili(True)
|
res = Common.loginBilibili(True)
|
||||||
return jsonify({"message":"ok","code":200,"status":0,"data":{"result":res}})
|
return jsonify({"message": "ok", "code": 200, "status": 0, "data": {"result": res}})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/files/", methods=["GET"])
|
@app.route("/files/", methods=["GET"])
|
||||||
@ -216,7 +158,7 @@ def fileIndex():
|
|||||||
"name": i,
|
"name": i,
|
||||||
"size": Common.parseSize(os.path.getsize(i))
|
"size": Common.parseSize(os.path.getsize(i))
|
||||||
})
|
})
|
||||||
return render_template("files.html",files=a)
|
return render_template("files.html", files=a)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/files/download/<path>", methods=["GET"])
|
@app.route("/files/download/<path>", methods=["GET"])
|
||||||
@ -226,9 +168,10 @@ def fileDownload(path):
|
|||||||
f.seek(offset)
|
f.seek(offset)
|
||||||
for row in f:
|
for row in f:
|
||||||
yield row
|
yield row
|
||||||
|
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
if "RANGE" in request.headers:
|
if "RANGE" in request.headers:
|
||||||
offset = int(request.headers["RANGE"].replace("=","-").split("-")[1].strip())
|
offset = int(request.headers["RANGE"].replace("=", "-").split("-")[1].strip())
|
||||||
code = 206
|
code = 206
|
||||||
else:
|
else:
|
||||||
offset = 0
|
offset = 0
|
||||||
@ -238,7 +181,8 @@ def fileDownload(path):
|
|||||||
mimetype='application/octet-stream',
|
mimetype='application/octet-stream',
|
||||||
headers={
|
headers={
|
||||||
"Content-Length": os.path.getsize(path),
|
"Content-Length": os.path.getsize(path),
|
||||||
"Content-Range": "bytes {}-{}/{}".format(offset,os.path.getsize(path)-1,os.path.getsize(path)),
|
"Content-Range": "bytes {}-{}/{}".format(offset, os.path.getsize(path) - 1,
|
||||||
|
os.path.getsize(path)),
|
||||||
"Accept-Ranges": "bytes",
|
"Accept-Ranges": "bytes",
|
||||||
"Range": "bytes",
|
"Range": "bytes",
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user