Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get item file in web plugin #4433

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beetsplug/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
10 changes: 10 additions & 0 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,16 @@ def test_patch_item_id_readonly(self):
# 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__)
Expand Down