@@ -335,7 +335,19 @@ const AssistServer = context => {
335
335
. then ( body => body . data [ 0 ] . url ? body . data [ 0 ] . url : Promise . reject ( new Error ( 'empty' ) ) )
336
336
. then ( link => runtime . preferenceReader . get ( 'CDN.redirect' ) ? link . replace ( / ( m \d + ?) (? ! c ) \. m u s i c \. 1 2 6 \. n e t / , '$1c.music.126.net' ) : link )
337
337
. then ( link => ( res . writeHead ( 302 , { location : url . pathname + '?' + queryify ( { url : link } ) } ) , res . end ( ) ) )
338
- . catch ( error => [ 'empty' ] . includes ( error . message ) ? ( res . writeHead ( 404 , { 'content-type' : 'audio/mpeg' } ) , res . end ( ) ) : error )
338
+ . catch ( error => [ 'empty' ] . includes ( error . message ) ? ( res . writeHead ( 404 , { 'content-type' : 'audio/*' } ) , res . end ( ) ) : error )
339
+ }
340
+ else if ( url . pathname === '/song/file' && query . path ) {
341
+ let file = decodeURIComponent ( urlParse ( query . path ) . pathname ) , meta = { }
342
+ file = process . platform === 'win32' ? file . replace ( / ^ \/ / , '' ) : file
343
+ try { meta = fs . statSync ( file ) }
344
+ catch ( error ) { return ( res . writeHead ( 404 , { 'content-type' : 'audio/*' } ) , res . end ( ) ) }
345
+ let [ start , end ] = ( headers [ 'range' ] || '' ) . split ( '-' )
346
+ start = parseInt ( start ) || 0
347
+ end = parseInt ( end ) || Infinity
348
+ const bytes = `bytes ${ start } -${ end === Infinity ? meta . size - 1 : end } /${ meta . size } `
349
+ res . writeHead ( headers [ 'range' ] ? 206 : 200 , { 'content-type' : 'audio/*' , 'content-range' : headers [ 'range' ] ? bytes : null } )
350
+ fs . createReadStream ( file , { start, end} ) . pipe ( res )
339
351
}
340
352
else {
341
353
res . socket . destroy ( )
0 commit comments