m / curl.js
zzmal's picture
Update curl.js
c8d32f7 verified
import fetch from 'node-fetch';
import { exec } from 'child_process';
// 定义要请求的URL
const url0 = 'https://zzmal-m.hf.space';
const url1 = 'https://zzmal-al.hf.space';
// 定义函数来发送请求
async function fetchData() {
try {
// 发送GET请求
let response = await fetch(url0);
// 检查响应状态码
if (response.ok) {
console.log('请求成功: ', url0);
} else {
console.error('请求失败: ', response.statusText);
}
response = await fetch(url1);
// 检查响应状态码
if (response.ok) {
console.log('请求成功: ', url1);
} else {
console.error('请求失败: ', response.statusText);
}
} catch (error) {
console.error('出现错误:', error.message);
}
}
// 定义函数来执行ping操作
function performPing() {
// 执行ping操作
exec('ping -c 1 zzmal-m.hf.space', (err, stdout, stderr) => {
if (err) {
console.error('ping失败: ', err);
return;
}
console.log('ping结果: ', stdout);
});
exec('ping -c 1 zzmal-mm.hf.space', (err, stdout, stderr) => {
if (err) {
console.error('ping失败: ', err);
return;
}
console.log('ping结果: ', stdout);
});
}
// 每5天执行一次请求
setInterval(() => {
fetchData();
}, 5 * 24 * 60 * 60 * 888); // 每5天左右执行一次
// 启动时立即执行一次
fetchData();