mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-03 15:08:40 +00:00
web: add files resource to the web server
Add a files resource that allows Ext to fetch the file tree via one of it's ajax proxies.
This commit is contained in:
parent
39d19b5afd
commit
c46bc049d1
1 changed files with 59 additions and 0 deletions
|
@ -87,6 +87,7 @@ CONFIG_DEFAULTS = {
|
||||||
"cert": "ssl/daemon.cert"
|
"cert": "ssl/daemon.cert"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILES_KEYS = ["files", "file_progress", "file_priorities"]
|
||||||
PEERS_KEYS = ["peers"]
|
PEERS_KEYS = ["peers"]
|
||||||
|
|
||||||
UI_CONFIG_KEYS = (
|
UI_CONFIG_KEYS = (
|
||||||
|
@ -216,6 +217,60 @@ class TorrentResource(resource.Resource):
|
||||||
request.write(compress(json.dumps(response), request))
|
request.write(compress(json.dumps(response), request))
|
||||||
request.finish()
|
request.finish()
|
||||||
|
|
||||||
|
class Files(TorrentResource):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
|
||||||
|
def on_got_files(self, torrent, request):
|
||||||
|
files = torrent.get("files")
|
||||||
|
file_progress = torrent.get("file_progress")
|
||||||
|
file_priorities = torrent.get("file_priorities")
|
||||||
|
|
||||||
|
paths = []
|
||||||
|
info = {}
|
||||||
|
|
||||||
|
for i, torrent_file in enumerate(files):
|
||||||
|
path = torrent_file["path"]
|
||||||
|
paths.append(path)
|
||||||
|
torrent_file["progress"] = file_progress[i]
|
||||||
|
torrent_file["priority"] = file_priorities[i]
|
||||||
|
torrent_file["index"] = i
|
||||||
|
torrent_file["path"] = path
|
||||||
|
info[path] = torrent_file
|
||||||
|
|
||||||
|
# Update the directory info
|
||||||
|
dirname = os.path.dirname(path)
|
||||||
|
while dirname:
|
||||||
|
dirinfo = info.setdefault(dirname, {})
|
||||||
|
dirinfo["size"] = dirinfo.get("size", 0) + torrent_file["size"]
|
||||||
|
if "priority" not in dirinfo:
|
||||||
|
dirinfo["priority"] = torrent_file["priority"]
|
||||||
|
else:
|
||||||
|
if dirinfo["priority"] != torrent_file["priority"]:
|
||||||
|
dirinfo["priority"] = 9
|
||||||
|
|
||||||
|
progresses = dirinfo.setdefault("progresses", [])
|
||||||
|
progresses.append(torrent_file["size"] * (torrent_file["progress"] / 100.0))
|
||||||
|
dirinfo["progress"] = float(sum(progresses)) / dirinfo["size"] * 100
|
||||||
|
dirinfo["path"] = dirname
|
||||||
|
dirname = os.path.dirname(dirname)
|
||||||
|
|
||||||
|
tree = uicommon.ExtFileTree(paths)
|
||||||
|
for path, item in tree.walk():
|
||||||
|
item.update(info[path])
|
||||||
|
self.send_response(tree.get_tree(), request)
|
||||||
|
|
||||||
|
@secure
|
||||||
|
def render(self, request):
|
||||||
|
if not hasattr(request, 'torrent_id'):
|
||||||
|
request.setResponseCode(http.NOT_FOUND)
|
||||||
|
return '<h1>Not Found</h1>'
|
||||||
|
|
||||||
|
component.get("SessionProxy"
|
||||||
|
).get_torrent_status(request.torrent_id, FILES_KEYS
|
||||||
|
).addCallback(self.on_got_files, request)
|
||||||
|
return server.NOT_DONE_YET
|
||||||
|
|
||||||
class Peers(TorrentResource):
|
class Peers(TorrentResource):
|
||||||
"""
|
"""
|
||||||
Returns a list of the peers that a torrent currently has in JSON format.
|
Returns a list of the peers that a torrent currently has in JSON format.
|
||||||
|
@ -230,6 +285,9 @@ class Peers(TorrentResource):
|
||||||
|
|
||||||
@secure
|
@secure
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
|
if not hasattr(request, 'torrent_id'):
|
||||||
|
request.setResponseCode(http.NOT_FOUND)
|
||||||
|
return '<h1>Not Found</h1>'
|
||||||
component.get("SessionProxy"
|
component.get("SessionProxy"
|
||||||
).get_torrent_status(request.torrent_id, PEERS_KEYS
|
).get_torrent_status(request.torrent_id, PEERS_KEYS
|
||||||
).addCallback(self.on_got_peers, request)
|
).addCallback(self.on_got_peers, request)
|
||||||
|
@ -504,6 +562,7 @@ class TopLevel(resource.Resource):
|
||||||
self.putChild("tracker", Tracker())
|
self.putChild("tracker", Tracker())
|
||||||
|
|
||||||
# Torrent REST resources
|
# Torrent REST resources
|
||||||
|
self.putChild("files", Files())
|
||||||
self.putChild("peers", Peers())
|
self.putChild("peers", Peers())
|
||||||
|
|
||||||
theme = component.get("DelugeWeb").config["theme"]
|
theme = component.get("DelugeWeb").config["theme"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue