mirror of
https://github.com/aljazceru/goose.git
synced 2026-02-01 04:34:21 +01:00
Add deeplink redirect to install link generator (#2024)
This commit is contained in:
@@ -5,6 +5,22 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Goose Install Link Generator</title>
|
||||
<link rel="stylesheet" href="./styles.css">
|
||||
<style>
|
||||
.error {
|
||||
color: #dc3545;
|
||||
padding: 10px;
|
||||
border: 1px solid #dc3545;
|
||||
border-radius: 4px;
|
||||
margin: 10px 0;
|
||||
background-color: #f8d7da;
|
||||
}
|
||||
.container {
|
||||
display: none; /* Hidden by default, shown if no params or error */
|
||||
}
|
||||
.result {
|
||||
display: none; /* Hidden by default, shown when needed */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
@@ -1,4 +1,92 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Function to show error message
|
||||
function showError(message) {
|
||||
const resultDiv = document.getElementById('generatedLink');
|
||||
resultDiv.innerHTML = `<div class="error">${message}</div>`;
|
||||
resultDiv.parentElement.style.display = 'block';
|
||||
}
|
||||
|
||||
// Function to handle generated link (display or redirect)
|
||||
function handleGeneratedLink(link, shouldRedirect = false) {
|
||||
if (shouldRedirect) {
|
||||
window.location.href = link;
|
||||
} else {
|
||||
displayGeneratedLink(link);
|
||||
}
|
||||
}
|
||||
|
||||
// Process URL parameters if present
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.toString()) {
|
||||
try {
|
||||
// Check if this is a built-in extension request
|
||||
if (urlParams.get('cmd') === 'goosed' && urlParams.getAll('arg').includes('mcp')) {
|
||||
const args = urlParams.getAll('arg');
|
||||
const extensionId = args[args.indexOf('mcp') + 1];
|
||||
if (!extensionId) {
|
||||
throw new Error('Missing extension ID in args');
|
||||
}
|
||||
|
||||
const server = {
|
||||
is_builtin: true,
|
||||
id: extensionId
|
||||
};
|
||||
const link = generateInstallLink(server);
|
||||
handleGeneratedLink(link, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle custom extension
|
||||
const cmd = urlParams.get('cmd');
|
||||
if (!cmd) {
|
||||
throw new Error('Missing required parameter: cmd');
|
||||
}
|
||||
|
||||
const args = urlParams.getAll('arg') || [];
|
||||
const command = [cmd, ...args].join(' ');
|
||||
const id = urlParams.get('id');
|
||||
const name = urlParams.get('name');
|
||||
const description = urlParams.get('description');
|
||||
|
||||
if (!id || !name || !description) {
|
||||
throw new Error('Missing required parameters. Need: id, name, and description');
|
||||
}
|
||||
|
||||
const server = {
|
||||
is_builtin: false,
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
command,
|
||||
environmentVariables: []
|
||||
};
|
||||
|
||||
// Handle environment variables if present
|
||||
const envVars = urlParams.getAll('env');
|
||||
if (envVars.length > 0) {
|
||||
envVars.forEach(env => {
|
||||
const [name, description] = env.split('=');
|
||||
if (name && description) {
|
||||
server.environmentVariables.push({
|
||||
name,
|
||||
description,
|
||||
required: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const link = generateInstallLink(server);
|
||||
handleGeneratedLink(link, true);
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
document.querySelector('.container').style.display = 'block';
|
||||
}
|
||||
} else {
|
||||
// Show the form if no parameters
|
||||
document.querySelector('.container').style.display = 'block';
|
||||
}
|
||||
|
||||
// Tab switching
|
||||
const tabs = document.querySelectorAll('.tab-btn');
|
||||
tabs.forEach(tab => {
|
||||
@@ -82,7 +170,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
|
||||
const link = generateInstallLink(server);
|
||||
displayGeneratedLink(link);
|
||||
handleGeneratedLink(link);
|
||||
});
|
||||
|
||||
// Generate link from JSON
|
||||
@@ -91,9 +179,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const jsonInput = document.getElementById('jsonInput').value;
|
||||
const server = JSON.parse(jsonInput);
|
||||
const link = generateInstallLink(server);
|
||||
displayGeneratedLink(link);
|
||||
handleGeneratedLink(link);
|
||||
} catch (error) {
|
||||
alert('Invalid JSON: ' + error.message);
|
||||
showError('Invalid JSON: ' + error.message);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -131,6 +219,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
function displayGeneratedLink(link) {
|
||||
const linkElement = document.getElementById('generatedLink');
|
||||
linkElement.textContent = link;
|
||||
linkElement.parentElement.style.display = 'block';
|
||||
}
|
||||
|
||||
// Add sample JSON to the textarea
|
||||
|
||||
Reference in New Issue
Block a user