forked from LBRYCommunity/lbry-sdk
Merge pull request #3695 from lbryio/3690
Fix claim fields fallback raising errors before download is saved on database
This commit is contained in:
commit
15dc52bd9a
2 changed files with 23 additions and 4 deletions
|
@ -13,11 +13,12 @@ from lbry.schema.url import URL
|
||||||
from lbry.wallet.dewies import dewies_to_lbc
|
from lbry.wallet.dewies import dewies_to_lbc
|
||||||
from lbry.file.source_manager import SourceManager
|
from lbry.file.source_manager import SourceManager
|
||||||
from lbry.file.source import ManagedDownloadSource
|
from lbry.file.source import ManagedDownloadSource
|
||||||
|
from lbry.extras.daemon.storage import StoredContentClaim
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from lbry.conf import Config
|
from lbry.conf import Config
|
||||||
from lbry.extras.daemon.analytics import AnalyticsManager
|
from lbry.extras.daemon.analytics import AnalyticsManager
|
||||||
from lbry.extras.daemon.storage import SQLiteStorage
|
from lbry.extras.daemon.storage import SQLiteStorage
|
||||||
from lbry.wallet import WalletManager, Output
|
from lbry.wallet import WalletManager
|
||||||
from lbry.extras.daemon.exchange_rate_manager import ExchangeRateManager
|
from lbry.extras.daemon.exchange_rate_manager import ExchangeRateManager
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -194,21 +195,24 @@ class FileManager:
|
||||||
####################
|
####################
|
||||||
# make downloader and wait for start
|
# make downloader and wait for start
|
||||||
####################
|
####################
|
||||||
|
# temporary with fields we know so downloader can start. Missing fields are populated later.
|
||||||
|
stored_claim = StoredContentClaim(outpoint=outpoint, claim_id=txo.claim_id, name=txo.claim_name,
|
||||||
|
amount=txo.amount, height=txo.tx_ref.height,
|
||||||
|
serialized=claim.to_bytes().hex())
|
||||||
|
|
||||||
if not claim.stream.source.bt_infohash:
|
if not claim.stream.source.bt_infohash:
|
||||||
# fixme: this shouldnt be here
|
# fixme: this shouldnt be here
|
||||||
stream = ManagedStream(
|
stream = ManagedStream(
|
||||||
self.loop, self.config, source_manager.blob_manager, claim.stream.source.sd_hash,
|
self.loop, self.config, source_manager.blob_manager, claim.stream.source.sd_hash,
|
||||||
download_directory, file_name, ManagedStream.STATUS_RUNNING, content_fee=payment,
|
download_directory, file_name, ManagedStream.STATUS_RUNNING, content_fee=payment,
|
||||||
analytics_manager=self.analytics_manager
|
analytics_manager=self.analytics_manager, claim=stored_claim
|
||||||
)
|
)
|
||||||
stream.downloader.node = source_manager.node
|
stream.downloader.node = source_manager.node
|
||||||
else:
|
else:
|
||||||
stream = TorrentSource(
|
stream = TorrentSource(
|
||||||
self.loop, self.config, self.storage, identifier=claim.stream.source.bt_infohash,
|
self.loop, self.config, self.storage, identifier=claim.stream.source.bt_infohash,
|
||||||
file_name=file_name, download_directory=download_directory or self.config.download_dir,
|
file_name=file_name, download_directory=download_directory or self.config.download_dir,
|
||||||
status=ManagedStream.STATUS_RUNNING,
|
status=ManagedStream.STATUS_RUNNING, claim=stored_claim, analytics_manager=self.analytics_manager,
|
||||||
analytics_manager=self.analytics_manager,
|
|
||||||
torrent_session=source_manager.torrent_session
|
torrent_session=source_manager.torrent_session
|
||||||
)
|
)
|
||||||
log.info("starting download for %s", uri)
|
log.info("starting download for %s", uri)
|
||||||
|
|
|
@ -89,6 +89,21 @@ class FileCommands(CommandTestCase):
|
||||||
await self.reflector.blob_manager.delete_blobs(all_except_sd)
|
await self.reflector.blob_manager.delete_blobs(all_except_sd)
|
||||||
self.assertEqual(all_except_sd, await self.daemon.jsonrpc_file_reflect(sd_hash=sd_hash))
|
self.assertEqual(all_except_sd, await self.daemon.jsonrpc_file_reflect(sd_hash=sd_hash))
|
||||||
|
|
||||||
|
async def test_sd_blob_fields_fallback(self):
|
||||||
|
claim_id = self.get_claim_id(await self.stream_create('foo', '0.01', suffix='.txt'))
|
||||||
|
stream = (await self.daemon.jsonrpc_file_list())["items"][0]
|
||||||
|
stream.descriptor.suggested_file_name = ' '
|
||||||
|
stream.descriptor.stream_name = ' '
|
||||||
|
stream.descriptor.stream_hash = stream.descriptor.get_stream_hash()
|
||||||
|
sd_hash = stream.descriptor.sd_hash = stream.descriptor.calculate_sd_hash()
|
||||||
|
await stream.descriptor.make_sd_blob()
|
||||||
|
await self.daemon.jsonrpc_file_delete(claim_name='foo')
|
||||||
|
await self.stream_update(claim_id=claim_id, sd_hash=sd_hash)
|
||||||
|
file_dict = await self.out(self.daemon.jsonrpc_get('lbry://foo', save_file=True))
|
||||||
|
self.assertEqual(file_dict['suggested_file_name'], stream.file_name)
|
||||||
|
self.assertEqual(file_dict['stream_name'], stream.file_name)
|
||||||
|
self.assertEqual(file_dict['mime_type'], 'text/plain')
|
||||||
|
|
||||||
async def test_file_management(self):
|
async def test_file_management(self):
|
||||||
await self.stream_create('foo', '0.01')
|
await self.stream_create('foo', '0.01')
|
||||||
await self.stream_create('foo2', '0.01')
|
await self.stream_create('foo2', '0.01')
|
||||||
|
|
Loading…
Reference in a new issue