Added changes for Z1 Tower with CapLink

Added TinyBin Item code and some notes, Added CapLink API
This commit is contained in:
stratic-dev
2024-04-01 22:08:58 +01:00
parent b8be6e7aa8
commit dc59755384
7 changed files with 99 additions and 31 deletions

View File

@@ -41,6 +41,12 @@ func NewAPIServer(config *Config) *APIServer {
}
return s
}
func (s *APIServer) loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s.logger.Info("Received " + r.Method + " request from " + r.RemoteAddr + "path" + r.RequestURI + "\n")
next.ServeHTTP(w, r)
})
}
// Start starts the server in a new goroutine.
func (s *APIServer) Start() error {
@@ -54,6 +60,9 @@ func (s *APIServer) Start() error {
r.HandleFunc("/character/export", s.ExportSave)
r.HandleFunc("/api/ss/bbs/upload.php", s.ScreenShot)
r.HandleFunc("/api/ss/bbs/{id}", s.ScreenShotGet)
r.HandleFunc("/v1/crypt/commonkey/rsa", s.CapLinkCrypt)
r.Use(s.loggingMiddleware)
handler := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))(r)
s.httpServer.Handler = handlers.LoggingHandler(os.Stdout, handler)
s.httpServer.Addr = fmt.Sprintf(":%d", s.erupeConfig.API.Port)

View File

@@ -410,3 +410,23 @@ func (s *APIServer) ScreenShot(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(xmlData)
}
func (s *APIServer) CapLinkCrypt(w http.ResponseWriter, r *http.Request) {
// Extract query parameters
queryParams := r.URL.Query()
// Extracting specific query parameters
clientPubKey := queryParams.Get("client_pub_key")
deviceID := queryParams.Get("device_id")
platformID := queryParams.Get("platform_id")
contentID := queryParams.Get("content_id")
serverVersion := queryParams.Get("server_version")
clientVersion := queryParams.Get("client_version")
// Your business logic to generate response based on query parameters
response := fmt.Sprintf("Received request with client_pub_key: %s, device_id: %s, platform_id: %s, content_id: %s, server_version: %s, client_version: %s", clientPubKey, deviceID, platformID, contentID, serverVersion, clientVersion)
// Write response headers
w.WriteHeader(http.StatusOK)
// Write response body
w.Write([]byte(response))
}