mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add clickable names to go to repos
This commit is contained in:
@@ -382,25 +382,35 @@ async function generateExtensionHtml(name, manifest, isActive, isDisabled, isExt
|
|||||||
const displayName = manifest.display_name;
|
const displayName = manifest.display_name;
|
||||||
let displayVersion = manifest.version ? ` v${manifest.version}` : "";
|
let displayVersion = manifest.version ? ` v${manifest.version}` : "";
|
||||||
let isUpToDate = true;
|
let isUpToDate = true;
|
||||||
|
let updateButton = '';
|
||||||
|
let originHtml = '';
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
let data = await getExtensionVersion(name.replace('third-party', ''));
|
let data = await getExtensionVersion(name.replace('third-party', ''));
|
||||||
let branch = data.currentBranchName;
|
let branch = data.currentBranchName;
|
||||||
let commitHash = data.currentCommitHash;
|
let commitHash = data.currentCommitHash;
|
||||||
|
let origin = data.remoteUrl
|
||||||
isUpToDate = data.isUpToDate;
|
isUpToDate = data.isUpToDate;
|
||||||
displayVersion = ` (${branch}-${commitHash.substring(0, 7)})`;
|
displayVersion = ` (${branch}-${commitHash.substring(0, 7)})`;
|
||||||
|
updateButton = isUpToDate ?
|
||||||
|
`<span class="update-button"><button class="btn_update menu_button" data-name="${name.replace('third-party', '')}" title="Up to date"><i class="fa-solid fa-code-commit"></i></button></span>` :
|
||||||
|
`<span class="update-button"><button class="btn_update menu_button" data-name="${name.replace('third-party', '')}" title="Update available"><i class="fa-solid fa-download"></i></button></span>`;
|
||||||
|
originHtml = `<a href="${origin}" target="_blank" rel="noopener noreferrer">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let toggleElement = isActive || isDisabled ?
|
let toggleElement = isActive || isDisabled ?
|
||||||
`<input type="checkbox" title="Click to toggle" data-name="${name}" class="${isActive ? 'toggle_disable' : 'toggle_enable'} ${checkboxClass}" ${isActive ? 'checked' : ''}>` :
|
`<input type="checkbox" title="Click to toggle" data-name="${name}" class="${isActive ? 'toggle_disable' : 'toggle_enable'} ${checkboxClass}" ${isActive ? 'checked' : ''}>` :
|
||||||
`<input type="checkbox" title="Cannot enable extension" data-name="${name}" class="extension_missing ${checkboxClass}" disabled>`;
|
`<input type="checkbox" title="Cannot enable extension" data-name="${name}" class="extension_missing ${checkboxClass}" disabled>`;
|
||||||
|
|
||||||
|
// if external, wrap the name in a link to the repo
|
||||||
|
|
||||||
let updateButton = isExternal && !isUpToDate ? `<button class="btn_update" data-name="${name.replace('third-party', '')}">Update</button>` : '';
|
|
||||||
let extensionHtml = `<hr>
|
let extensionHtml = `<hr>
|
||||||
<h4>
|
<h4>
|
||||||
<span class="update-button">${updateButton}</span>
|
${updateButton}
|
||||||
|
${originHtml}
|
||||||
<span class="${isActive ? "extension_enabled" : isDisabled ? "extension_disabled" : "extension_missing"}">
|
<span class="${isActive ? "extension_enabled" : isDisabled ? "extension_disabled" : "extension_missing"}">
|
||||||
${DOMPurify.sanitize(displayName)}${displayVersion}
|
${DOMPurify.sanitize(displayName)}${displayVersion}
|
||||||
</span>
|
</span>
|
||||||
|
${isExternal ? '</a>' : ''}
|
||||||
<span style="float:right;">${toggleElement}</span>
|
<span style="float:right;">${toggleElement}</span>
|
||||||
</h4>`;
|
</h4>`;
|
||||||
|
|
||||||
@@ -488,8 +498,7 @@ async function onUpdateClick() {
|
|||||||
console.log('Extension updated');
|
console.log('Extension updated');
|
||||||
toastr.success(`Extension updated to ${data.shortCommitHash}`);
|
toastr.success(`Extension updated to ${data.shortCommitHash}`);
|
||||||
}
|
}
|
||||||
$(this).text(data.shortCommitHash);
|
showExtensionsDetails();
|
||||||
console.log(data);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
}
|
}
|
||||||
|
@@ -3804,7 +3804,7 @@ input.extension_missing[type="checkbox"] {
|
|||||||
|
|
||||||
.update-button {
|
.update-button {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
/* Adjust the value as needed */
|
display: inline-flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* possible place for WI Entry header styling */
|
/* possible place for WI Entry header styling */
|
||||||
|
77
server.js
77
server.js
@@ -4391,18 +4391,25 @@ async function getManifest(extensionPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkIfRepoIsUpToDate(extensionPath) {
|
async function checkIfRepoIsUpToDate(extensionPath) {
|
||||||
await git.cwd(extensionPath).fetch('origin');
|
await git.cwd(extensionPath).fetch('origin');
|
||||||
const currentBranch = await git.cwd(extensionPath).branch();
|
const currentBranch = await git.cwd(extensionPath).branch();
|
||||||
const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
|
const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
|
||||||
const log = await git.cwd(extensionPath).log({
|
const log = await git.cwd(extensionPath).log({
|
||||||
from: currentCommitHash,
|
from: currentCommitHash,
|
||||||
to: `origin/${currentBranch.current}`,
|
to: `origin/${currentBranch.current}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return log.total === 0;
|
// Fetch remote repository information
|
||||||
|
const remotes = await git.cwd(extensionPath).getRemotes(true);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isUpToDate: log.total === 0,
|
||||||
|
remoteUrl: remotes[0].refs.fetch, // URL of the remote repository
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP POST handler function to clone a git repository from a provided URL, read the extension manifest,
|
* HTTP POST handler function to clone a git repository from a provided URL, read the extension manifest,
|
||||||
* and return extension information and path.
|
* and return extension information and path.
|
||||||
@@ -4450,36 +4457,37 @@ app.post('/get_extension', jsonParser, async (request, response) => {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
app.post('/update_extension', jsonParser, async (request, response) => {
|
app.post('/update_extension', jsonParser, async (request, response) => {
|
||||||
if (!request.body.extensionName) {
|
if (!request.body.extensionName) {
|
||||||
return response.status(400).send('Bad Request: extensionName is required in the request body.');
|
return response.status(400).send('Bad Request: extensionName is required in the request body.');
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const extensionName = request.body.extensionName;
|
|
||||||
const extensionPath = path.join(directories.extensions, 'third-party', extensionName);
|
|
||||||
|
|
||||||
if (!fs.existsSync(extensionPath)) {
|
|
||||||
return response.status(404).send(`Directory does not exist at ${extensionPath}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isUpToDate = await checkIfRepoIsUpToDate(extensionPath);
|
try {
|
||||||
|
const extensionName = request.body.extensionName;
|
||||||
|
const extensionPath = path.join(directories.extensions, 'third-party', extensionName);
|
||||||
|
|
||||||
if (!isUpToDate) {
|
if (!fs.existsSync(extensionPath)) {
|
||||||
await git.cwd(extensionPath).pull('origin', currentBranch.current);
|
return response.status(404).send(`Directory does not exist at ${extensionPath}`);
|
||||||
console.log(`Extension has been updated at ${extensionPath}`);
|
}
|
||||||
} else {
|
|
||||||
console.log(`Extension is up to date at ${extensionPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fullCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
|
const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath);
|
||||||
const shortCommitHash = fullCommitHash.slice(0, 7);
|
const currentBranch = await git.cwd(extensionPath).branch();
|
||||||
|
if (!isUpToDate) {
|
||||||
|
|
||||||
return response.send({ shortCommitHash, extensionPath, isUpToDate: isUpToDate.total === 0 });
|
await git.cwd(extensionPath).pull('origin', currentBranch.current);
|
||||||
|
console.log(`Extension has been updated at ${extensionPath}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Extension is up to date at ${extensionPath}`);
|
||||||
|
}
|
||||||
|
await git.cwd(extensionPath).fetch('origin');
|
||||||
|
const fullCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
|
||||||
|
const shortCommitHash = fullCommitHash.slice(0, 7);
|
||||||
|
|
||||||
} catch (error) {
|
return response.send({ shortCommitHash, extensionPath, isUpToDate, remoteUrl });
|
||||||
console.log('Updating custom content failed', error);
|
|
||||||
return response.status(500).send(`Server Error: ${error.message}`);
|
} catch (error) {
|
||||||
}
|
console.log('Updating custom content failed', error);
|
||||||
|
return response.status(500).send(`Server Error: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4501,11 +4509,12 @@ app.post('/get_extension_version', jsonParser, async (request, response) => {
|
|||||||
const currentBranch = await git.cwd(extensionPath).branch();
|
const currentBranch = await git.cwd(extensionPath).branch();
|
||||||
// get only the working branch
|
// get only the working branch
|
||||||
const currentBranchName = currentBranch.current;
|
const currentBranchName = currentBranch.current;
|
||||||
|
await git.cwd(extensionPath).fetch('origin');
|
||||||
const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
|
const currentCommitHash = await git.cwd(extensionPath).revparse(['HEAD']);
|
||||||
console.log(currentBranch, currentCommitHash);
|
console.log(currentBranch, currentCommitHash);
|
||||||
const isUpToDate = await checkIfRepoIsUpToDate(extensionPath);
|
const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath);
|
||||||
|
|
||||||
return response.send({ currentBranchName, currentCommitHash, isUpToDate });
|
return response.send({ currentBranchName, currentCommitHash, isUpToDate, remoteUrl });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Getting extension version failed', error);
|
console.log('Getting extension version failed', error);
|
||||||
|
Reference in New Issue
Block a user