fix suggested_file_name for torrent on json encoder

This commit is contained in:
Victor Shyba 2022-10-27 20:38:21 -03:00
parent 2bf0ca6441
commit 732b7e79d7
3 changed files with 6 additions and 2 deletions

View file

@ -294,7 +294,7 @@ class JSONResponseEncoder(JSONEncoder):
'stopped': not managed_stream.running, 'stopped': not managed_stream.running,
'stream_hash': None, 'stream_hash': None,
'stream_name': None, 'stream_name': None,
'suggested_file_name': None, 'suggested_file_name': managed_stream.suggested_file_name,
'sd_hash': None, 'sd_hash': None,
'mime_type': managed_stream.mime_type, 'mime_type': managed_stream.mime_type,
'key': None, 'key': None,
@ -328,7 +328,6 @@ class JSONResponseEncoder(JSONEncoder):
result.update({ result.update({
'stream_hash': managed_stream.stream_hash, 'stream_hash': managed_stream.stream_hash,
'stream_name': managed_stream.stream_name, 'stream_name': managed_stream.stream_name,
'suggested_file_name': managed_stream.suggested_file_name,
'sd_hash': managed_stream.descriptor.sd_hash, 'sd_hash': managed_stream.descriptor.sd_hash,
'key': managed_stream.descriptor.key, 'key': managed_stream.descriptor.key,
'blobs_completed': managed_stream.blobs_completed, 'blobs_completed': managed_stream.blobs_completed,

View file

@ -92,6 +92,10 @@ class ManagedDownloadSource:
def added_on(self) -> Optional[int]: def added_on(self) -> Optional[int]:
return self._added_on return self._added_on
@property
def suggested_file_name(self):
return self._file_name
@property @property
def status(self) -> str: def status(self) -> str:
return self._status return self._status

View file

@ -86,6 +86,7 @@ class FileCommands(CommandTestCase):
self.assertEqual(btih, file['metadata']['source']['bt_infohash']) self.assertEqual(btih, file['metadata']['source']['bt_infohash'])
self.assertAlmostEqual(time.time(), file['added_on'], delta=2) self.assertAlmostEqual(time.time(), file['added_on'], delta=2)
self.assertEqual("application/octet-stream", file['mime_type']) self.assertEqual("application/octet-stream", file['mime_type'])
self.assertEqual("tmp1", file['suggested_file_name'])
self.assertIn(btih, self.client_session._handles) self.assertIn(btih, self.client_session._handles)
# stream over streaming API (full range of the largest file) # stream over streaming API (full range of the largest file)