@@ -153,6 +153,7 @@ struct SourcePage {
153
153
file : Option < File > ,
154
154
file_content : Option < String > ,
155
155
canonical_url : CanonicalUrl ,
156
+ is_file_too_large : bool ,
156
157
is_latest_url : bool ,
157
158
use_direct_platform_links : bool ,
158
159
}
@@ -226,7 +227,7 @@ pub(crate) async fn source_browser_handler(
226
227
227
228
// try to get actual file first
228
229
// skip if request is a directory
229
- let blob = if !params. path . ends_with ( '/' ) {
230
+ let ( blob, is_file_too_large ) = if !params. path . ends_with ( '/' ) {
230
231
match storage
231
232
. fetch_source_file (
232
233
& params. name ,
@@ -238,17 +239,23 @@ pub(crate) async fn source_browser_handler(
238
239
. await
239
240
. context ( "error fetching source file" )
240
241
{
241
- Ok ( blob) => Some ( blob) ,
242
- Err ( err) => {
243
- if err. is :: < PathNotFoundError > ( ) {
244
- None
245
- } else {
246
- return Err ( err. into ( ) ) ;
242
+ Ok ( blob) => ( Some ( blob) , false ) ,
243
+ Err ( err) => match err {
244
+ err if err. is :: < PathNotFoundError > ( ) => ( None , false ) ,
245
+ // if file is too large, set is_file_too_large to true
246
+ err if err. downcast_ref :: < std:: io:: Error > ( ) . is_some_and ( |err| {
247
+ err. get_ref ( )
248
+ . map ( |err| err. is :: < crate :: error:: SizeLimitReached > ( ) )
249
+ . unwrap_or ( false )
250
+ } ) =>
251
+ {
252
+ ( None , true )
247
253
}
248
- }
254
+ _ => return Err ( err. into ( ) ) ,
255
+ } ,
249
256
}
250
257
} else {
251
- None
258
+ ( None , false )
252
259
} ;
253
260
254
261
let canonical_url = CanonicalUrl :: from_path ( format ! (
@@ -305,6 +312,7 @@ pub(crate) async fn source_browser_handler(
305
312
file,
306
313
file_content,
307
314
canonical_url,
315
+ is_file_too_large,
308
316
is_latest_url : params. version . is_latest ( ) ,
309
317
use_direct_platform_links : true ,
310
318
}
0 commit comments