fix sources problems

This commit is contained in:
Jack 2016-04-01 22:11:11 -04:00
parent 2540b9969f
commit d4b7064d2f
3 changed files with 49 additions and 45 deletions

View file

@ -47,7 +47,6 @@ log = logging.getLogger(__name__)
BAD_REQUEST = 400 BAD_REQUEST = 400
NOT_FOUND = 404 NOT_FOUND = 404
OK_CODE = 200 OK_CODE = 200
# TODO add login credentials in a conf file # TODO add login credentials in a conf file
# TODO alert if your copy of a lbry file is out of date with the name record # TODO alert if your copy of a lbry file is out of date with the name record
@ -83,13 +82,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
if not self.announced_startup: if not self.announced_startup:
if functionPath != 'is_running': if functionPath != 'is_running':
request.setHeader("Access-Control-Allow-Origin", "*") return server.failure
request.setHeader("content-type", "text/json")
s = jsonrpclib.Fault(self.FAILURE, "error")
request.setHeader("content-length", str(len(s)))
request.write(s)
request.finish()
return server.NOT_DONE_YET
try: try:
function = self._getFunction(functionPath) function = self._getFunction(functionPath)
@ -561,7 +554,11 @@ class LBRYDaemon(jsonrpc.JSONRPC):
def _get_stream(name): def _get_stream(name):
def _disp(stream): def _disp(stream):
log.info("[" + str(datetime.now()) + "] Start stream: " + stream['stream_hash']) stream_hash = stream['stream_hash']
if isinstance(stream_hash, dict):
stream_hash = stream_hash['sd_hash']
log.info("[" + str(datetime.now()) + "] Start stream: " + stream_hash)
return stream return stream
d = self.session.wallet.get_stream_info_for_name(name) d = self.session.wallet.get_stream_info_for_name(name)
@ -602,6 +599,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
f.close() f.close()
file_name = l['stream_name'].decode('hex') file_name = l['stream_name'].decode('hex')
for lbry_file in self.lbry_file_manager.lbry_files: for lbry_file in self.lbry_file_manager.lbry_files:
if lbry_file.stream_name == file_name: if lbry_file.stream_name == file_name:
if sys.platform == "darwin": if sys.platform == "darwin":
@ -616,6 +614,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
def _check(info): def _check(info):
stream_hash = info['stream_hash'] stream_hash = info['stream_hash']
if isinstance(stream_hash, dict):
stream_hash = stream_hash['sd_hash']
path = os.path.join(self.blobfile_dir, stream_hash) path = os.path.join(self.blobfile_dir, stream_hash)
if os.path.isfile(path): if os.path.isfile(path):
log.info("[" + str(datetime.now()) + "] Search for lbry_file, returning: " + stream_hash) log.info("[" + str(datetime.now()) + "] Search for lbry_file, returning: " + stream_hash)
@ -680,7 +681,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
return d return d
d = self.session.wallet.get_stream_info_for_name(name) d = self.session.wallet.get_stream_info_for_name(name)
d.addCallback(lambda info: download_sd_blob(self.session, info['stream_hash'], d.addCallback(lambda info: info['stream_hash'] if isinstance(info['stream_hash'], str)
else info['stream_hash']['sd_hash'])
d.addCallback(lambda sd_hash: download_sd_blob(self.session, sd_hash,
self.blob_request_payment_rate_manager)) self.blob_request_payment_rate_manager))
d.addCallback(self.sd_identifier.get_metadata_for_sd_blob) d.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
d.addCallback(lambda metadata: metadata.validator.info_to_show()) d.addCallback(lambda metadata: metadata.validator.info_to_show())
@ -829,11 +832,16 @@ class LBRYDaemon(jsonrpc.JSONRPC):
params = Bunch(p) params = Bunch(p)
def _disp(info): def _disp(info):
log.info("[" + str(datetime.now()) + "] Resolved info: " + info['stream_hash']) stream_hash = info['stream_hash']
if isinstance(stream_hash, dict):
stream_hash = stream_hash['sd_hash']
log.info("[" + str(datetime.now()) + "] Resolved info: " + stream_hash)
return self._render_response(info, OK_CODE) return self._render_response(info, OK_CODE)
d = self._resolve_name(params.name) d = self._resolve_name(params.name)
d.addCallbacks(_disp, lambda _: self._render_response('error', NOT_FOUND)) d.addCallbacks(_disp, lambda _: server.failure)
d.callback(None) d.callback(None)
return d return d
@ -960,7 +968,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
return self._render_response("Deleted: " + file_name, OK_CODE) return self._render_response("Deleted: " + file_name, OK_CODE)
lbry_files = [self._delete_lbry_file(f) for f in self.lbry_file_manager.lbry_files lbry_files = [self._delete_lbry_file(f) for f in self.lbry_file_manager.lbry_files
if params.file_name == f.file_name] if str(params.file_name) == str(f.file_name)]
d = defer.DeferredList(lbry_files) d = defer.DeferredList(lbry_files)
d.addCallback(lambda _: _disp(params.file_name)) d.addCallback(lambda _: _disp(params.file_name))
@ -974,38 +982,27 @@ class LBRYDaemon(jsonrpc.JSONRPC):
@return: @return:
""" """
params = Bunch(p) metadata_fields = ["name", "file_path", "bid", "author", "title",
"description", "thumbnail", "key_fee", "key_fee_address",
"content_license", "sources"]
metadata_fields = {"name": unicode, "file_path": unicode, "bid": float, "author": unicode, "title": unicode, for k in metadata_fields:
"description": unicode, "thumbnail": unicode, "key_fee": float, "key_fee_address": unicode, if k not in p.keys():
"content_license": unicode, "sources": dict} p[k] = None
for k in metadata_fields.keys(): pub = Publisher(self.session, self.lbry_file_manager, self.session.wallet)
if k in params.__dict__.keys():
if isinstance(params.__dict__[k], metadata_fields[k]):
if type(params.__dict__[k]) == unicode:
metadata_fields[k] = str(params.__dict__[k])
else:
metadata_fields[k] = params.__dict__[k]
else:
metadata_fields[k] = None
else:
metadata_fields[k] = None
log.info("[" + str(datetime.now()) + "] Publish: ", metadata_fields) d = pub.start(p['name'],
p['file_path'],
p = Publisher(self.session, self.lbry_file_manager, self.session.wallet) p['bid'],
d = p.start(name=metadata_fields['name'], title=p['title'],
file_path=metadata_fields['file_path'], description=p['description'],
bid=metadata_fields['bid'], thumbnail=p['thumbnail'],
title=metadata_fields['title'], key_fee=p['key_fee'],
description=metadata_fields['description'], key_fee_address=p['key_fee_address'],
thumbnail=metadata_fields['thumbnail'], content_license=p['content_license'],
key_fee=metadata_fields['key_fee'], author=p['author'],
key_fee_address=metadata_fields['key_fee_address'], sources=p['sources'])
content_license=metadata_fields['content_license'],
author=metadata_fields['author'],
sources=metadata_fields['sources'])
d.addCallbacks(lambda msg: self._render_response(msg, OK_CODE), d.addCallbacks(lambda msg: self._render_response(msg, OK_CODE),
lambda err: self._render_response(err.getTraceback(), BAD_REQUEST)) lambda err: self._render_response(err.getTraceback(), BAD_REQUEST))

