diff --git a/lbry/file/file_manager.py b/lbry/file/file_manager.py index 67c1630d7..6ab943907 100644 --- a/lbry/file/file_manager.py +++ b/lbry/file/file_manager.py @@ -13,11 +13,12 @@ from lbry.schema.url import URL from lbry.wallet.dewies import dewies_to_lbc from lbry.file.source_manager import SourceManager from lbry.file.source import ManagedDownloadSource +from lbry.extras.daemon.storage import StoredContentClaim if typing.TYPE_CHECKING: from lbry.conf import Config from lbry.extras.daemon.analytics import AnalyticsManager 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 log = logging.getLogger(__name__) @@ -194,21 +195,24 @@ class FileManager: #################### # 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: # fixme: this shouldnt be here stream = ManagedStream( self.loop, self.config, source_manager.blob_manager, claim.stream.source.sd_hash, 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 else: stream = TorrentSource( 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, - status=ManagedStream.STATUS_RUNNING, - analytics_manager=self.analytics_manager, + status=ManagedStream.STATUS_RUNNING, claim=stored_claim, analytics_manager=self.analytics_manager, torrent_session=source_manager.torrent_session ) log.info("starting download for %s", uri) diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index 99023e20c..95e92ce1e 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -89,6 +89,21 @@ class FileCommands(CommandTestCase): 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)) + 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): await self.stream_create('foo', '0.01') await self.stream_create('foo2', '0.01')