mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-13 01:15:47 +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
This commit is contained in:
committed by
GitHub
parent
451430006e
commit
c15bdd4cf0
@@ -6,8 +6,8 @@ const winston = require('winston');
|
||||
const semver = require('semver');
|
||||
const nconf = require('nconf');
|
||||
const chalk = require('chalk');
|
||||
const request = require('request-promise-native');
|
||||
|
||||
const request = require('../request');
|
||||
const user = require('../user');
|
||||
const posts = require('../posts');
|
||||
|
||||
@@ -153,10 +153,10 @@ Plugins.reloadRoutes = async function (params) {
|
||||
|
||||
Plugins.get = async function (id) {
|
||||
const url = `${nconf.get('registry') || 'https://packages.nodebb.org'}/api/v1/plugins/${id}`;
|
||||
const body = await request(url, {
|
||||
json: true,
|
||||
});
|
||||
|
||||
const { response, body } = await request.get(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`[[error:unable-to-load-plugin, ${id}]]`);
|
||||
}
|
||||
let normalised = await Plugins.normalise([body ? body.payload : {}]);
|
||||
normalised = normalised.filter(plugin => plugin.id === id);
|
||||
return normalised.length ? normalised[0] : undefined;
|
||||
@@ -169,9 +169,10 @@ Plugins.list = async function (matching) {
|
||||
const { version } = require(paths.currentPackage);
|
||||
const url = `${nconf.get('registry') || 'https://packages.nodebb.org'}/api/v1/plugins${matching !== false ? `?version=${version}` : ''}`;
|
||||
try {
|
||||
const body = await request(url, {
|
||||
json: true,
|
||||
});
|
||||
const { response, body } = await request.get(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`[[error:unable-to-load-plugins-from-nbbpm]]`);
|
||||
}
|
||||
return await Plugins.normalise(body);
|
||||
} catch (err) {
|
||||
winston.error(`Error loading ${url}`, err);
|
||||
@@ -181,9 +182,11 @@ Plugins.list = async function (matching) {
|
||||
|
||||
Plugins.listTrending = async () => {
|
||||
const url = `${nconf.get('registry') || 'https://packages.nodebb.org'}/api/v1/analytics/top/week`;
|
||||
return await request(url, {
|
||||
json: true,
|
||||
});
|
||||
const { response, body } = await request.get(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`[[error:unable-to-load-trending-plugins]]`);
|
||||
}
|
||||
return body;
|
||||
};
|
||||
|
||||
Plugins.normalise = async function (apiReturn) {
|
||||
|
||||
@@ -7,8 +7,8 @@ const nconf = require('nconf');
|
||||
const os = require('os');
|
||||
const cproc = require('child_process');
|
||||
const util = require('util');
|
||||
const request = require('request-promise-native');
|
||||
|
||||
const request = require('../request');
|
||||
const db = require('../database');
|
||||
const meta = require('../meta');
|
||||
const pubsub = require('../pubsub');
|
||||
@@ -74,12 +74,10 @@ module.exports = function (Plugins) {
|
||||
};
|
||||
|
||||
Plugins.checkWhitelist = async function (id, version) {
|
||||
const body = await request({
|
||||
method: 'GET',
|
||||
url: `https://packages.nodebb.org/api/v1/plugins/${encodeURIComponent(id)}`,
|
||||
json: true,
|
||||
});
|
||||
|
||||
const { response, body } = await request.get(`https://packages.nodebb.org/api/v1/plugins/${encodeURIComponent(id)}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`[[error:cant-connect-to-nbbpm]]`);
|
||||
}
|
||||
if (body && body.code === 'ok' && (version === 'latest' || body.payload.valid.includes(version))) {
|
||||
return;
|
||||
}
|
||||
@@ -88,11 +86,10 @@ module.exports = function (Plugins) {
|
||||
};
|
||||
|
||||
Plugins.suggest = async function (pluginId, nbbVersion) {
|
||||
const body = await request({
|
||||
method: 'GET',
|
||||
url: `https://packages.nodebb.org/api/v1/suggest?package=${encodeURIComponent(pluginId)}&version=${encodeURIComponent(nbbVersion)}`,
|
||||
json: true,
|
||||
});
|
||||
const { response, body } = await request.get(`https://packages.nodebb.org/api/v1/suggest?package=${encodeURIComponent(pluginId)}&version=${encodeURIComponent(nbbVersion)}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`[[error:cant-connect-to-nbbpm]]`);
|
||||
}
|
||||
return body;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,48 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
const nconf = require('nconf');
|
||||
const request = require('request');
|
||||
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 * * *', (() => {
|
||||
Plugins.submitUsageData();
|
||||
new cronJob('0 0 0 * * *', (async () => {
|
||||
await Plugins.submitUsageData();
|
||||
}), null, true);
|
||||
};
|
||||
|
||||
Plugins.submitUsageData = function (callback) {
|
||||
callback = callback || function () {};
|
||||
Plugins.submitUsageData = async function () {
|
||||
if (!meta.config.submitPluginUsage || !Plugins.loadedPlugins.length || global.env !== 'production') {
|
||||
return callback();
|
||||
return;
|
||||
}
|
||||
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(nconf.get('url'));
|
||||
request.post(`${nconf.get('registry') || 'https://packages.nodebb.org'}/api/v1/plugin/usage`, {
|
||||
form: {
|
||||
id: hash.digest('hex'),
|
||||
version: pkg.version,
|
||||
plugins: Plugins.loadedPlugins,
|
||||
},
|
||||
timeout: 5000,
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
winston.error(err.stack);
|
||||
return callback(err);
|
||||
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}`);
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
winston.error(`[plugins.submitUsageData] received ${res.statusCode} ${body}`);
|
||||
callback(new Error(`[[error:nbbpm-${res.statusCode}]]`));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
winston.error(err.stack);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user