View file

@ -68,6 +68,8 @@ class GetStream(object):
self.key_fee_address = None self.key_fee_address = None
self.stream_hash = self.stream_info['stream_hash'] self.stream_hash = self.stream_info['stream_hash']
if isinstance(self.stream_hash, dict):
self.stream_hash = self.stream_hash['sd_hash']
else: else:
log.error("InvalidStreamInfoError in autofetcher: ", stream_info) log.error("InvalidStreamInfoError in autofetcher: ", stream_info)

View file

@ -43,7 +43,7 @@ class Publisher(object):
message = "[" + str(datetime.now()) + "] Published " + self.file_name + " --> lbry://" + \ message = "[" + str(datetime.now()) + "] Published " + self.file_name + " --> lbry://" + \
str(self.publish_name) + " with txid: " + str(self.tx_hash) str(self.publish_name) + " with txid: " + str(self.tx_hash)
log.info(message) log.info(message)
return defer.succeed(message) return defer.succeed(self.tx_hash)
self.publish_name = name self.publish_name = name
self.file_path = file_path self.file_path = file_path
@ -103,12 +103,16 @@ class Publisher(object):
def set_sd_hash(sd_hash): def set_sd_hash(sd_hash):
self.sd_hash = sd_hash self.sd_hash = sd_hash
if isinstance(self.sources, dict):
self.sources['lbry_sd_hash'] = sd_hash
else:
self.sources = {'lbry_sd_hash': sd_hash}
d.addCallback(set_sd_hash) d.addCallback(set_sd_hash)
return d return d
def _claim_name(self): def _claim_name(self):
d = self.wallet.claim_name(self.publish_name, {'sd_hash': self.sd_hash}, self.bid_amount, d = self.wallet.claim_name(self.publish_name, self.sd_hash, self.bid_amount,
description=self.description, key_fee=self.key_fee, description=self.description, key_fee=self.key_fee,
key_fee_address=self.key_fee_address, thumbnail=self.thumbnail, key_fee_address=self.key_fee_address, thumbnail=self.thumbnail,
content_license=self.content_license, author=self.author, content_license=self.content_license, author=self.author,
@ -121,6 +125,7 @@ class Publisher(object):
return d return d
def _show_publish_error(self, err): def _show_publish_error(self, err):
log.info(err.getTraceback())
message = "An error occurred publishing %s to %s. Error: %s." message = "An error occurred publishing %s to %s. Error: %s."
if err.check(InsufficientFundsError): if err.check(InsufficientFundsError):
error_message = "Insufficient funds" error_message = "Insufficient funds"