33const translatorApi = module . exports ;
44
55translatorApi . translate = async function ( postData ) {
6- // Dynamically import node-fetch (ES module)
7- const fetch = ( await import ( 'node-fetch' ) ) . default ;
8-
9- const FLASK_URL = 'http://localhost:8080/translate' ;
10-
11- try {
12- const response = await fetch ( FLASK_URL , {
13- method : 'POST' ,
14- headers : {
15- 'Content-Type' : 'application/json' ,
16- } ,
17- body : JSON . stringify ( {
18- text : postData . content || ''
19- } )
20- } ) ;
21-
22- if ( ! response . ok ) {
23- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
24- }
25-
26- const data = await response . json ( ) ;
27-
28- // Return [isEnglish, translatedContent]
29- return [ data . is_english , data . translated || data . translated_content || '' ] ;
30- } catch ( error ) {
31- console . error ( 'Translation API error:' , error ) ;
32- // Return defaults on error - assume English, no translation
33- return [ true , '' ] ;
34- }
6+ // Dynamically import node-fetch (ES module)
7+ const fetch = ( await import ( 'node-fetch' ) ) . default ;
8+
9+ const FLASK_URL = 'http://localhost:8080/translate' ;
10+
11+ try {
12+ const response = await fetch ( FLASK_URL , {
13+ method : 'POST' ,
14+ headers : {
15+ 'Content-Type' : 'application/json' ,
16+ } ,
17+ body : JSON . stringify ( {
18+ text : postData . content || '' ,
19+ } ) ,
20+ } ) ;
21+
22+ if ( ! response . ok ) {
23+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
24+ }
25+
26+ const data = await response . json ( ) ;
27+
28+ // Return [isEnglish, translatedContent]
29+ return [ data . is_english , data . translated || data . translated_content || '' ] ;
30+ } catch ( error ) {
31+ console . error ( 'Translation API error:' , error ) ;
32+ // Return defaults on error - assume English, no translation
33+ return [ true , '' ] ;
34+ }
3535} ;
0 commit comments