@@ -5,11 +5,11 @@ export class Request {
5
5
constructor ( o = { } ) {
6
6
this . proxy = o . proxy ;
7
7
this . cookie = o . cookie ;
8
- this . timeout = o . timeout || 30000 ; // 默认30秒超时
8
+ this . timeout = o . timeout || 30000 ;
9
9
this . headers = {
10
10
'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' ,
11
11
'accept' : 'text/html,application/json,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8' ,
12
- 'accept-language' : 'zh-CN,zh;q=0.9, en;q=0.8 ' ,
12
+ 'accept-language' : 'en-US, en;q=0.9 ' ,
13
13
'cache-control' : 'no-cache' ,
14
14
'pragma' : 'no-cache' ,
15
15
'sec-ch-ua' : '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"' ,
@@ -20,18 +20,22 @@ export class Request {
20
20
'sec-fetch-site' : 'none' ,
21
21
'sec-fetch-user' : '?1' ,
22
22
'upgrade-insecure-requests' : '1' ,
23
- 'x-requested-with' : 'XMLHttpRequest' ,
24
- 'x-instagram-ajax' : '1' ,
25
- 'referer' : 'https://www.instagram.com/'
23
+ 'x-ig-app-id' : '936619743392459' ,
24
+ 'x-requested-with' : 'XMLHttpRequest'
26
25
} ;
26
+
27
+ if ( ! this . cookie ) {
28
+ this . cookie = 'ig_did=...; csrftoken=...; mid=...; ds_user_id=...; sessionid=...' ;
29
+ }
27
30
}
28
31
29
32
async fetch ( url , options = { } ) {
30
33
const reqOptions = {
31
34
...options ,
32
35
headers : {
33
36
...this . headers ,
34
- ...options . headers
37
+ ...options . headers ,
38
+ cookie : this . cookie
35
39
} ,
36
40
timeout : this . timeout
37
41
} ;
@@ -41,13 +45,12 @@ export class Request {
41
45
reqOptions . agent = new HttpsProxyAgent ( this . proxy ) ;
42
46
}
43
47
44
- if ( this . cookie ) {
45
- reqOptions . headers . cookie = this . cookie ;
46
- }
47
-
48
48
try {
49
49
const response = await fetch ( url , reqOptions ) ;
50
50
if ( ! response . ok ) {
51
+ if ( response . status === 401 ) {
52
+ throw new Error ( 'Instagram认证失败,请检查cookie是否有效' ) ;
53
+ }
51
54
throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
52
55
}
53
56
return response ;
0 commit comments