mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-31 04:40:27 +01:00
* axios migration * controller tests * add missing deps * feeds * remove unused async * flags * locale-detect * messaging/middleware * remove log * meta * plugins * posts * search * topics/thumbs * user/emails * uploads.js * socket.io * cleaunup * test native fetch * cleanup * increase engine to 18 fix remaining tests * remove testing file * fix comments,typo * revert debug
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const nconf = require('nconf');
|
|
const winston = require('winston');
|
|
const crypto = require('crypto');
|
|
const cronJob = require('cron').CronJob;
|
|
|
|
const request = require('../request');
|
|
const pkg = require('../../package.json');
|
|
|
|
const meta = require('../meta');
|
|
|
|
module.exports = function (Plugins) {
|
|
Plugins.startJobs = function () {
|
|
new cronJob('0 0 0 * * *', (async () => {
|
|
await Plugins.submitUsageData();
|
|
}), null, true);
|
|
};
|
|
|
|
Plugins.submitUsageData = async function () {
|
|
if (!meta.config.submitPluginUsage || !Plugins.loadedPlugins.length || global.env !== 'production') {
|
|
return;
|
|
}
|
|
|
|
const hash = crypto.createHash('sha256');
|
|
hash.update(nconf.get('url'));
|
|
const url = `${nconf.get('registry') || 'https://packages.nodebb.org'}/api/v1/plugin/usage`;
|
|
try {
|
|
const { response, body } = await request.post(url, {
|
|
body: {
|
|
id: hash.digest('hex'),
|
|
version: pkg.version,
|
|
plugins: Plugins.loadedPlugins,
|
|
},
|
|
timeout: 5000,
|
|
});
|
|
|
|
if (!response.ok) {
|
|
winston.error(`[plugins.submitUsageData] received ${response.status} ${body}`);
|
|
}
|
|
} catch (err) {
|
|
winston.error(err.stack);
|
|
}
|
|
};
|
|
};
|