Merge pull request #4433 from vicholp/master

Fix get item file in web plugin
This commit is contained in:
Adrian Sampson 2022-08-05 09:15:00 -04:00 committed by GitHub
commit 6eec17c661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -324,7 +324,7 @@ def item_file(item_id):
response = flask.send_file(
item_path,
as_attachment=True,
attachment_filename=safe_filename
download_name=safe_filename
)
response.headers['Content-Length'] = os.path.getsize(item_path)
return response

View file

@ -92,6 +92,7 @@ Bug fixes:
that casues a crash when ImportAdded plugin enabled.
:bug:`4389`
* :doc:`plugins/convert`: Fix a bug with the `wma` format alias.
* :doc:`/plugins/web`: Fix get file from item.
For packagers:

View file

@ -667,6 +667,16 @@ class WebPluginTest(_common.LibTestCase):
# Remove the item
self.lib.get_item(item_id).remove()
def test_get_item_file(self):
ipath = os.path.join(self.temp_dir, b'testfile2.mp3')
shutil.copy(os.path.join(_common.RSRC, b'full.mp3'), ipath)
self.assertTrue(os.path.exists(ipath))
item_id = self.lib.add(Item.from_path(ipath))
response = self.client.get('/item/' + str(item_id) + '/file')
self.assertEqual(response.status_code, 200)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)