1414
1515use std:: any;
1616use std:: borrow:: Cow ;
17+ use std:: collections:: HashMap ;
1718use std:: error:: Error ;
1819use std:: fmt:: Display ;
1920use std:: future:: Future ;
@@ -147,6 +148,7 @@ struct VisitPath {
147148struct ScanPaths {
148149 visit : VisitPath ,
149150 subdirectory : Subdirectory ,
151+ metadata : HashMap < String , String > ,
150152}
151153
152154/// GraphQL type to provide current configuration for a beamline
@@ -155,6 +157,12 @@ struct CurrentConfiguration {
155157 high_file : Option < u32 > ,
156158}
157159
160+ #[ derive( Debug , InputObject ) ]
161+ struct MetaKeyValue {
162+ key : String ,
163+ value : String ,
164+ }
165+
158166/// Error to be returned when a path contains non-unicode characters
159167#[ derive( Debug ) ]
160168struct NonUnicodePath ;
@@ -301,6 +309,12 @@ impl FieldSource<ScanField> for ScanPaths {
301309 ScanField :: Subdirectory => self . subdirectory . to_string ( ) . into ( ) ,
302310 ScanField :: ScanNumber => self . visit . info . scan_number ( ) . to_string ( ) . into ( ) ,
303311 ScanField :: Beamline ( bl) => self . visit . resolve ( bl) ,
312+ ScanField :: Custom ( key) => self
313+ . metadata
314+ . get ( key)
315+ . map ( |s| s. as_str ( ) )
316+ . unwrap_or ( "" )
317+ . into ( ) ,
304318 }
305319 }
306320}
@@ -399,6 +413,7 @@ impl Mutation {
399413 beamline : String ,
400414 visit : String ,
401415 sub : Option < Subdirectory > ,
416+ meta : Option < Vec < MetaKeyValue > > ,
402417 ) -> async_graphql:: Result < ScanPaths > {
403418 check_auth ( ctx, |policy, token| {
404419 policy. check_access ( token, & beamline, & visit)
@@ -422,11 +437,18 @@ impl Mutation {
422437 warn ! ( "Failed to increment tracker file: {e}" ) ;
423438 }
424439
440+ let metadata = meta
441+ . into_iter ( )
442+ . flatten ( )
443+ . map ( |kv| ( kv. key , kv. value ) )
444+ . collect ( ) ;
445+
425446 Ok ( ScanPaths {
426447 visit : VisitPath {
427448 visit,
428449 info : next_scan,
429450 } ,
451+ metadata,
430452 subdirectory : sub. unwrap_or_default ( ) ,
431453 } )
432454 }
0 commit comments