Merge branch 'master' into develop

This commit is contained in:
Barış Soner Uşaklı
2023-09-25 10:51:44 -04:00
3 changed files with 22 additions and 28 deletions

View File

@@ -194,4 +194,4 @@
"url": "https://github.com/barisusakli"
}
]
}
}

View File

@@ -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) {

View File

@@ -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,