|
|
@ -263,20 +263,29 @@ def reboot(): |
|
|
|
|
|
|
|
|
|
|
|
@dispatcher.add_method |
|
|
|
@dispatcher.add_method |
|
|
|
def uploadFileToUrl(fn, url, headers): |
|
|
|
def uploadFileToUrl(fn, url, headers): |
|
|
|
if len(fn) == 0 or fn[0] == '/' or '..' in fn: |
|
|
|
return uploadFilesToUrls([[fn, url, headers]]) |
|
|
|
return 500 |
|
|
|
|
|
|
|
path = os.path.join(ROOT, fn) |
|
|
|
|
|
|
|
if not os.path.exists(path): |
|
|
|
|
|
|
|
return 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item = UploadItem(path=path, url=url, headers=headers, created_at=int(time.time() * 1000), id=None) |
|
|
|
@dispatcher.add_method |
|
|
|
upload_id = hashlib.sha1(str(item).encode()).hexdigest() |
|
|
|
def uploadFilesToUrls(files_data): |
|
|
|
item = item._replace(id=upload_id) |
|
|
|
items = [] |
|
|
|
|
|
|
|
for fn, url, headers in files_data: |
|
|
|
|
|
|
|
if len(fn) == 0 or fn[0] == '/' or '..' in fn: |
|
|
|
|
|
|
|
return 500 |
|
|
|
|
|
|
|
path = os.path.join(ROOT, fn) |
|
|
|
|
|
|
|
if not os.path.exists(path): |
|
|
|
|
|
|
|
return 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item = UploadItem(path=path, url=url, headers=headers, created_at=int(time.time() * 1000), id=None) |
|
|
|
|
|
|
|
upload_id = hashlib.sha1(str(item).encode()).hexdigest() |
|
|
|
|
|
|
|
items.append(item._replace(id=upload_id)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for item in items: |
|
|
|
|
|
|
|
upload_queue.put_nowait(item) |
|
|
|
|
|
|
|
|
|
|
|
upload_queue.put_nowait(item) |
|
|
|
|
|
|
|
UploadQueueCache.cache(upload_queue) |
|
|
|
UploadQueueCache.cache(upload_queue) |
|
|
|
|
|
|
|
|
|
|
|
return {"enqueued": 1, "item": item._asdict()} |
|
|
|
return {"enqueued": len(items), "items": [i._asdict() for i in items]} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dispatcher.add_method |
|
|
|
@dispatcher.add_method |
|
|
@ -287,11 +296,15 @@ def listUploadQueue(): |
|
|
|
|
|
|
|
|
|
|
|
@dispatcher.add_method |
|
|
|
@dispatcher.add_method |
|
|
|
def cancelUpload(upload_id): |
|
|
|
def cancelUpload(upload_id): |
|
|
|
upload_ids = {item.id for item in list(upload_queue.queue)} |
|
|
|
if not isinstance(upload_id, list): |
|
|
|
if upload_id not in upload_ids: |
|
|
|
upload_id = [upload_id] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uploading_ids = {item.id for item in list(upload_queue.queue)} |
|
|
|
|
|
|
|
cancelled_ids = uploading_ids.intersection(upload_id) |
|
|
|
|
|
|
|
if len(cancelled_ids) == 0: |
|
|
|
return 404 |
|
|
|
return 404 |
|
|
|
|
|
|
|
|
|
|
|
cancelled_uploads.add(upload_id) |
|
|
|
cancelled_uploads.update(cancelled_ids) |
|
|
|
return {"success": 1} |
|
|
|
return {"success": 1} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|