2015-11-12 23:16:28 +00:00
|
|
|
import simplejson
|
|
|
|
|
2016-01-27 06:49:23 +00:00
|
|
|
from twisted.web.server import UnsupportedMethod
|
|
|
|
|
2016-02-09 15:30:06 +00:00
|
|
|
from nevow import rend
|
2015-11-12 23:16:28 +00:00
|
|
|
from nevow.inevow import IRequest
|
|
|
|
|
2016-05-23 20:48:07 +00:00
|
|
|
from allmydata.web.common import WebError, TokenOnlyWebApi
|
2015-11-12 23:16:28 +00:00
|
|
|
|
|
|
|
|
2016-05-23 20:48:07 +00:00
|
|
|
class MagicFolderWebApi(TokenOnlyWebApi):
|
2015-11-12 23:16:28 +00:00
|
|
|
"""
|
|
|
|
I provide the web-based API for Magic Folder status etc.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, client):
|
2016-05-23 20:48:07 +00:00
|
|
|
TokenOnlyWebApi.__init__(self, client)
|
2015-11-12 23:16:28 +00:00
|
|
|
self.client = client
|
|
|
|
|
2016-05-23 20:48:07 +00:00
|
|
|
def post_json(self, req):
|
2015-11-12 23:16:28 +00:00
|
|
|
req.setHeader("content-type", "application/json")
|
|
|
|
|
|
|
|
data = []
|
|
|
|
for item in self.client._magic_folder.uploader.get_status():
|
|
|
|
d = dict(
|
|
|
|
path=item.relpath_u,
|
|
|
|
status=item.status_history()[-1][0],
|
|
|
|
kind='upload',
|
|
|
|
)
|
|
|
|
for (status, ts) in item.status_history():
|
|
|
|
d[status + '_at'] = ts
|
|
|
|
d['percent_done'] = item.progress.progress
|
|
|
|
data.append(d)
|
|
|
|
|
|
|
|
for item in self.client._magic_folder.downloader.get_status():
|
|
|
|
d = dict(
|
|
|
|
path=item.relpath_u,
|
|
|
|
status=item.status_history()[-1][0],
|
|
|
|
kind='download',
|
|
|
|
)
|
|
|
|
for (status, ts) in item.status_history():
|
|
|
|
d[status + '_at'] = ts
|
|
|
|
d['percent_done'] = item.progress.progress
|
|
|
|
data.append(d)
|
|
|
|
|
|
|
|
return simplejson.dumps(data)
|