Files
GaCy-GO/internal/sdkserver/api_tool_session.go
T

29 lines
834 B
Go

package sdkserver
import (
"encoding/json"
"gac-hkrpg-go/internal/common"
"net/http"
)
func apiToolSession(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
var req struct {
Connected bool `json:"connected"`
Client string `json:"client"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || (r.Header.Get("X-GaC-Srtool") != "1" && req.Client != "GaC-Srtool") {
http.Error(w, "explicit Srtool connection required", http.StatusBadRequest)
return
}
seconds, err := common.SetSrtoolConnection(req.Connected)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
writeJSON(w, map[string]any{"status": 200, "connected": req.Connected, "lease_seconds": seconds})
}