mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Documentation update
This commit is contained in:
@@ -8494,6 +8494,16 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the click event for the third-party extension import button.
|
||||||
|
* Prompts the user to enter the Git URL of the extension to import.
|
||||||
|
* After obtaining the Git URL, makes a POST request to '/get_extension' to import the extension.
|
||||||
|
* If the extension is imported successfully, a success message is displayed.
|
||||||
|
* If the extension import fails, an error message is displayed and the error is logged to the console.
|
||||||
|
* After successfully importing the extension, the extension settings are reloaded and a 'EXTENSION_SETTINGS_LOADED' event is emitted.
|
||||||
|
*
|
||||||
|
* @listens #third_party_extension_button#click - The click event of the '#third_party_extension_button' element.
|
||||||
|
*/
|
||||||
$('#third_party_extension_button').on('click', async () => {
|
$('#third_party_extension_button').on('click', async () => {
|
||||||
const html = `<h3>Enter the Git URL of the extension to import</h3>
|
const html = `<h3>Enter the Git URL of the extension to import</h3>
|
||||||
<br>
|
<br>
|
||||||
|
@@ -378,6 +378,17 @@ function addExtensionScript(name, manifest) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates HTML string for displaying an extension in the UI.
|
||||||
|
*
|
||||||
|
* @param {string} name - The name of the extension.
|
||||||
|
* @param {object} manifest - The manifest of the extension.
|
||||||
|
* @param {boolean} isActive - Whether the extension is active or not.
|
||||||
|
* @param {boolean} isDisabled - Whether the extension is disabled or not.
|
||||||
|
* @param {boolean} isExternal - Whether the extension is external or not.
|
||||||
|
* @param {string} checkboxClass - The class for the checkbox HTML element.
|
||||||
|
* @return {string} - The HTML string that represents the extension.
|
||||||
|
*/
|
||||||
async function generateExtensionHtml(name, manifest, isActive, isDisabled, isExternal, checkboxClass) {
|
async function generateExtensionHtml(name, manifest, isActive, isDisabled, isExternal, checkboxClass) {
|
||||||
const displayName = manifest.display_name;
|
const displayName = manifest.display_name;
|
||||||
let displayVersion = manifest.version ? ` v${manifest.version}` : "";
|
let displayVersion = manifest.version ? ` v${manifest.version}` : "";
|
||||||
@@ -431,6 +442,12 @@ async function generateExtensionHtml(name, manifest, isActive, isDisabled, isExt
|
|||||||
return extensionHtml;
|
return extensionHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets extension data and generates the corresponding HTML for displaying the extension.
|
||||||
|
*
|
||||||
|
* @param {Array} extension - An array where the first element is the extension name and the second element is the extension manifest.
|
||||||
|
* @return {object} - An object with 'isExternal' indicating whether the extension is external, and 'extensionHtml' for the extension's HTML string.
|
||||||
|
*/
|
||||||
async function getExtensionData(extension) {
|
async function getExtensionData(extension) {
|
||||||
const name = extension[0];
|
const name = extension[0];
|
||||||
const manifest = extension[1];
|
const manifest = extension[1];
|
||||||
@@ -446,6 +463,11 @@ async function getExtensionData(extension) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the module information to be displayed.
|
||||||
|
*
|
||||||
|
* @return {string} - The HTML string for the module information.
|
||||||
|
*/
|
||||||
function getModuleInformation() {
|
function getModuleInformation() {
|
||||||
let moduleInfo = modules.length ? `<p>${DOMPurify.sanitize(modules.join(', '))}</p>` : '<p class="failure">Not connected to the API!</p>';
|
let moduleInfo = modules.length ? `<p>${DOMPurify.sanitize(modules.join(', '))}</p>` : '<p class="failure">Not connected to the API!</p>';
|
||||||
return `
|
return `
|
||||||
@@ -454,6 +476,9 @@ function getModuleInformation() {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the HTML strings for all extensions and displays them in a popup.
|
||||||
|
*/
|
||||||
async function showExtensionsDetails() {
|
async function showExtensionsDetails() {
|
||||||
let htmlDefault = '<h3>Default Extensions:</h3>';
|
let htmlDefault = '<h3>Default Extensions:</h3>';
|
||||||
let htmlExternal = '<h3>External Extensions:</h3>';
|
let htmlExternal = '<h3>External Extensions:</h3>';
|
||||||
@@ -478,7 +503,12 @@ 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.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
async function onUpdateClick() {
|
async function onUpdateClick() {
|
||||||
const extensionName = $(this).data('name');
|
const extensionName = $(this).data('name');
|
||||||
try {
|
try {
|
||||||
@@ -488,14 +518,10 @@ async function onUpdateClick() {
|
|||||||
body: JSON.stringify({ extensionName })
|
body: JSON.stringify({ extensionName })
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Response', response);
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('Data', data);
|
|
||||||
if (data.isUpToDate) {
|
if (data.isUpToDate) {
|
||||||
console.log('Extension is up to date');
|
|
||||||
toastr.success('Extension is already up to date');
|
toastr.success('Extension is already up to date');
|
||||||
} else {
|
} else {
|
||||||
console.log('Extension updated');
|
|
||||||
toastr.success(`Extension updated to ${data.shortCommitHash}`);
|
toastr.success(`Extension updated to ${data.shortCommitHash}`);
|
||||||
}
|
}
|
||||||
showExtensionsDetails();
|
showExtensionsDetails();
|
||||||
@@ -504,6 +530,15 @@ async function onUpdateClick() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the version details of a specific extension.
|
||||||
|
*
|
||||||
|
* @param {string} extensionName - The name of the extension.
|
||||||
|
* @return {object} - An object containing the extension's version details.
|
||||||
|
* This object includes the currentBranchName, currentCommitHash, isUpToDate, and remoteUrl.
|
||||||
|
* @throws {error} - If there is an error during the fetch operation, it logs the error to the console.
|
||||||
|
*/
|
||||||
async function getExtensionVersion(extensionName) {
|
async function getExtensionVersion(extensionName) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/get_extension_version', {
|
const response = await fetch('/get_extension_version', {
|
||||||
|
19
server.js
19
server.js
@@ -4413,7 +4413,7 @@ async function checkIfRepoIsUpToDate(extensionPath) {
|
|||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
* @param {Object} request - HTTP Request object, expects a JSON body with a 'url' property.
|
* @param {Object} request - HTTP Request object, expects a JSON body with a 'url' property.
|
||||||
* @param {Object} response - HTTP Response object used to respond to the HTTP request.
|
* @param {Object} response - HTTP Response object used to respond to the HTTP request.
|
||||||
*
|
*
|
||||||
@@ -4448,9 +4448,11 @@ app.post('/get_extension', jsonParser, async (request, response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP POST handler function to pull the latest updates from a given git repository
|
* HTTP POST handler function to pull the latest updates from a git repository
|
||||||
* based on the extension name and return the latest commit hash.
|
* based on the extension name provided in the request body. It returns the latest commit hash,
|
||||||
*
|
* the path of the extension, the status of the repository (whether it's up-to-date or not),
|
||||||
|
* and the remote URL of the repository.
|
||||||
|
*
|
||||||
* @param {Object} request - HTTP Request object, expects a JSON body with an 'extensionName' property.
|
* @param {Object} request - HTTP Request object, expects a JSON body with an 'extensionName' property.
|
||||||
* @param {Object} response - HTTP Response object used to respond to the HTTP request.
|
* @param {Object} response - HTTP Response object used to respond to the HTTP request.
|
||||||
*
|
*
|
||||||
@@ -4491,7 +4493,14 @@ app.post('/update_extension', jsonParser, async (request, response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get current git commit hash and branch name for a given extension.
|
* HTTP POST handler function to get the current git commit hash and branch name for a given extension.
|
||||||
|
* It checks whether the repository is up-to-date with the remote, and returns the status along with
|
||||||
|
* the remote URL of the repository.
|
||||||
|
*
|
||||||
|
* @param {Object} request - HTTP Request object, expects a JSON body with an 'extensionName' property.
|
||||||
|
* @param {Object} response - HTTP Response object used to respond to the HTTP request.
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
app.post('/get_extension_version', jsonParser, async (request, response) => {
|
app.post('/get_extension_version', jsonParser, async (request, response) => {
|
||||||
if (!request.body.extensionName) {
|
if (!request.body.extensionName) {
|
||||||
|
Reference in New Issue
Block a user