@@ -15,11 +15,14 @@ crate::routes! {
15
15
}
16
16
17
17
#[ derive( Debug , Error , EditoastError ) ]
18
- #[ editoast_error( base_id = "scenario " ) ]
18
+ #[ editoast_error( base_id = "sprites " ) ]
19
19
enum SpriteErrors {
20
20
#[ error( "Unknown signaling system '{0}'" ) ]
21
21
#[ editoast_error( status = 404 ) ]
22
22
UnknownSignalingSystem ( String ) ,
23
+ #[ error( "File '{0}' not found" ) ]
24
+ #[ editoast_error( status = 404 ) ]
25
+ FileNotFound ( String ) ,
23
26
}
24
27
25
28
/// This endpoint returns the list of supported signaling systems
@@ -41,21 +44,23 @@ async fn signaling_systems() -> Result<Json<Vec<String>>> {
41
44
tag = "sprites" ,
42
45
params(
43
46
( "signaling_system" = String , Path , description = "Signaling system name" ) ,
44
- ( "file_name" = String , Path , description = "Atlas file name (json or png) respecting map libre documentation " ) ,
47
+ ( "file_name" = String , Path , description = "File name (json, png or svg) " ) ,
45
48
) ,
46
49
responses(
47
50
( status = 200 , description = "Atlas image of config" ) ,
48
51
( status = 404 , description = "Signaling system not found" ) ,
49
52
) ,
50
53
) ]
51
- #[ get( "/{signaling_system}/{file_name:sprites(@[23]x)? \\ .(json|png)}" ) ]
54
+ #[ get( "/{signaling_system}/{file_name:[-_ @0-9A-Za-z]+ \\ .(json|png|svg )}" ) ]
52
55
async fn sprites ( path : Path < ( String , String ) > ) -> Result < NamedFile > {
53
56
let ( signaling_system, file_name) = path. into_inner ( ) ;
54
57
let sprite_configs = SpriteConfig :: load ( ) ;
55
58
if !sprite_configs. contains_key ( & signaling_system) {
56
59
return Err ( SpriteErrors :: UnknownSignalingSystem ( signaling_system) . into ( ) ) ;
57
60
}
58
61
let path = get_assets_path ( ) . join ( format ! ( "signal_sprites/{signaling_system}/{file_name}" ) ) ;
59
- assert ! ( path. is_file( ) ) ;
62
+ if !path. is_file ( ) {
63
+ return Err ( SpriteErrors :: FileNotFound ( file_name) . into ( ) ) ;
64
+ }
60
65
Ok ( NamedFile :: open ( path) . unwrap ( ) . use_last_modified ( false ) )
61
66
}
0 commit comments