@@ -10,16 +10,22 @@ import path from 'path';
1010import { pipeline } from 'stream/promises' ;
1111import sanitize from 'sanitize-filename' ;
1212import internal from 'stream' ;
13+ import { app } from 'electron' ;
1314
1415export class RequestService {
1516 private static instance : RequestService ;
1617 private preferredFamily : number | undefined = undefined ;
18+ private readonly baseHeaders = {
19+ 'User-Agent' : `BSManager/${ app . getVersion ( ) } (Electron/${ process . versions . electron } Chrome/${ process . versions . chrome } Node/${ process . versions . node } )` ,
20+ }
21+
1722
1823 public static getInstance ( ) : RequestService {
1924 if ( ! RequestService . instance ) {
2025 RequestService . instance = new RequestService ( ) ;
2126 }
2227 return RequestService . instance ;
28+
2329 }
2430
2531 private constructor ( ) { }
@@ -32,7 +38,7 @@ export class RequestService {
3238 try {
3339
3440 // @ts -ignore (ESM is not well supported in this project, We need to move out electron-react-boilerplate, and use Vite)
35- const res = await got ( url , { dnsLookupIpVersion : family , responseType : 'json' } ) ;
41+ const res = await got ( url , { dnsLookupIpVersion : family , responseType : 'json' , headers : this . baseHeaders } ) ;
3642 this . preferredFamily = family ;
3743 return { data : res . body as T , headers : res . headers } ;
3844 } catch ( err ) {
@@ -67,7 +73,7 @@ export class RequestService {
6773 let file : WriteStream | undefined ;
6874
6975 // @ts -ignore (ESM is not well supported in this project, We need to move out electron-react-boilerplate, and use Vite)
70- stream = got . stream ( url , { dnsLookupIpVersion : family } ) ;
76+ stream = got . stream ( url , { dnsLookupIpVersion : family , headers : this . baseHeaders } ) ;
7177
7278 stream . on ( 'response' , ( response ) => {
7379 this . preferredFamily = family ;
@@ -130,6 +136,7 @@ export class RequestService {
130136 data : null ,
131137 } ;
132138
139+ const headers = { ...this . baseHeaders , ...( options ?. headers ?? { } ) } ;
133140 const familiesToTry = this . preferredFamily ? [ this . preferredFamily , this . preferredFamily === 4 ? 6 : 4 ] : [ 4 , 6 ] ;
134141
135142 let attempt = 0 ;
@@ -142,9 +149,8 @@ export class RequestService {
142149 }
143150
144151 const family = familiesToTry [ attempt ++ ] ;
145-
146152 // @ts -ignore (ESM is not well supported in this project, We need to move out electron-react-boilerplate, and use Vite)
147- stream = got . stream ( url , { dnsLookupIpVersion : family , ...( options ?? { } ) } ) ;
153+ stream = got . stream ( url , { dnsLookupIpVersion : family , ...( options ?? { } ) , headers } ) ;
148154
149155 let data = Buffer . alloc ( 0 ) ;
150156 let response : IncomingMessage ;
0 commit comments