2022-03-17 05:50:24 +01:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const path = require('path');
|
|
|
|
const os = require('os');
|
|
|
|
const isCI = require('is-ci');
|
|
|
|
const pkg = require('../package.json');
|
|
|
|
|
|
|
|
const dest = path.resolve(__dirname, '../.next/cache/umami.json');
|
2023-03-23 22:01:15 +01:00
|
|
|
const url = 'https://telemetry.umami.is/api/send';
|
2022-03-17 05:50:24 +01:00
|
|
|
|
2022-03-19 06:39:39 +01:00
|
|
|
async function sendTelemetry(action) {
|
2022-03-17 05:50:24 +01:00
|
|
|
let json = {};
|
|
|
|
|
|
|
|
try {
|
|
|
|
json = await fs.readJSON(dest);
|
|
|
|
} catch {
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
|
2022-04-04 23:36:42 +02:00
|
|
|
try {
|
|
|
|
await fs.writeJSON(dest, { version: pkg.version });
|
|
|
|
} catch {
|
|
|
|
// Ignore
|
|
|
|
}
|
2022-03-19 06:39:39 +01:00
|
|
|
|
|
|
|
const { default: isDocker } = await import('is-docker');
|
|
|
|
const { default: fetch } = await import('node-fetch');
|
2022-03-19 06:52:42 +01:00
|
|
|
const upgrade = json.version !== undefined && json.version !== pkg.version;
|
2022-03-19 06:39:39 +01:00
|
|
|
|
|
|
|
const payload = {
|
|
|
|
action,
|
|
|
|
version: pkg.version,
|
|
|
|
node: process.version,
|
|
|
|
platform: os.platform(),
|
|
|
|
arch: os.arch(),
|
|
|
|
os: `${os.type()} (${os.version()})`,
|
|
|
|
docker: isDocker(),
|
|
|
|
ci: isCI,
|
2022-03-19 06:52:42 +01:00
|
|
|
prev: json.version,
|
|
|
|
upgrade,
|
2022-03-19 06:39:39 +01:00
|
|
|
};
|
|
|
|
|
2022-04-05 00:14:26 +02:00
|
|
|
try {
|
|
|
|
await fetch(url, {
|
|
|
|
method: 'post',
|
|
|
|
cache: 'no-cache',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify(payload),
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
// Ignore
|
|
|
|
}
|
2022-03-17 05:50:24 +01:00
|
|
|
}
|
|
|
|
|
2022-03-19 05:57:58 +01:00
|
|
|
module.exports = {
|
|
|
|
sendTelemetry,
|
|
|
|
};
|