fix main change owner route, fix group create id return, add new client

This commit is contained in:
2026-04-02 23:29:45 +02:00
parent 3d1c7afdd7
commit 922f13c64f
4 changed files with 10 additions and 17 deletions
BIN
View File
Binary file not shown.
+5 -12
View File
@@ -2,8 +2,8 @@ package main
import (
"context"
"encoding/binary"
json2 "encoding/json"
"fmt"
"maps"
"net/http"
"slices"
@@ -87,7 +87,7 @@ func getIfOwnerClientAndGroup(ctx context.Context, response *http.ResponseWriter
return client, group, nil
}
func HttpHandleNewUser(response http.ResponseWriter, request *http.Request) {
func HttpHandleNewClient(response http.ResponseWriter, request *http.Request) {
if !isMethodAllowed(&response, request) {
return
}
@@ -131,7 +131,7 @@ func HttpHandleNewUser(response http.ResponseWriter, request *http.Request) {
return
}
response.WriteHeader(http.StatusAccepted)
response.WriteHeader(http.StatusCreated)
response.Write([]byte("created"))
}
@@ -234,11 +234,8 @@ func HttpHandeNewGroup(response http.ResponseWriter, request *http.Request) {
http.Error(response, err.Error(), http.StatusInternalServerError)
return
}
groupIdBytes := make([]byte, 4)
binary.BigEndian.PutUint32(groupIdBytes, group.Id)
response.WriteHeader(http.StatusCreated)
response.Write(groupIdBytes)
fmt.Fprintf(response, "%d", group.Id)
}
func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Request) {
@@ -295,11 +292,7 @@ func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Reques
}
response.WriteHeader(http.StatusAccepted)
_, err = response.Write([]byte("ok"))
if err != nil {
http.Error(response, "internal server error", http.StatusInternalServerError)
return
}
response.Write([]byte("ok"))
}
func HttpHandleGroupRemoveClient(response http.ResponseWriter, request *http.Request) {
+4 -4
View File
@@ -88,7 +88,7 @@
let ws = null;
let activeForm = null;
const forms = {
var formDefs = {
'new-client': {
title: 'POST /new/client — register new user',
fields: [
@@ -214,10 +214,10 @@
}
activeForm = name;
const def = forms[name];
const def = formDefs[name];
// activate clicked button
const idx = Object.keys(forms).indexOf(name);
const idx = Object.keys(formDefs).indexOf(name);
if (idx >= 0) {
buttons[idx].classList.add('active');
if (name === 'websocket') buttons[idx].classList.add('ws');
@@ -236,7 +236,7 @@
${f.hint ? `<span class="hint">${f.hint}</span>` : ''}
</div>`;
}
html += `<div class="form-actions"><button class="send" onclick="forms['${name}'].submit()">Send</button></div>`;
html += `<div class="form-actions"><button class="send" onclick="formDefs['${name}'].submit()">Send</button></div>`;
fieldsEl.innerHTML = html;
}
+1 -1
View File
@@ -17,7 +17,7 @@ func main() {
ctx := context.Background()
DbInit(ctx)
http.HandleFunc("/new/client", withCORS(HttpHandleNewUser))
http.HandleFunc("/new/client", withCORS(HttpHandleNewClient))
http.HandleFunc("/new/token", withCORS(HttpHandleNewToken))
http.HandleFunc("/new/group", withCORS(HttpHandeNewGroup))
http.HandleFunc("/mod/group/addclients", withCORS(HttpHandleGroupAddClient))