forked from LBRYCommunity/lbry-sdk
Apply suggestions
This commit is contained in:
parent
f92b610a03
commit
15376c19be
3 changed files with 12 additions and 10 deletions
|
@ -89,7 +89,7 @@ class StreamDescriptor:
|
||||||
self.blob_dir = blob_dir
|
self.blob_dir = blob_dir
|
||||||
self.stream_name = stream_name
|
self.stream_name = stream_name
|
||||||
self.key = key
|
self.key = key
|
||||||
self.suggested_file_name = sanitize_file_name(suggested_file_name)
|
self.suggested_file_name = suggested_file_name
|
||||||
self.blobs = blobs
|
self.blobs = blobs
|
||||||
self.stream_hash = stream_hash or self.get_stream_hash()
|
self.stream_hash = stream_hash or self.get_stream_hash()
|
||||||
self.sd_hash = sd_hash
|
self.sd_hash = sd_hash
|
||||||
|
@ -251,9 +251,10 @@ class StreamDescriptor:
|
||||||
blobs.append(blob_info)
|
blobs.append(blob_info)
|
||||||
blobs.append(
|
blobs.append(
|
||||||
BlobInfo(len(blobs), 0, binascii.hexlify(next(iv_generator)).decode())) # add the stream terminator
|
BlobInfo(len(blobs), 0, binascii.hexlify(next(iv_generator)).decode())) # add the stream terminator
|
||||||
|
file_name = os.path.basename(file_path)
|
||||||
|
suggested_file_name = sanitize_file_name(file_name)
|
||||||
descriptor = cls(
|
descriptor = cls(
|
||||||
loop, blob_dir, os.path.basename(file_path), binascii.hexlify(key).decode(), os.path.basename(file_path),
|
loop, blob_dir, file_name, binascii.hexlify(key).decode(), suggested_file_name, blobs
|
||||||
blobs
|
|
||||||
)
|
)
|
||||||
sd_blob = await descriptor.make_sd_blob(old_sort=old_sort, blob_completed_callback=blob_completed_callback)
|
sd_blob = await descriptor.make_sd_blob(old_sort=old_sort, blob_completed_callback=blob_completed_callback)
|
||||||
descriptor.sd_hash = sd_blob.blob_hash
|
descriptor.sd_hash = sd_blob.blob_hash
|
||||||
|
|
|
@ -8,7 +8,7 @@ from lbry.utils import generate_id
|
||||||
from lbry.error import DownloadSDTimeout
|
from lbry.error import DownloadSDTimeout
|
||||||
from lbry.schema.mime_types import guess_media_type
|
from lbry.schema.mime_types import guess_media_type
|
||||||
from lbry.stream.downloader import StreamDownloader
|
from lbry.stream.downloader import StreamDownloader
|
||||||
from lbry.stream.descriptor import StreamDescriptor
|
from lbry.stream.descriptor import StreamDescriptor, sanitize_file_name
|
||||||
from lbry.stream.reflector.client import StreamReflectorClient
|
from lbry.stream.reflector.client import StreamReflectorClient
|
||||||
from lbry.extras.daemon.storage import StoredStreamClaim
|
from lbry.extras.daemon.storage import StoredStreamClaim
|
||||||
from lbry.blob import MAX_BLOB_SIZE
|
from lbry.blob import MAX_BLOB_SIZE
|
||||||
|
@ -386,7 +386,7 @@ class ManagedStream:
|
||||||
os.mkdir(self.download_directory)
|
os.mkdir(self.download_directory)
|
||||||
self._file_name = await get_next_available_file_name(
|
self._file_name = await get_next_available_file_name(
|
||||||
self.loop, self.download_directory,
|
self.loop, self.download_directory,
|
||||||
file_name or self.file_name
|
file_name or self._file_name or sanitize_file_name(self.descriptor.suggested_file_name)
|
||||||
)
|
)
|
||||||
await self.blob_manager.storage.change_file_download_dir_and_file_name(
|
await self.blob_manager.storage.change_file_download_dir_and_file_name(
|
||||||
self.stream_hash, self.download_directory, self.file_name
|
self.stream_hash, self.download_directory, self.file_name
|
||||||
|
|
|
@ -51,11 +51,11 @@ class FileCommands(CommandTestCase):
|
||||||
suffix = '.ext.'
|
suffix = '.ext.'
|
||||||
san_prefix = 'antz m'
|
san_prefix = 'antz m'
|
||||||
san_suffix = '.ext'
|
san_suffix = '.ext'
|
||||||
claim = await self.stream_create('foo', '0.01', prefix=prefix, suffix=suffix)
|
tx = await self.stream_create('foo', '0.01', prefix=prefix, suffix=suffix)
|
||||||
stream = self.daemon.jsonrpc_file_list()[0]
|
stream = self.daemon.jsonrpc_file_list()[0]
|
||||||
|
|
||||||
# Check that file list and source contains the local unsanitized name, but suggested name is sanitized
|
# Assert that file list and source contains the local unsanitized name, but suggested name is sanitized
|
||||||
source_file_name = claim['outputs'][0]['value']['source']['name']
|
source_file_name = tx['outputs'][0]['value']['source']['name']
|
||||||
file_list_name = stream.file_name
|
file_list_name = stream.file_name
|
||||||
suggested_file_name = stream.descriptor.suggested_file_name
|
suggested_file_name = stream.descriptor.suggested_file_name
|
||||||
self.assertTrue(source_file_name.startswith(prefix))
|
self.assertTrue(source_file_name.startswith(prefix))
|
||||||
|
@ -64,15 +64,16 @@ class FileCommands(CommandTestCase):
|
||||||
self.assertTrue(suggested_file_name.startswith(san_prefix))
|
self.assertTrue(suggested_file_name.startswith(san_prefix))
|
||||||
self.assertTrue(suggested_file_name.endswith(san_suffix))
|
self.assertTrue(suggested_file_name.endswith(san_suffix))
|
||||||
|
|
||||||
# Delete the file, re-download and check that the file name is sanitized
|
# Delete the file, re-download and assert that the file name is sanitized
|
||||||
self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'))
|
self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'))
|
||||||
|
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 0)
|
||||||
full_path = (await self.daemon.jsonrpc_get('lbry://foo', save_file=True)).full_path
|
full_path = (await self.daemon.jsonrpc_get('lbry://foo', save_file=True)).full_path
|
||||||
file_name = os.path.basename(full_path)
|
file_name = os.path.basename(full_path)
|
||||||
self.assertTrue(os.path.isfile(full_path))
|
self.assertTrue(os.path.isfile(full_path))
|
||||||
self.assertTrue(file_name.startswith(san_prefix))
|
self.assertTrue(file_name.startswith(san_prefix))
|
||||||
self.assertTrue(file_name.endswith(san_suffix))
|
self.assertTrue(file_name.endswith(san_suffix))
|
||||||
|
|
||||||
# Check that the downloaded file name is not sanitized when user provides custom file name
|
# Assert that the downloaded file name is not sanitized when user provides custom file name
|
||||||
self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'))
|
self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'))
|
||||||
file_name = 'my <u?|*m.name'
|
file_name = 'my <u?|*m.name'
|
||||||
full_path = (await self.daemon.jsonrpc_get('lbry://foo', file_name=file_name, save_file=True)).full_path
|
full_path = (await self.daemon.jsonrpc_get('lbry://foo', file_name=file_name, save_file=True)).full_path
|
||||||
|
|
Loading…
Add table
Reference in a new issue