Merge pull request #3173 from ceruleandeep/redesign-extension-manager

Redesign extension manager
This commit is contained in:
Cohee 2024-12-11 17:43:57 +02:00 committed by GitHub
commit 003d17b2c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 5 deletions

2
.gitignore vendored
View File

@ -50,3 +50,5 @@ public/css/user.css
/default/scaffold
public/scripts/extensions/third-party
/certs
.aider*
.env

View File

@ -770,7 +770,7 @@ async function showExtensionsDetails() {
/**
* Handles the click event for the update button of an extension.
* This function makes a POST request to '/update_extension' with the extension's name.
* This function makes a POST request to '/api/extensions/update' with the extension's name.
* If the extension is already up to date, it displays a success message.
* If the extension is not up to date, it updates the extension and displays a success message with the new commit hash.
*/
@ -783,8 +783,11 @@ async function onUpdateClick() {
return;
}
$(this).find('i').addClass('fa-spin');
const icon = $(this).find('i');
icon.addClass('fa-spin');
await updateExtension(extensionName, false);
// updateExtension eats the error, but we can at least stop the spinner
icon.removeClass('fa-spin');
}
/**
@ -803,10 +806,17 @@ async function updateExtension(extensionName, quiet) {
}),
});
if (!response.ok) {
const text = await response.text();
toastr.error(text || response.statusText, t`Extension update failed`, { timeOut: 5000 });
console.error('Extension update failed', response.status, response.statusText, text);
return;
}
const data = await response.json();
if (!quiet) {
showExtensionsDetails();
await showExtensionsDetails();
}
if (data.isUpToDate) {

View File

@ -224,12 +224,20 @@ router.post('/version', jsonParser, async (request, response) => {
return response.status(404).send(`Directory does not exist at ${extensionPath}`);
}
let currentCommitHash;
try {
currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
} catch (error) {
// it is not a git repo, or has no commits yet, or is a bare repo
// not possible to update it, most likely can't get the branch name either
return response.send({ currentBranchName: null, currentCommitHash, isUpToDate: true, remoteUrl: null });
}
const currentBranch = await git.cwd(extensionPath).branch();
// get only the working branch
const currentBranchName = currentBranch.current;
await git.cwd(extensionPath).fetch('origin');
const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
console.log(currentBranch, currentCommitHash);
console.log(extensionName, currentBranchName, currentCommitHash);
const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath);
return response.send({ currentBranchName, currentCommitHash, isUpToDate, remoteUrl });