Skip to content

Commit b41bf2d

Browse files
committed
webhook ui for the key manager
1 parent cacae05 commit b41bf2d

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

key-manager.html

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,12 @@ <h4>Update Price</h4>
506506
<button class="update-price-btn">Update Price</button>
507507
</div>
508508

509+
<div class="admin-group webhook-actions">
510+
<h4>Webhook URL <a href="https://docs.rotur.dev/keys#webhook-format" target="_blank" style="color: #6bff9f; font-size: 12px; text-decoration: none;">(?)</a></h4>
511+
<input type="url" class="update-webhook-input" placeholder="https://example.com/webhook">
512+
<button class="update-webhook-btn">Update Webhook</button>
513+
</div>
514+
509515
<div class="admin-group key-actions">
510516
<h4>Key Management</h4>
511517
<button class="revoke-key-btn">Revoke Key</button>
@@ -795,14 +801,24 @@ <h4>Key Management</h4>
795801
keyItem.querySelector('.update-name-input').value = key.name;
796802
}
797803

798-
// Set up the name update button
804+
if (key.webhook) {
805+
keyItem.querySelector('.update-webhook-input').value = key.webhook;
806+
}
807+
799808
const nameUpdateButton = keyItem.querySelector('.update-name-btn');
800809
nameUpdateButton.setAttribute('data-key', key.key);
801810
nameUpdateButton.addEventListener('click', (e) => {
802811
e.stopPropagation(); // Prevent event bubbling
803812
updateKeyName(key.key, keyItemDiv);
804813
});
805814

815+
const webhookUpdateButton = keyItem.querySelector('.update-webhook-btn');
816+
webhookUpdateButton.setAttribute('data-key', key.key);
817+
webhookUpdateButton.addEventListener('click', (e) => {
818+
e.stopPropagation();
819+
updateKeyWebhook(key.key, keyItemDiv);
820+
});
821+
806822
// Check if current user is the creator (for admin functions visibility)
807823
const isCreator = currentUser.toLowerCase() === creatorName.toLowerCase();
808824

@@ -938,7 +954,7 @@ <h4>Key Management</h4>
938954
async function createNewKey() {
939955
const priceInput = document.getElementById('new-key-price');
940956
const keyType = document.getElementById('new-key-type').value;
941-
const nameInput = document.getElementById('new-key-name'); // new line
957+
const nameInput = document.getElementById('new-key-name');
942958
const createKeyResult = document.getElementById('create-key-result');
943959

944960
// Clear previous messages
@@ -986,7 +1002,7 @@ <h4>Key Management</h4>
9861002

9871003
// 7. Reset form fields
9881004
priceInput.value = '';
989-
nameInput.value = ''; // reset name field
1005+
nameInput.value = '';
9901006
document.getElementById('new-key-type').value = 'regular';
9911007
document.getElementById('subscription-fields').style.display = 'none';
9921008

@@ -1203,6 +1219,51 @@ <h4>Key Management</h4>
12031219
}
12041220
}
12051221

1222+
async function updateKeyWebhook(keyId, keyElement) {
1223+
const webhookInput = keyElement.querySelector('.update-webhook-input');
1224+
const webhook = webhookInput.value.trim();
1225+
const messageDiv = keyElement.querySelector('.key-message');
1226+
const errorDiv = keyElement.querySelector('.key-error');
1227+
1228+
messageDiv.textContent = '';
1229+
errorDiv.textContent = '';
1230+
1231+
if (webhook && !webhook.match(/^https?:\/\/.+/)) {
1232+
errorDiv.textContent = 'Please enter a valid URL (must start with http:// or https://)';
1233+
setTimeout(() => {
1234+
errorDiv.textContent = '';
1235+
}, 3000);
1236+
return;
1237+
}
1238+
1239+
try {
1240+
const url = `${API_BASE_URL}/keys/update/${keyId}?auth=${encodeURIComponent(authToken)}&key=webhook&data=${encodeURIComponent(webhook)}`;
1241+
const response = await fetch(url);
1242+
const data = await response.json();
1243+
1244+
if (response.ok) {
1245+
messageDiv.textContent = webhook ? 'Webhook URL updated successfully' : 'Webhook URL removed';
1246+
1247+
setTimeout(() => {
1248+
messageDiv.textContent = '';
1249+
}, 3000);
1250+
} else {
1251+
errorDiv.textContent = data.error || 'Failed to update webhook URL';
1252+
1253+
setTimeout(() => {
1254+
errorDiv.textContent = '';
1255+
}, 3000);
1256+
}
1257+
} catch (error) {
1258+
errorDiv.textContent = 'Network error occurred. Please try again.';
1259+
console.error('Update webhook error:', error);
1260+
1261+
setTimeout(() => {
1262+
errorDiv.textContent = '';
1263+
}, 3000);
1264+
}
1265+
}
1266+
12061267
async function addUserToKey(keyId, keyElement) {
12071268
const input = keyElement.querySelector('.add-user-input');
12081269
const username = input.value.trim().toLowerCase();
@@ -1414,4 +1475,4 @@ <h4>Key Management</h4>
14141475
}
14151476
</script>
14161477
</body>
1417-
</html>
1478+
</html>

0 commit comments

Comments
 (0)