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

Feat/download via share link #3666

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

glorenzen
Copy link
Contributor

This feature adds an option when sharing a media item to allow users to download the zip file.

This resolves #3606

This is still a work in progress, but I've added the toggle to the share modal, updated the MediaItemShare model to include a field for whether or not the item is downloadable, added the migration file for the updated column, and updated the ShareController.

image

@glorenzen glorenzen marked this pull request as ready for review December 3, 2024 22:14
@glorenzen
Copy link
Contributor Author

@advplyr I think this should be ready to go, but let me know if you have any thoughts or think anything should be changed. I added to the download method in the LibraryItemController to handle share items, but there might be a better way to handle it that I didn't think of.

Also, I'm not sure if the migration script name needs to be changed since the server version was updated after I started this PR.

@glorenzen
Copy link
Contributor Author

Here's a screenshot of the download button on the share page (top left corner):
image

@@ -157,33 +157,49 @@ class LibraryItemController {
* @param {Response} res
*/
async download(req, res) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this endpoint isn't going to work because all of the endpoints in /api/ are authenticated. The reason it would have worked in your testing is because you're still authenticated via the session. You can test it by using the share link in incognito.

The download functionality should be in the ShareController which gets served from the unauthenticated PublicRouter. Most of those functions are authenticating using the share_session_id cookie.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. I didn't test in an incognito and didn't realize all endpoints in /api/ were authenticated, but that makes sense! I'll move the download functionality to the ShareController.

* @param {MigrationOptions} options - an object containing the migration context.
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
*/
module.exports = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrations should keep the same format of using individual functions up and down for consistency. The JSDoc types also aren't going to work when they are above the export like that.
If you're not using an editor that can use JSDocs I highly recommend it.

The other migrations have a log for BEGIN/END on up and down which we should keep consistent

*/
module.exports = {
up: async ({ context: { queryInterface, logger } }) => {
await queryInterface.addColumn('mediaItemShares', 'isDownloadable', {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the mediaItemShares table was added later someone may be upgrading from a version that doesn't have the table yet which will cause this to crash. See v2.17.3-fk-constraints migration on wrapping this in a tableExists check.

Also, we want these migrations to be idempotent. If this migration were to run and the isDownloadable column already exists, the migration should still run.

@advplyr
Copy link
Owner

advplyr commented Dec 4, 2024

Also, I'm not sure if the migration script name needs to be changed since the server version was updated after I started this PR.

Yeah if you can merge master and update the name of the migration file to v2.17.5

@advplyr
Copy link
Owner

advplyr commented Dec 4, 2024

There is also a changelog.md in the migrations folder that should have a short description of each migration

@glorenzen
Copy link
Contributor Author

@advplyr I think all the updates should be complete now, but let me know if I missed something or need to change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Download via share link
2 participants