1414
1515use std:: any;
1616use std:: borrow:: Cow ;
17+ use std:: collections:: HashMap ;
18+ use std:: error:: Error ;
1719use std:: future:: Future ;
1820use std:: io:: Write ;
1921use std:: path:: { Component , PathBuf } ;
@@ -145,6 +147,7 @@ struct DirectoryPath {
145147struct ScanPaths {
146148 directory : DirectoryPath ,
147149 subdirectory : Subdirectory ,
150+ metadata : HashMap < String , String > ,
148151}
149152
150153/// GraphQL type to provide current configuration for an instrument
@@ -153,6 +156,12 @@ struct CurrentConfiguration {
153156 high_file : Option < u32 > ,
154157}
155158
159+ #[ derive( Debug , InputObject ) ]
160+ struct MetaKeyValue {
161+ key : String ,
162+ value : String ,
163+ }
164+
156165/// Error to be returned when a path contains non-unicode characters
157166#[ derive( Debug , Display , Error ) ]
158167#[ display( "Path contains non-unicode characters" ) ]
@@ -308,6 +317,12 @@ impl FieldSource<ScanField> for ScanPaths {
308317 ScanField :: Subdirectory => self . subdirectory . to_string ( ) . into ( ) ,
309318 ScanField :: ScanNumber => self . directory . info . scan_number ( ) . to_string ( ) . into ( ) ,
310319 ScanField :: Directory ( dir) => self . directory . resolve ( dir) ,
320+ ScanField :: Custom ( key) => self
321+ . metadata
322+ . get ( key)
323+ . map ( |s| s. as_str ( ) )
324+ . unwrap_or ( "" )
325+ . into ( ) ,
311326 }
312327 }
313328}
@@ -397,6 +412,7 @@ impl Mutation {
397412 instrument : String ,
398413 instrument_session : String ,
399414 sub : Option < Subdirectory > ,
415+ meta : Option < Vec < MetaKeyValue > > ,
400416 ) -> async_graphql:: Result < ScanPaths > {
401417 check_auth ( ctx, |policy, token| {
402418 policy. check_access ( token, & instrument, & instrument_session)
@@ -420,11 +436,18 @@ impl Mutation {
420436 warn ! ( "Failed to increment tracker file: {e}" ) ;
421437 }
422438
439+ let metadata = meta
440+ . into_iter ( )
441+ . flatten ( )
442+ . map ( |kv| ( kv. key , kv. value ) )
443+ . collect ( ) ;
444+
423445 Ok ( ScanPaths {
424446 directory : DirectoryPath {
425447 instrument_session,
426448 info : next_scan,
427449 } ,
450+ metadata,
428451 subdirectory : sub. unwrap_or_default ( ) ,
429452 } )
430453 }
0 commit comments