Use inlineCallbacks for jsonrpc_open() and jsonrpc_reveal()

This commit is contained in:
Alex Liebowitz 2017-01-18 04:02:27 -05:00
parent 5db1a4d328
commit 08aa024499

View file

@ -2220,6 +2220,7 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
@defer.inlineCallbacks
def jsonrpc_open(self, p): def jsonrpc_open(self, p):
""" """
Instruct the OS to open a file with its default program. Instruct the OS to open a file with its default program.
@ -2230,18 +2231,20 @@ class Daemon(AuthJSONRPCServer):
True, opens file True, opens file
""" """
def _open_lbry_file(lbry_file): if 'sd_hash' not in p:
try: raise ValueError('sd_hash is required')
file_utils.start(lbry_file['download_path'])
except IOError:
pass
d = self._get_lbry_file(FileID.SD_HASH, p['sd_hash']) lbry_file = yield self._get_lbry_file(FileID.SD_HASH, p['sd_hash'])
d.addCallback(_open_lbry_file) if not lbry_file:
d.addCallback(lambda _: self._render_response(True, OK_CODE)) raise Exception('Unable to find file for {}'.format(p['sd_hash']))
return d try:
file_utils.start(lbry_file['download_path'])
except IOError:
pass
defer.returnValue(True)
@defer.inlineCallbacks
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_reveal(self, p): def jsonrpc_reveal(self, p):
""" """
@ -2253,18 +2256,18 @@ class Daemon(AuthJSONRPCServer):
True, opens file browser True, opens file browser
""" """
def _reveal_lbry_file(lbry_file): if 'sd_hash' not in p:
try: raise ValueError('sd_hash is required')
file_utils.reveal(lbry_file['download_path'])
except IOError:
pass
d = self._get_lbry_file(FileID.SD_HASH, p['sd_hash']) lbry_file = yield self._get_lbry_file(FileID.SD_HASH, p['sd_hash'])
d.addCallback(_reveal_lbry_file) if not lbry_file:
d.addCallback(lambda _: self._render_response(True, OK_CODE)) raise Exception('Unable to find file for {}'.format(p['sd_hash']))
return d
try:
file_utils.reveal(lbry_file['download_path'])
except IOError:
pass
defer.returnValue(True)
def jsonrpc_get_peers_for_hash(self, p): def jsonrpc_get_peers_for_hash(self, p):
""" """