xiaoju-survey/web/report.ts
luch 351f18f255
[Feature] 新增暂停功能以及多表字段升级 (#434)
* feat:新增暂停功能  (#416)

* feat:新增暂停功能

* feat: 修改状态相关功能 (#433)

Co-authored-by: luchunhui <luchunhui@didiglobal.com>

* fix: 修改刷数据逻辑错误和环境变量问题

* fix: 解决lint问题

---------

Co-authored-by: chaorenluo <1243357953@qq.com>
Co-authored-by: luchunhui <luchunhui@didiglobal.com>
2024-09-27 19:52:01 +08:00

48 lines
1.0 KiB
TypeScript

import fs from 'fs-extra'
const fsa = fs.promises
process.env.XIAOJU_SURVEY_REPORT = 'true'
const readData = async (pkg: string) => {
const id = new Date().getTime().toString()
try {
if (!fs.existsSync(pkg)) {
return {
type: 'web',
name: '',
version: '',
description: '',
id,
msg: '文件不存在'
}
}
const data = await fsa.readFile(pkg, 'utf8').catch((e) => e)
const { name, version, description } = JSON.parse(data)
return { type: 'web', name, version, description, id }
} catch (error) {
return error
}
}
const report = async () => {
if (!process.env.XIAOJU_SURVEY_REPORT) {
return
}
const res = await readData('./package.json')
// 上报
fetch &&
fetch('https://xiaojusurveysrc.didi.cn/reportSourceData', {
method: 'POST',
headers: {
Accept: 'application/json, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(res)
}).catch(() => {})
}
report()