mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 04:24:27 +00:00
[WebUI|Py3] Fix and refactor torrent upload
This commit is contained in:
parent
4a335eeb61
commit
86de5657ff
@ -111,27 +111,30 @@ class Upload(resource.Resource):
|
|||||||
# Block all other HTTP methods.
|
# Block all other HTTP methods.
|
||||||
if request.method != b'POST':
|
if request.method != b'POST':
|
||||||
request.setResponseCode(http.NOT_ALLOWED)
|
request.setResponseCode(http.NOT_ALLOWED)
|
||||||
return ''
|
request.finish()
|
||||||
|
return server.NOT_DONE_YET
|
||||||
print(request.args)
|
|
||||||
if b'file' not in request.args:
|
|
||||||
request.setResponseCode(http.OK)
|
|
||||||
return json.dumps({'success': True, 'files': []})
|
|
||||||
|
|
||||||
tempdir = tempfile.mkdtemp(prefix='delugeweb-')
|
|
||||||
log.debug('uploading files to %s', tempdir)
|
|
||||||
|
|
||||||
|
files = request.args.get(b'file', [])
|
||||||
filenames = []
|
filenames = []
|
||||||
for upload in request.args.get('file'):
|
|
||||||
fd, fn = tempfile.mkstemp('.torrent', dir=tempdir)
|
if files:
|
||||||
os.write(fd, upload)
|
tempdir = tempfile.mkdtemp(prefix='delugeweb-')
|
||||||
os.close(fd)
|
log.debug('uploading files to %s', tempdir)
|
||||||
filenames.append(fn)
|
|
||||||
log.debug('uploaded %d file(s)', len(filenames))
|
for upload in files:
|
||||||
|
fd, fn = tempfile.mkstemp('.torrent', dir=tempdir)
|
||||||
|
os.write(fd, upload)
|
||||||
|
os.close(fd)
|
||||||
|
filenames.append(fn)
|
||||||
|
|
||||||
|
log.debug('uploaded %d file(s)', len(filenames))
|
||||||
|
|
||||||
request.setHeader(b'content-type', b'text/html')
|
request.setHeader(b'content-type', b'text/html')
|
||||||
request.setResponseCode(http.OK)
|
request.setResponseCode(http.OK)
|
||||||
return compress(json.dumps({'success': True, 'files': filenames}), request)
|
return compress(
|
||||||
|
json.dumps({'success': bool(filenames), 'files': filenames}).encode('utf8'),
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Render(resource.Resource):
|
class Render(resource.Resource):
|
||||||
@ -542,7 +545,7 @@ class TopLevel(resource.Resource):
|
|||||||
|
|
||||||
def getChildWithDefault(self, path, request): # NOQA: N802
|
def getChildWithDefault(self, path, request): # NOQA: N802
|
||||||
# Calculate the request base
|
# Calculate the request base
|
||||||
header = request.getHeader('x-deluge-base')
|
header = request.getHeader(b'x-deluge-base')
|
||||||
base = header if header else component.get('DelugeWeb').base
|
base = header if header else component.get('DelugeWeb').base
|
||||||
|
|
||||||
# validate the base parameter
|
# validate the base parameter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user