Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
b01d2527
Commit
b01d2527
authored
10 months ago
by
Jason Volk
Committed by
🥺
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
fix remote media error propagation
Signed-off-by:
Jason Volk
<
jason@zemos.net
>
parent
b3984f53
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/api/client_server/media.rs
+45
-30
45 additions, 30 deletions
src/api/client_server/media.rs
with
45 additions
and
30 deletions
src/api/client_server/media.rs
+
45
−
30
View file @
b01d2527
...
@@ -181,15 +181,18 @@ pub(crate) async fn get_content_route(body: Ruma<get_content::v3::Request>) -> R
...
@@ -181,15 +181,18 @@ pub(crate) async fn get_content_route(body: Ruma<get_content::v3::Request>) -> R
cache_control
:
Some
(
CACHE_CONTROL_IMMUTABLE
.into
()),
cache_control
:
Some
(
CACHE_CONTROL_IMMUTABLE
.into
()),
})
})
}
else
if
&*
body
.server_name
!=
services
()
.globals
.server_name
()
&&
body
.allow_remote
{
}
else
if
&*
body
.server_name
!=
services
()
.globals
.server_name
()
&&
body
.allow_remote
{
let
remote_content_response
=
get_remote_content
(
get_remote_content
(
&
mxc
,
&
mxc
,
&
body
.server_name
,
&
body
.server_name
,
body
.media_id
.clone
(),
body
.media_id
.clone
(),
body
.allow_redirect
,
body
.allow_redirect
,
body
.timeout_ms
,
body
.timeout_ms
,
)
)
.await
?
;
.await
Ok
(
remote_content_response
)
.map_err
(|
e
|
{
debug_warn!
(
"Fetching media `{}` failed: {:?}"
,
mxc
,
e
);
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Remote media error."
)
})
}
else
{
}
else
{
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
))
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
))
}
}
...
@@ -240,22 +243,27 @@ pub(crate) async fn get_content_as_filename_route(
...
@@ -240,22 +243,27 @@ pub(crate) async fn get_content_as_filename_route(
cache_control
:
Some
(
CACHE_CONTROL_IMMUTABLE
.into
()),
cache_control
:
Some
(
CACHE_CONTROL_IMMUTABLE
.into
()),
})
})
}
else
if
&*
body
.server_name
!=
services
()
.globals
.server_name
()
&&
body
.allow_remote
{
}
else
if
&*
body
.server_name
!=
services
()
.globals
.server_name
()
&&
body
.allow_remote
{
let
remote_content_response
=
get_remote_content
(
match
get_remote_content
(
&
mxc
,
&
mxc
,
&
body
.server_name
,
&
body
.server_name
,
body
.media_id
.clone
(),
body
.media_id
.clone
(),
body
.allow_redirect
,
body
.allow_redirect
,
body
.timeout_ms
,
body
.timeout_ms
,
)
)
.await
?
;
.await
{
Ok
(
get_content_as_filename
::
v3
::
Response
{
Ok
(
remote_content_response
)
=>
Ok
(
get_content_as_filename
::
v3
::
Response
{
content_disposition
:
Some
(
format!
(
"inline: filename={}"
,
body
.filename
)),
content_disposition
:
Some
(
format!
(
"inline: filename={}"
,
body
.filename
)),
content_type
:
remote_content_response
.content_type
,
content_type
:
remote_content_response
.content_type
,
file
:
remote_content_response
.file
,
file
:
remote_content_response
.file
,
cross_origin_resource_policy
:
Some
(
"cross-origin"
.to_owned
()),
cross_origin_resource_policy
:
Some
(
"cross-origin"
.to_owned
()),
cache_control
:
Some
(
CACHE_CONTROL_IMMUTABLE
.into
()),
cache_control
:
Some
(
CACHE_CONTROL_IMMUTABLE
.into
()),
})
}),
Err
(
e
)
=>
{
debug_warn!
(
"Fetching media `{}` failed: {:?}"
,
mxc
,
e
);
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Remote media error."
))
},
}
}
else
{
}
else
{
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
))
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
))
}
}
...
@@ -330,7 +338,7 @@ pub(crate) async fn get_content_thumbnail_route(
...
@@ -330,7 +338,7 @@ pub(crate) async fn get_content_thumbnail_route(
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
));
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
));
}
}
let
get_thumbnail_response
=
services
()
match
services
()
.sending
.sending
.send_federation_request
(
.send_federation_request
(
&
body
.server_name
,
&
body
.server_name
,
...
@@ -345,22 +353,29 @@ pub(crate) async fn get_content_thumbnail_route(
...
@@ -345,22 +353,29 @@ pub(crate) async fn get_content_thumbnail_route(
allow_redirect
:
body
.allow_redirect
,
allow_redirect
:
body
.allow_redirect
,
},
},
)
)
.await
?
;
.await
{
services
()
Ok
(
get_thumbnail_response
)
=>
{
.media
services
()
.upload_thumbnail
(
.media
None
,
.upload_thumbnail
(
mxc
,
None
,
None
,
mxc
,
get_thumbnail_response
.content_type
.as_deref
(),
None
,
body
.width
.try_into
()
.expect
(
"all UInts are valid u32s"
),
get_thumbnail_response
.content_type
.as_deref
(),
body
.height
.try_into
()
.expect
(
"all UInts are valid u32s"
),
body
.width
.try_into
()
.expect
(
"all UInts are valid u32s"
),
&
get_thumbnail_response
.file
,
body
.height
.try_into
()
.expect
(
"all UInts are valid u32s"
),
)
&
get_thumbnail_response
.file
,
.await
?
;
)
.await
?
;
Ok
(
get_thumbnail_response
)
Ok
(
get_thumbnail_response
)
},
Err
(
e
)
=>
{
debug_warn!
(
"Fetching media `{}` failed: {:?}"
,
mxc
,
e
);
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Remote media error."
))
},
}
}
else
{
}
else
{
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
))
Err
(
Error
::
BadRequest
(
ErrorKind
::
NotFound
,
"Media not found."
))
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment