update test client

This commit is contained in:
2026-04-05 13:06:30 +02:00
parent 9d279c9680
commit cf8a635dd7
2 changed files with 114 additions and 38 deletions
+114 -38
View File
@@ -66,17 +66,23 @@
<div id="log"></div>
<div id="btn-row">
<button onclick="showForm('new-client')">POST /new/client</button>
<button onclick="showForm('new-user')">POST /new/user</button>
<button onclick="showForm('new-connection')">POST /new/connection</button>
<button onclick="showForm('new-token')">POST /new/token</button>
<button onclick="showForm('new-group')">POST /new/group</button>
<button onclick="showForm('add-clients')">POST /mod/group/addclients</button>
<button onclick="showForm('remove-clients')">POST /mod/group/removeclients</button>
<button onclick="showForm('mod-user-appearance')">POST /mod/user/appearence</button>
<button onclick="showForm('mod-user-about')">POST /mod/user/about</button>
<button onclick="showForm('accept-connection')">POST /mod/connection/accept</button>
<button onclick="showForm('delete-connection')" class="warn">POST /mod/connection/delete</button>
<button onclick="showForm('add-users')">POST /mod/group/addusers</button>
<button onclick="showForm('remove-users')">POST /mod/group/removeusers</button>
<button onclick="showForm('group-color')">POST /mod/group/color</button>
<button onclick="showForm('group-owner')">POST /mod/group/owner</button>
<button onclick="showForm('new-message')">POST /new/message</button>
<button onclick="showForm('get-groups')">POST /get/groups</button>
<button onclick="showForm('get-connections')">POST /get/connections</button>
<button onclick="showForm('get-members')">POST /get/group/members</button>
<button onclick="showForm('del-group')" class="warn">POST /del/group</button>
<button onclick="showForm('msg-group')">POST /msg/group</button>
<button onclick="showForm('websocket')">WS /ws</button>
</div>
@@ -88,16 +94,30 @@
<script>
let ws = null;
let activeForm = null;
let currentToken = '';
function autofillTokens() {
if (!currentToken) return;
document.querySelectorAll('input[id$="-token"]').forEach(el => { el.value = currentToken; });
}
var formDefs = {
'new-client': {
title: 'POST /new/client — register new user',
'new-user': {
title: 'POST /new/user — register new user',
fields: [
{ id: 'nc-username', label: 'username', ph: 'min 4 chars' },
{ id: 'nc-password', label: 'password', ph: 'min 8 chars' },
{ id: 'nc-color', label: 'color', ph: '255,100,50', hint: 'R,G,B' },
{ id: 'nu-username', label: 'username', ph: 'min 4 chars' },
{ id: 'nu-password', label: 'password', ph: 'min 8 chars' },
{ id: 'nu-color', label: 'color', ph: '255,100,50', hint: 'R,G,B' },
],
submit: () => httpPost('/new/client', { username:'nc-username', password:'nc-password', color:'nc-color' })
submit: () => httpPost('/new/user', { username:'nu-username', password:'nu-password', color:'nu-color' })
},
'new-connection': {
title: 'POST /new/connection — send connection request',
fields: [
{ id: 'nconn-token', label: 'token', ph: '' },
{ id: 'nconn-recipientid', label: 'recipientid', ph: 'uint32' },
],
submit: () => httpPost('/new/connection', { token:'nconn-token', recipientid:'nconn-recipientid' })
},
'new-token': {
title: 'POST /new/token — login / get token',
@@ -110,30 +130,62 @@
'new-group': {
title: 'POST /new/group — create group',
fields: [
{ id: 'ng-token', label: 'token', ph: '' },
{ id: 'ng-name', label: 'name', ph: 'optional, default: Best group ever' },
{ id: 'ng-color', label: 'color', ph: 'R,G,B or name, optional', hint: 'R,G,B' },
{ id: 'ng-enableClientColors', label: 'enableClientColors', ph: '1 to enable (optional)' },
{ id: 'ng-token', label: 'token', ph: '' },
{ id: 'ng-name', label: 'name', ph: 'optional, default: Best group ever' },
{ id: 'ng-color', label: 'color', ph: 'R,G,B optional', hint: 'R,G,B' },
{ id: 'ng-enableUserColors', label: 'enableUserColors', ph: '1 to enable (optional)' },
],
submit: () => httpPost('/new/group', { token:'ng-token', name:'ng-name', color:'ng-color', enableClientColors:'ng-enableClientColors' })
submit: () => httpPost('/new/group', { token:'ng-token', name:'ng-name', color:'ng-color', enableUserColors:'ng-enableUserColors' })
},
'add-clients': {
title: 'POST /mod/group/addclients — add clients (owner only)',
'mod-user-appearance': {
title: 'POST /mod/user/appearence — change user color',
fields: [
{ id: 'ac-token', label: 'token', ph: '' },
{ id: 'ac-groupid', label: 'groupid', ph: 'uint32' },
{ id: 'ac-clients', label: 'clients', ph: 'id1,id2,id3', hint: 'csv of uint32' },
{ id: 'mua-token', label: 'token', ph: '' },
{ id: 'mua-color', label: 'color', ph: '255,100,50', hint: 'R,G,B' },
],
submit: () => httpPost('/mod/group/addclients', { token:'ac-token', groupid:'ac-groupid', clients:'ac-clients' })
submit: () => httpPost('/mod/user/appearence', { token:'mua-token', color:'mua-color' })
},
'remove-clients': {
title: 'POST /mod/group/removeclients — remove clients (owner only)',
'mod-user-about': {
title: 'POST /mod/user/about — change user pronouns',
fields: [
{ id: 'rc-token', label: 'token', ph: '' },
{ id: 'rc-groupid', label: 'groupid', ph: 'uint32' },
{ id: 'rc-clients', label: 'clients', ph: 'id1,id2,id3', hint: 'csv of uint32' },
{ id: 'mub-token', label: 'token', ph: '' },
{ id: 'mub-pronouns', label: 'pronouns', ph: '225 chars' },
],
submit: () => httpPost('/mod/group/removeclients', { token:'rc-token', groupid:'rc-groupid', clients:'rc-clients' })
submit: () => httpPost('/mod/user/about', { token:'mub-token', pronouns:'mub-pronouns' })
},
'accept-connection': {
title: 'POST /mod/connection/accept — accept connection request',
fields: [
{ id: 'ca-token', label: 'token', ph: '' },
{ id: 'ca-connectedid', label: 'connectedid', ph: 'uint32' },
],
submit: () => httpPost('/mod/connection/accept', { token:'ca-token', connectedid:'ca-connectedid' })
},
'delete-connection': {
title: 'POST /mod/connection/delete — delete connection',
fields: [
{ id: 'cd-token', label: 'token', ph: '' },
{ id: 'cd-connectedid', label: 'connectedid', ph: 'uint32' },
],
submit: () => httpPost('/mod/connection/delete', { token:'cd-token', connectedid:'cd-connectedid' })
},
'add-users': {
title: 'POST /mod/group/addusers — add users (owner only)',
fields: [
{ id: 'au-token', label: 'token', ph: '' },
{ id: 'au-groupid', label: 'groupid', ph: 'uint32' },
{ id: 'au-users', label: 'users', ph: 'id1,id2,id3', hint: 'csv of uint32' },
],
submit: () => httpPost('/mod/group/addusers', { token:'au-token', groupid:'au-groupid', users:'au-users' })
},
'remove-users': {
title: 'POST /mod/group/removeusers — remove users (owner only)',
fields: [
{ id: 'ru-token', label: 'token', ph: '' },
{ id: 'ru-groupid', label: 'groupid', ph: 'uint32' },
{ id: 'ru-users', label: 'users', ph: 'id1,id2,id3', hint: 'csv of uint32' },
],
submit: () => httpPost('/mod/group/removeusers', { token:'ru-token', groupid:'ru-groupid', users:'ru-users' })
},
'group-color': {
title: 'POST /mod/group/color — change color (owner only)',
@@ -151,24 +203,22 @@
{ id: 'go-groupid', label: 'groupid', ph: 'uint32' },
{ id: 'go-newOwner', label: 'newOwner', ph: 'username of new owner' },
],
submit: () => httpPost('/mod/group/color', { token:'go-token', groupid:'go-groupid', newOwner:'go-newOwner' })
},
'new-message': {
title: 'POST /new/message — send message to group',
fields: [
{ id: 'nm-token', label: 'token', ph: '' },
{ id: 'nm-subject', label: 'subject', ph: 'group ID (uint32)', hint: 'group id' },
{ id: 'nm-content', label: 'content', ph: 'message text' },
],
submit: () => httpPost('/new/message', { token:'nm-token', subject:'nm-subject', content:'nm-content' })
submit: () => httpPost('/mod/group/owner', { token:'go-token', groupid:'go-groupid', newOwner:'go-newOwner' })
},
'get-groups': {
title: "POST /get/groups — get client's groups (no members)",
title: "POST /get/groups — get user's groups (no members)",
fields: [
{ id: 'gg-token', label: 'token', ph: '' },
],
submit: () => httpPost('/get/groups', { token:'gg-token' })
},
'get-connections': {
title: "POST /get/connections — get user's connections",
fields: [
{ id: 'gconn-token', label: 'token', ph: '' },
],
submit: () => httpPost('/get/connections', { token:'gconn-token' })
},
'get-members': {
title: 'POST /get/group/members — get group member IDs',
fields: [
@@ -185,6 +235,15 @@
],
submit: () => httpPost('/del/group', { token:'dg-token', groupid:'dg-groupid' })
},
'msg-group': {
title: 'POST /msg/group — send message to group',
fields: [
{ id: 'mg-token', label: 'token', ph: '' },
{ id: 'mg-groupid', label: 'groupid', ph: 'uint32' },
{ id: 'mg-content', label: 'content', ph: 'message text' },
],
submit: () => httpPost('/msg/group', { token:'mg-token', groupid:'mg-groupid', content:'mg-content' })
},
'websocket': {
title: 'WS /ws — WebSocket connection',
renderCustom: () => {
@@ -247,6 +306,7 @@
}
html += `<div class="form-actions"><button class="send" onclick="formDefs['${name}'].submit()">Send</button></div>`;
fieldsEl.innerHTML = html;
autofillTokens();
}
panel.classList.add('open');
@@ -280,11 +340,27 @@
const resp = await fetch(url, { method: 'POST', body: params });
const text = await resp.text();
log(`HTTP ${resp.status}`, text, resp.ok ? 'log-http' : 'log-err');
if (path === '/new/token' && resp.ok) {
currentToken = text.trim();
autofillTokens();
wsConnectAndAuth();
}
} catch(e) {
log('HTTP ERR', e.message, 'log-err');
}
}
function wsConnectAndAuth() {
if (ws) { wsAuth(); return; }
const url = baseUrl().replace(/^http/, 'ws') + '/ws';
log('WS', `auto-connecting to ${url}`, 'log-info');
ws = new WebSocket(url);
ws.onopen = () => { setWsStatus(true); log('WS', 'connected', 'log-ws'); wsAuth(); };
ws.onmessage = (e) => { log('WS', e.data, 'log-ws'); };
ws.onerror = () => { log('WS ERR', 'error', 'log-err'); };
ws.onclose = () => { setWsStatus(false); log('WS', 'disconnected', 'log-info'); ws = null; };
}
function wsConnect() {
if (ws) { log('WS', 'already connected', 'log-info'); return; }
const url = baseUrl().replace(/^http/, 'ws') + '/ws';