feat: umami 统计追踪

This commit is contained in:
手瓜一十雪
2024-12-29 14:39:17 +08:00
parent 4ac7a25afb
commit 3b86d3c632
4 changed files with 56 additions and 4 deletions

41
src/common/umami.ts Normal file
View File

@@ -0,0 +1,41 @@
import https from 'node:https';
import { napCatVersion } from './version';
export class umamiTrace {
static trackEvent(eventName: string, info?: string) {
const StatesData = {
type: 'event',
payload: {
'website': '596cbbb2-1740-4373-a807-cf3d0637bfa7',
'hostname': 'trace.napneko.icu',
'language': process.env.LANG || 'en-US',
'title': 'NapCat ' + napCatVersion,
'url': '/' + napCatVersion + '/' + eventName,
'referrer': 'https://trace.napneko.icu/' + napCatVersion,
'info': info
}
};
let request = https.request({
hostname: '104.19.42.72',// 固定 IP
port: 443,
path: '/api/send',
method: 'POST',
headers: {
"Host": "umami.napneko.icu",
"Content-Type": "application/json",
"User-Agent": `Mozilla/5.0 Umami/${process.version}`
}
}, (res) => {
res.on('error', (error) => {
});
res.on('data', (data) => {
});
});
request.write(JSON.stringify(StatesData));
request.end();
}
}