forked from selfboot/ai_gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit-to-bing.mjs
More file actions
80 lines (67 loc) · 1.99 KB
/
submit-to-bing.mjs
File metadata and controls
80 lines (67 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import fetch from 'node-fetch';
const DOMAIN = 'gallery.selfboot.cn';
const BING_KEY = '90d513c720ec40e3a57f488239db260c';
const KEY_LOCATION = `https://${DOMAIN}/${BING_KEY}.txt`;
async function submitToBing(urls) {
if (!urls || urls.length === 0) {
console.log('没有URL需要提交');
return;
}
console.log('准备提交以下URL到Bing:', urls);
const payload = {
host: DOMAIN,
key: BING_KEY,
keyLocation: KEY_LOCATION,
urlList: urls
};
try {
console.log('提交payload:', payload);
const response = await fetch('https://api.indexnow.org/IndexNow', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify(payload)
});
const status = response.status;
console.log(`提交状态码: ${status}`);
switch (status) {
case 200:
console.log('URL提交成功!');
break;
case 400:
console.error('提交格式错误');
break;
case 403:
console.error('API密钥无效');
break;
case 422:
console.error('URL不属于指定域名或密钥格式不匹配');
break;
case 429:
console.error('请求过于频繁,可能被视为垃圾请求');
break;
default:
console.error(`未知错误: ${status}`);
}
} catch (error) {
console.error('提交过程中发生错误:', error);
}
}
async function submitNewUrlsToBing() {
console.log('开始获取今天更新的页面URL...');
const { getRecentPageUrls } = await import('./track-page-changes.mjs');
const urls = await getRecentPageUrls();
if (urls.length > 0) {
await submitToBing(urls);
} else {
console.log('今天没有更新的页面,不需要提交');
}
}
// 直接执行主函数
console.log('开始执行 bing index now脚本...');
submitNewUrlsToBing().catch((error) => {
console.error('执行过程中发生错误:', error);
process.exit(1);
});
export { submitToBing };