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

Support rendering some media downloads as inline #1360

Closed

Conversation

Half-Shot
Copy link
Contributor

For matrix-org/synapse#15988

This is incredibly hamfisted, as my ability to write perl is limited. The idea here is that we allow either inline or attachment depositions for certain content-types.

@Half-Shot Half-Shot requested a review from a team as a code owner July 24, 2023 11:24
@@ -45,7 +45,7 @@
=head2 upload_test_content

my ( $content_id, $content_uri ) = upload_test_content(
$user, filename => "filename",
$user, filename => "filename", $content_type
Copy link

Choose a reason for hiding this comment

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

Not a fan of mixing positionals and named arguments like that.

We could make it another param, and skip it when using %params in its entirety, like this:

my ($user, %params) = @_;
my $content_type = delete $params{content_type} //= "application/octet-stream";

This is using the defined-or construct introduced in Perl 5.10 – which is over 15 years old, though it is tradition that if the version is not declared anywhere, we should assume 5.8 featureset. I see a bunch of use 5.010; elsewhere in the codebase though, so we should be in the clear here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't modify delete in defined or assignment (//=) at tests/51media/01unicode.pl line 61, at EOF :(

Copy link

Choose a reason for hiding this comment

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

Oh yes, I got ahead of myself there. That should be just //, not //=. We already have the assignment in that line :)

@@ -125,7 +129,14 @@ sub parse_content_disposition_params {
# the first part must be 'attachment'
my $k = shift @parts;
my $v = shift @parts;
assert_eq( $k, "attachment", "content-disposition" );

if ($allow_inline_disposition eq 1) {
Copy link

Choose a reason for hiding this comment

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

eq is for string comparison, which is works here but it needlessly explicit and out of place.

Suggested change
if ($allow_inline_disposition eq 1) {
if ($allow_inline_disposition) {

}
Future->done( $cd_params, $body );
});
}
push @EXPORT, qw( get_media );

sub parse_content_disposition_params {
my ( $disposition ) = @_;
my ( $disposition, $allow_inline_disposition ) = @_;
Copy link

Choose a reason for hiding this comment

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

I'd consider making this a named argument to make it more readable on the caller side (more than a plain 1 in the argument list).

@Half-Shot
Copy link
Contributor Author

matrix-org/complement#646 implements this test...so we can just drop it.

@Half-Shot
Copy link
Contributor Author

The

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.

2 participants