@@ -10,30 +10,13 @@ function getApi(api?: 'google' | 'hf' | 'openai') {
1010 if ( typeof api === 'string' ) {
1111 api = api . toLowerCase ( ) as 'google' | 'hf' | 'openai' ;
1212 }
13+ const defaultAPI = config . use . DEFAULT ;
1314
14- const useGoogle = api === 'google' || ( ! api && config . use . GOOGLE ) ;
15- const useHf = api === 'hf' || ( ! api && config . use . HF ) ;
16- const useOpenai = api === 'openai' || ( ! api && config . use . OPENAI ) ;
17-
18- if ( useGoogle ) {
19- return {
20- summarize : google . summarize ,
21- store : google . store ,
22- search : google . search ,
23- } ;
24- } else if ( useHf ) {
25- return {
26- summarize : hf . summarize ,
27- store : hf . store ,
28- search : hf . search ,
29- } ;
30- } else {
31- return {
32- summarize : openai . summarize ,
33- store : openai . store ,
34- search : openai . search ,
35- } ;
36- }
15+ return {
16+ google,
17+ hf,
18+ openai,
19+ } [ api ?? defaultAPI ] as typeof openai ;
3720}
3821
3922const defaultApi = getApi ( ) ;
@@ -77,24 +60,23 @@ async function search({
7760
7861router . post ( '/videos' , async ( req , res ) => {
7962 const { videos } = req . body as { videos : string [ ] } ;
80- const useApi = req . headers [ 'x-use-api' ] as
81- | 'google'
82- | 'hf'
83- | 'openai'
84- | undefined ;
85- const api = getApi ( useApi ) ;
63+ const apis : [ 'google' , 'hf' , 'openai' ] = [ 'google' , 'hf' , 'openai' ] ;
8664
8765 try {
88- await loadVideos ( { api, videos } ) ;
66+ await Promise . all (
67+ apis . map ( ( api ) => {
68+ return loadVideos ( { api : getApi ( api ) , videos } ) ;
69+ } ) ,
70+ ) ;
8971
9072 res . status ( 200 ) . json ( { message : 'Videos loaded' } ) ;
9173 } catch ( e ) {
92- log . error ( 'Unexpected error in /videos/load ' , {
74+ log . error ( 'Unexpected error in /videos' , {
9375 error : {
9476 message : ( e as Error ) . message ,
9577 stack : ( e as Error ) . stack ,
9678 } ,
97- location : 'router.videos.google.load ' ,
79+ location : 'router.videos' ,
9880 } ) ;
9981
10082 res . status ( 500 ) . json ( { error : ( e as Error ) . message } ) ;
0 commit comments