mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-06 21:29:15 +02:00
Merge branch 'master' into develop
This commit is contained in:
@@ -194,4 +194,4 @@
|
||||
"url": "https://github.com/barisusakli"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,36 +7,32 @@ import { confirm } from 'bootbox';
|
||||
|
||||
const baseUrl = config.relative_path + '/api/v3';
|
||||
|
||||
function call(options, callback) {
|
||||
async function call(options, callback) {
|
||||
options.url = options.url.startsWith('/api') ?
|
||||
config.relative_path + options.url :
|
||||
baseUrl + options.url;
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
xhr(options, callback);
|
||||
xhr(options).then(result => callback(null, result), err => callback(err));
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
xhr(options, function (err, data) {
|
||||
if (err) {
|
||||
if (err.message === 'A valid login session was not found. Please log in and try again.') {
|
||||
return confirm('[[error:api.reauth-required]]', (ok) => {
|
||||
if (ok) {
|
||||
ajaxify.go('login');
|
||||
}
|
||||
});
|
||||
try {
|
||||
const result = await xhr(options);
|
||||
return result;
|
||||
} catch (err) {
|
||||
if (err.message === 'A valid login session was not found. Please log in and try again.') {
|
||||
return confirm('[[error:api.reauth-required]]', (ok) => {
|
||||
if (ok) {
|
||||
ajaxify.go('login');
|
||||
}
|
||||
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function xhr(options, cb) {
|
||||
async function xhr(options) {
|
||||
// Normalize body based on type
|
||||
const { url } = options;
|
||||
delete options.url;
|
||||
@@ -79,16 +75,14 @@ async function xhr(options, cb) {
|
||||
|
||||
if (!res.ok) {
|
||||
if (response) {
|
||||
return cb(new Error(isJSON ? response.status.message : response));
|
||||
throw new Error(isJSON ? response.status.message : response);
|
||||
}
|
||||
return cb(new Error(res.statusText));
|
||||
throw new Error(res.statusText);
|
||||
}
|
||||
|
||||
cb(null, (
|
||||
isJSON && response && response.hasOwnProperty('status') && response.hasOwnProperty('response') ?
|
||||
response.response :
|
||||
response
|
||||
));
|
||||
return isJSON && response && response.hasOwnProperty('status') && response.hasOwnProperty('response') ?
|
||||
response.response :
|
||||
response;
|
||||
}
|
||||
|
||||
export function get(route, data, onSuccess) {
|
||||
|
||||
@@ -106,7 +106,7 @@ async function checkPlugins() {
|
||||
current = plugins[suggestObj.package];
|
||||
suggested = suggestObj.version;
|
||||
|
||||
if (suggestObj.code === 'match-found' && semver.gt(suggested, current)) {
|
||||
if (suggestObj.code === 'match-found' && semver.valid(current) && semver.valid(suggested) && semver.gt(suggested, current)) {
|
||||
return {
|
||||
name: suggestObj.package,
|
||||
current: current,
|
||||
|
||||
Reference in New Issue
Block a user