断点续传
This commit is contained in:
parent
035e71185a
commit
a9ecd1e7ab
13
Common.py
13
Common.py
@ -42,15 +42,20 @@ def getTimeDelta(a, b):
|
||||
return sec+(ms/100000.0)
|
||||
|
||||
|
||||
def getCurrentStatus():
|
||||
def doClean():
|
||||
global _do_move_time
|
||||
_disk = psutil.disk_usage("/")
|
||||
if _disk.percent > config["max"] and getTimeDelta(datetime.now(), _do_move_time) > 3600:
|
||||
_do_move_time = datetime.now()
|
||||
os.system(config["dow"])
|
||||
|
||||
|
||||
|
||||
def getCurrentStatus():
|
||||
_disk = psutil.disk_usage("/")
|
||||
_mem = psutil.virtual_memory()
|
||||
_net = psutil.net_io_counters()
|
||||
_delta= getTimeDelta(datetime.now(),network["currentTime"])
|
||||
if _disk.percent > config["max"] and getTimeDelta(datetime.now(), _do_move_time) > 3600:
|
||||
_do_move_time = datetime.now()
|
||||
os.system(config["dow"])
|
||||
if 60 > _delta > 0:
|
||||
_inSpeed = (_net.bytes_recv - network["in"]["currentByte"])/_delta
|
||||
_outSpeed = (_net.bytes_sent - network["out"]["currentByte"])/_delta
|
||||
|
31
WebMain.py
31
WebMain.py
@ -7,7 +7,7 @@ import Common
|
||||
import threading
|
||||
from liveDownloader import run as RUN
|
||||
|
||||
app = Flask("liveStatus")
|
||||
app = Flask(__name__)
|
||||
app.config['JSON_AS_ASCII'] = False
|
||||
CORS(app, supports_credentials=True)
|
||||
# url_for('static', filename='index.html')
|
||||
@ -187,12 +187,28 @@ def fileIndex():
|
||||
|
||||
@app.route("/files/download/<path>", methods=["GET"])
|
||||
def fileDownload(path):
|
||||
def generate(file):
|
||||
def generate(file, offset=0):
|
||||
with open(file, "rb") as f:
|
||||
f.seek(offset)
|
||||
for row in f:
|
||||
yield row
|
||||
if os.path.exists(path):
|
||||
return Response(generate(path), mimetype='application/octet-stream')
|
||||
if "RANGE" in request.headers:
|
||||
offset = int(request.headers["RANGE"].replace("=","-").split("-")[1].strip())
|
||||
code = 206
|
||||
else:
|
||||
offset = 0
|
||||
code = 200
|
||||
return Response(generate(path, offset),
|
||||
status=code,
|
||||
mimetype='application/octet-stream',
|
||||
headers={
|
||||
"Content-Length": os.path.getsize(path)-1-offset,
|
||||
"Content-Range": "bytes {}-{}/{}".format(offset,os.path.getsize(path)-1,os.path.getsize(path)),
|
||||
"Accept-Ranges": "bytes",
|
||||
"Range": "bytes",
|
||||
"Content-Disposition": "attachment; filename={}".format(path),
|
||||
})
|
||||
else:
|
||||
return Response(status=404)
|
||||
|
||||
@ -210,6 +226,9 @@ def SubThread():
|
||||
t.start()
|
||||
|
||||
|
||||
p = threading.Thread(target=SubThread)
|
||||
p.setDaemon(True)
|
||||
p.start()
|
||||
# p = threading.Thread(target=SubThread)
|
||||
# p.setDaemon(True)
|
||||
# p.start()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
Reference in New Issue
Block a user