@@ -11,6 +11,17 @@ function error(message: string): never {
1111 process . exit ( 1 ) ;
1212}
1313
14+ function parseInputFileParams ( input : string ) : { path : string , params : Record < string , string > } {
15+ const [ filePath , ...rawParams ] = input . split ( / (?< ! \\ ) ; \s * / ) ;
16+ const params : Record < string , string > = { } ;
17+ for ( const rawParam of rawParams ) {
18+ const equalsIndex = rawParam . indexOf ( "=" ) ;
19+ if ( equalsIndex === - 1 ) params [ rawParam . trim ( ) ] = "" ;
20+ else params [ rawParam . substring ( 0 , equalsIndex ) ] = rawParam . substring ( equalsIndex + 1 ) ;
21+ }
22+ return { path : filePath ! , params} ;
23+ }
24+
1425// Action inputs
1526const GH_INPUTS : Record < string , string > = JSON . parse ( process . env . GH_INPUTS ! ) ;
1627const GITHUB_TOKEN = process . env . GITHUB_TOKEN ! ;
@@ -33,11 +44,12 @@ else {
3344// Read the files
3445core . info ( "Reading files..." ) ;
3546const files = await Promise . all ( inputs . files . split ( "\n" ) . map ( async f => {
36- const hasMimeType = f . lastIndexOf ( "&" ) !== - 1 ;
37- const filePath = ( hasMimeType ? f . substring ( 0 , f . lastIndexOf ( "&" ) ) : f ) . trim ( ) ;
38- const mimeType = ( hasMimeType ? f . substring ( f . lastIndexOf ( "&" ) + 1 ) : "application/octet-stream" ) . trim ( ) . toLowerCase ( ) ;
47+ const { path : filePath , params} = parseInputFileParams ( f ) ;
48+ const mimeType = params [ "type" ] ?? "application/octet-stream" ;
49+ const fileName = params [ "filename" ] ?? path . basename ( filePath ) ;
50+
3951 const data = await fs . readFile ( filePath ) ;
40- core . info ( `Read file ${ filePath } (type ${ mimeType } , size ${ data . length } bytes )` ) ;
52+ core . info ( `Read file: ${ filePath } (type= ${ mimeType } ; name= ${ fileName } ; size= ${ data . length } )` ) ;
4153 return new File ( [ data ] , path . basename ( filePath ) , { type : mimeType } ) ;
4254} ) ) ;
4355
0 commit comments