Use inlineCallbacks for jsonrpc_open() and jsonrpc_reveal()
This commit is contained in:
parent
5db1a4d328
commit
08aa024499
1 changed files with 22 additions and 19 deletions
|
@ -2220,6 +2220,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
return d
|
||||
|
||||
@AuthJSONRPCServer.auth_required
|
||||
@defer.inlineCallbacks
|
||||
def jsonrpc_open(self, p):
|
||||
"""
|
||||
Instruct the OS to open a file with its default program.
|
||||
|
@ -2230,18 +2231,20 @@ class Daemon(AuthJSONRPCServer):
|
|||
True, opens file
|
||||
"""
|
||||
|
||||
def _open_lbry_file(lbry_file):
|
||||
if 'sd_hash' not in p:
|
||||
raise ValueError('sd_hash is required')
|
||||
|
||||
lbry_file = yield self._get_lbry_file(FileID.SD_HASH, p['sd_hash'])
|
||||
if not lbry_file:
|
||||
raise Exception('Unable to find file for {}'.format(p['sd_hash']))
|
||||
|
||||
try:
|
||||
file_utils.start(lbry_file['download_path'])
|
||||
except IOError:
|
||||
pass
|
||||
defer.returnValue(True)
|
||||
|
||||
d = self._get_lbry_file(FileID.SD_HASH, p['sd_hash'])
|
||||
d.addCallback(_open_lbry_file)
|
||||
d.addCallback(lambda _: self._render_response(True, OK_CODE))
|
||||
|
||||
return d
|
||||
|
||||
@defer.inlineCallbacks
|
||||
@AuthJSONRPCServer.auth_required
|
||||
def jsonrpc_reveal(self, p):
|
||||
"""
|
||||
|
@ -2253,18 +2256,18 @@ class Daemon(AuthJSONRPCServer):
|
|||
True, opens file browser
|
||||
"""
|
||||
|
||||
def _reveal_lbry_file(lbry_file):
|
||||
if 'sd_hash' not in p:
|
||||
raise ValueError('sd_hash is required')
|
||||
|
||||
lbry_file = yield self._get_lbry_file(FileID.SD_HASH, p['sd_hash'])
|
||||
if not lbry_file:
|
||||
raise Exception('Unable to find file for {}'.format(p['sd_hash']))
|
||||
|
||||
try:
|
||||
file_utils.reveal(lbry_file['download_path'])
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
d = self._get_lbry_file(FileID.SD_HASH, p['sd_hash'])
|
||||
d.addCallback(_reveal_lbry_file)
|
||||
d.addCallback(lambda _: self._render_response(True, OK_CODE))
|
||||
|
||||
return d
|
||||
|
||||
defer.returnValue(True)
|
||||
|
||||
def jsonrpc_get_peers_for_hash(self, p):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue