fix main change owner route, fix group create id return, add new client
This commit is contained in:
@@ -2,8 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
|
||||||
json2 "encoding/json"
|
json2 "encoding/json"
|
||||||
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -87,7 +87,7 @@ func getIfOwnerClientAndGroup(ctx context.Context, response *http.ResponseWriter
|
|||||||
return client, group, nil
|
return client, group, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpHandleNewUser(response http.ResponseWriter, request *http.Request) {
|
func HttpHandleNewClient(response http.ResponseWriter, request *http.Request) {
|
||||||
if !isMethodAllowed(&response, request) {
|
if !isMethodAllowed(&response, request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ func HttpHandleNewUser(response http.ResponseWriter, request *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.WriteHeader(http.StatusAccepted)
|
response.WriteHeader(http.StatusCreated)
|
||||||
response.Write([]byte("created"))
|
response.Write([]byte("created"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,11 +234,8 @@ func HttpHandeNewGroup(response http.ResponseWriter, request *http.Request) {
|
|||||||
http.Error(response, err.Error(), http.StatusInternalServerError)
|
http.Error(response, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
groupIdBytes := make([]byte, 4)
|
|
||||||
binary.BigEndian.PutUint32(groupIdBytes, group.Id)
|
|
||||||
|
|
||||||
response.WriteHeader(http.StatusCreated)
|
response.WriteHeader(http.StatusCreated)
|
||||||
response.Write(groupIdBytes)
|
fmt.Fprintf(response, "%d", group.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Request) {
|
func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Request) {
|
||||||
@@ -295,11 +292,7 @@ func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
response.WriteHeader(http.StatusAccepted)
|
response.WriteHeader(http.StatusAccepted)
|
||||||
_, err = response.Write([]byte("ok"))
|
response.Write([]byte("ok"))
|
||||||
if err != nil {
|
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpHandleGroupRemoveClient(response http.ResponseWriter, request *http.Request) {
|
func HttpHandleGroupRemoveClient(response http.ResponseWriter, request *http.Request) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
let ws = null;
|
let ws = null;
|
||||||
let activeForm = null;
|
let activeForm = null;
|
||||||
|
|
||||||
const forms = {
|
var formDefs = {
|
||||||
'new-client': {
|
'new-client': {
|
||||||
title: 'POST /new/client — register new user',
|
title: 'POST /new/client — register new user',
|
||||||
fields: [
|
fields: [
|
||||||
@@ -214,10 +214,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
activeForm = name;
|
activeForm = name;
|
||||||
const def = forms[name];
|
const def = formDefs[name];
|
||||||
|
|
||||||
// activate clicked button
|
// activate clicked button
|
||||||
const idx = Object.keys(forms).indexOf(name);
|
const idx = Object.keys(formDefs).indexOf(name);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
buttons[idx].classList.add('active');
|
buttons[idx].classList.add('active');
|
||||||
if (name === 'websocket') buttons[idx].classList.add('ws');
|
if (name === 'websocket') buttons[idx].classList.add('ws');
|
||||||
@@ -236,7 +236,7 @@
|
|||||||
${f.hint ? `<span class="hint">${f.hint}</span>` : ''}
|
${f.hint ? `<span class="hint">${f.hint}</span>` : ''}
|
||||||
</div>`;
|
</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;
|
fieldsEl.innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func main() {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
DbInit(ctx)
|
DbInit(ctx)
|
||||||
|
|
||||||
http.HandleFunc("/new/client", withCORS(HttpHandleNewUser))
|
http.HandleFunc("/new/client", withCORS(HttpHandleNewClient))
|
||||||
http.HandleFunc("/new/token", withCORS(HttpHandleNewToken))
|
http.HandleFunc("/new/token", withCORS(HttpHandleNewToken))
|
||||||
http.HandleFunc("/new/group", withCORS(HttpHandeNewGroup))
|
http.HandleFunc("/new/group", withCORS(HttpHandeNewGroup))
|
||||||
http.HandleFunc("/mod/group/addclients", withCORS(HttpHandleGroupAddClient))
|
http.HandleFunc("/mod/group/addclients", withCORS(HttpHandleGroupAddClient))
|
||||||
|
|||||||
Reference in New Issue
Block a user