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
BIN
View File
Binary file not shown.
+112 -36
View File
@@ -66,17 +66,23 @@
<div id="log"></div> <div id="log"></div>
<div id="btn-row"> <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-token')">POST /new/token</button>
<button onclick="showForm('new-group')">POST /new/group</button> <button onclick="showForm('new-group')">POST /new/group</button>
<button onclick="showForm('add-clients')">POST /mod/group/addclients</button> <button onclick="showForm('mod-user-appearance')">POST /mod/user/appearence</button>
<button onclick="showForm('remove-clients')">POST /mod/group/removeclients</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-color')">POST /mod/group/color</button>
<button onclick="showForm('group-owner')">POST /mod/group/owner</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-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('get-members')">POST /get/group/members</button>
<button onclick="showForm('del-group')" class="warn">POST /del/group</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> <button onclick="showForm('websocket')">WS /ws</button>
</div> </div>
@@ -88,16 +94,30 @@
<script> <script>
let ws = null; let ws = null;
let activeForm = null; let activeForm = null;
let currentToken = '';
function autofillTokens() {
if (!currentToken) return;
document.querySelectorAll('input[id$="-token"]').forEach(el => { el.value = currentToken; });
}
var formDefs = { var formDefs = {
'new-client': { 'new-user': {
title: 'POST /new/client — register new user', title: 'POST /new/user — register new user',
fields: [ fields: [
{ id: 'nc-username', label: 'username', ph: 'min 4 chars' }, { id: 'nu-username', label: 'username', ph: 'min 4 chars' },
{ id: 'nc-password', label: 'password', ph: 'min 8 chars' }, { id: 'nu-password', label: 'password', ph: 'min 8 chars' },
{ id: 'nc-color', label: 'color', ph: '255,100,50', hint: 'R,G,B' }, { 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': { 'new-token': {
title: 'POST /new/token — login / get token', title: 'POST /new/token — login / get token',
@@ -112,28 +132,60 @@
fields: [ fields: [
{ id: 'ng-token', label: 'token', ph: '' }, { id: 'ng-token', label: 'token', ph: '' },
{ id: 'ng-name', label: 'name', ph: 'optional, default: Best group ever' }, { 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-color', label: 'color', ph: 'R,G,B optional', hint: 'R,G,B' },
{ id: 'ng-enableClientColors', label: 'enableClientColors', ph: '1 to enable (optional)' }, { 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': { 'mod-user-appearance': {
title: 'POST /mod/group/addclients — add clients (owner only)', title: 'POST /mod/user/appearence — change user color',
fields: [ fields: [
{ id: 'ac-token', label: 'token', ph: '' }, { id: 'mua-token', label: 'token', ph: '' },
{ id: 'ac-groupid', label: 'groupid', ph: 'uint32' }, { id: 'mua-color', label: 'color', ph: '255,100,50', hint: 'R,G,B' },
{ id: 'ac-clients', label: 'clients', ph: 'id1,id2,id3', hint: 'csv of uint32' },
], ],
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': { 'mod-user-about': {
title: 'POST /mod/group/removeclients — remove clients (owner only)', title: 'POST /mod/user/about — change user pronouns',
fields: [ fields: [
{ id: 'rc-token', label: 'token', ph: '' }, { id: 'mub-token', label: 'token', ph: '' },
{ id: 'rc-groupid', label: 'groupid', ph: 'uint32' }, { id: 'mub-pronouns', label: 'pronouns', ph: '225 chars' },
{ id: 'rc-clients', label: 'clients', ph: 'id1,id2,id3', hint: 'csv of uint32' },
], ],
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': { 'group-color': {
title: 'POST /mod/group/color — change color (owner only)', title: 'POST /mod/group/color — change color (owner only)',
@@ -151,24 +203,22 @@
{ id: 'go-groupid', label: 'groupid', ph: 'uint32' }, { id: 'go-groupid', label: 'groupid', ph: 'uint32' },
{ id: 'go-newOwner', label: 'newOwner', ph: 'username of new owner' }, { id: 'go-newOwner', label: 'newOwner', ph: 'username of new owner' },
], ],
submit: () => httpPost('/mod/group/color', { token:'go-token', groupid:'go-groupid', newOwner:'go-newOwner' }) submit: () => httpPost('/mod/group/owner', { 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' })
}, },
'get-groups': { 'get-groups': {
title: "POST /get/groups — get client's groups (no members)", title: "POST /get/groups — get user's groups (no members)",
fields: [ fields: [
{ id: 'gg-token', label: 'token', ph: '' }, { id: 'gg-token', label: 'token', ph: '' },
], ],
submit: () => httpPost('/get/groups', { token:'gg-token' }) 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': { 'get-members': {
title: 'POST /get/group/members — get group member IDs', title: 'POST /get/group/members — get group member IDs',
fields: [ fields: [
@@ -185,6 +235,15 @@
], ],
submit: () => httpPost('/del/group', { token:'dg-token', groupid:'dg-groupid' }) 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': { 'websocket': {
title: 'WS /ws — WebSocket connection', title: 'WS /ws — WebSocket connection',
renderCustom: () => { renderCustom: () => {
@@ -247,6 +306,7 @@
} }
html += `<div class="form-actions"><button class="send" onclick="formDefs['${name}'].submit()">Send</button></div>`; html += `<div class="form-actions"><button class="send" onclick="formDefs['${name}'].submit()">Send</button></div>`;
fieldsEl.innerHTML = html; fieldsEl.innerHTML = html;
autofillTokens();
} }
panel.classList.add('open'); panel.classList.add('open');
@@ -280,11 +340,27 @@
const resp = await fetch(url, { method: 'POST', body: params }); const resp = await fetch(url, { method: 'POST', body: params });
const text = await resp.text(); const text = await resp.text();
log(`HTTP ${resp.status}`, text, resp.ok ? 'log-http' : 'log-err'); log(`HTTP ${resp.status}`, text, resp.ok ? 'log-http' : 'log-err');
if (path === '/new/token' && resp.ok) {
currentToken = text.trim();
autofillTokens();
wsConnectAndAuth();
}
} catch(e) { } catch(e) {
log('HTTP ERR', e.message, 'log-err'); 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() { function wsConnect() {
if (ws) { log('WS', 'already connected', 'log-info'); return; } if (ws) { log('WS', 'already connected', 'log-info'); return; }
const url = baseUrl().replace(/^http/, 'ws') + '/ws'; const url = baseUrl().replace(/^http/, 'ws') + '/ws';