mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-23 15:37:50 +01:00
Batch extension version checks
This commit is contained in:
parent
c5b3ce0d5c
commit
3c82d961bd
@ -586,7 +586,6 @@ function generateExtensionHtml(name, manifest, isActive, isDisabled, isExternal,
|
|||||||
const isUserAdmin = isAdmin();
|
const isUserAdmin = isAdmin();
|
||||||
const extensionIcon = getExtensionIcon();
|
const extensionIcon = getExtensionIcon();
|
||||||
const displayName = manifest.display_name;
|
const displayName = manifest.display_name;
|
||||||
let displayVersion = manifest.version ? ` v${manifest.version}` : '';
|
|
||||||
const externalId = name.replace('third-party', '');
|
const externalId = name.replace('third-party', '');
|
||||||
let originHtml = '';
|
let originHtml = '';
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
@ -632,7 +631,7 @@ function generateExtensionHtml(name, manifest, isActive, isDisabled, isExternal,
|
|||||||
${originHtml}
|
${originHtml}
|
||||||
<span class="${isActive ? 'extension_enabled' : isDisabled ? 'extension_disabled' : 'extension_missing'}">
|
<span class="${isActive ? 'extension_enabled' : isDisabled ? 'extension_disabled' : 'extension_missing'}">
|
||||||
<span class="extension_name">${DOMPurify.sanitize(displayName)}</span>
|
<span class="extension_name">${DOMPurify.sanitize(displayName)}</span>
|
||||||
<span class="extension_version">${displayVersion}</span>
|
<span class="extension_version"></span>
|
||||||
${modulesInfo}
|
${modulesInfo}
|
||||||
</span>
|
</span>
|
||||||
${isExternal ? '</a>' : ''}
|
${isExternal ? '</a>' : ''}
|
||||||
@ -1032,6 +1031,29 @@ export function doDailyExtensionUpdatesCheck() {
|
|||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const concurrencyLimit = 5;
|
||||||
|
let activeRequestsCount = 0;
|
||||||
|
const versionCheckQueue = [];
|
||||||
|
|
||||||
|
function enqueueVersionCheck(fn) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
versionCheckQueue.push(() => fn().then(resolve).catch(reject));
|
||||||
|
processVersionCheckQueue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function processVersionCheckQueue() {
|
||||||
|
if (activeRequestsCount >= concurrencyLimit || versionCheckQueue.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
activeRequestsCount++;
|
||||||
|
const fn = versionCheckQueue.shift();
|
||||||
|
fn().finally(() => {
|
||||||
|
activeRequestsCount--;
|
||||||
|
processVersionCheckQueue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a manual check for updates on all 3rd-party extensions.
|
* Performs a manual check for updates on all 3rd-party extensions.
|
||||||
* @param {AbortSignal} abortSignal Signal to abort the operation
|
* @param {AbortSignal} abortSignal Signal to abort the operation
|
||||||
@ -1041,7 +1063,7 @@ async function checkForUpdatesManual(abortSignal) {
|
|||||||
const promises = [];
|
const promises = [];
|
||||||
for (const id of Object.keys(manifests).filter(x => x.startsWith('third-party'))) {
|
for (const id of Object.keys(manifests).filter(x => x.startsWith('third-party'))) {
|
||||||
const externalId = id.replace('third-party', '');
|
const externalId = id.replace('third-party', '');
|
||||||
const promise = new Promise(async (resolve, reject) => {
|
const promise = enqueueVersionCheck(async () => {
|
||||||
try {
|
try {
|
||||||
const data = await getExtensionVersion(externalId, abortSignal);
|
const data = await getExtensionVersion(externalId, abortSignal);
|
||||||
const extensionBlock = document.querySelector(`.extension_block[data-name="${externalId}"]`);
|
const extensionBlock = document.querySelector(`.extension_block[data-name="${externalId}"]`);
|
||||||
@ -1072,10 +1094,8 @@ async function checkForUpdatesManual(abortSignal) {
|
|||||||
versionElement.textContent += ` (${branch}-${commitHash.substring(0, 7)})`;
|
versionElement.textContent += ` (${branch}-${commitHash.substring(0, 7)})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking for extension updates', error);
|
console.error('Error checking for extension updates', error);
|
||||||
reject();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
@ -1111,17 +1131,16 @@ async function checkForExtensionUpdates(force) {
|
|||||||
console.debug(`Skipping global extension: ${manifest.display_name} (${id}) for non-admin user`);
|
console.debug(`Skipping global extension: ${manifest.display_name} (${id}) for non-admin user`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manifest.auto_update && id.startsWith('third-party')) {
|
if (manifest.auto_update && id.startsWith('third-party')) {
|
||||||
const promise = new Promise(async (resolve, reject) => {
|
const promise = enqueueVersionCheck(async () => {
|
||||||
try {
|
try {
|
||||||
const data = await getExtensionVersion(id.replace('third-party', ''));
|
const data = await getExtensionVersion(id.replace('third-party', ''));
|
||||||
if (data.isUpToDate === false) {
|
if (!data.isUpToDate) {
|
||||||
updatesAvailable.push(manifest.display_name);
|
updatesAvailable.push(manifest.display_name);
|
||||||
}
|
}
|
||||||
resolve();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking for extension updates', error);
|
console.error('Error checking for extension updates', error);
|
||||||
reject();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user