Add HTML charset

This commit is contained in:
zimplexing
2025-07-14 13:31:02 +08:00
parent 2d1d6be6b0
commit ee805960cc
3 changed files with 30 additions and 9124 deletions

3
.gitignore vendored
View File

@@ -23,4 +23,5 @@ expo-env.d.ts
web/** web/**
.bmad-core .bmad-core
.kilocodemodes .kilocodemodes
.roomodes .roomode
yarn-errors.log

View File

@@ -1,4 +1,4 @@
import TCPHttpServer from './tcpHttpServer'; import TCPHttpServer from "./tcpHttpServer";
const getRemotePageHTML = () => { const getRemotePageHTML = () => {
return ` return `
@@ -6,6 +6,7 @@ const getRemotePageHTML = () => {
<html> <html>
<head> <head>
<title>OrionTV Remote</title> <title>OrionTV Remote</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<style> <style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; background-color: #121212; color: white; } body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; background-color: #121212; color: white; }
@@ -57,55 +58,55 @@ class RemoteControlService {
private setupRequestHandler() { private setupRequestHandler() {
this.httpServer.setRequestHandler((request) => { this.httpServer.setRequestHandler((request) => {
console.log('[RemoteControl] Received request:', request.method, request.url); console.log("[RemoteControl] Received request:", request.method, request.url);
try { try {
if (request.method === 'GET' && request.url === '/') { if (request.method === "GET" && request.url === "/") {
return { return {
statusCode: 200, statusCode: 200,
headers: { 'Content-Type': 'text/html' }, headers: { "Content-Type": "text/html; charset=utf-8" },
body: getRemotePageHTML() body: getRemotePageHTML(),
}; };
} else if (request.method === 'POST' && request.url === '/message') { } else if (request.method === "POST" && request.url === "/message") {
try { try {
const parsedBody = JSON.parse(request.body || '{}'); const parsedBody = JSON.parse(request.body || "{}");
const message = parsedBody.message; const message = parsedBody.message;
if (message) { if (message) {
this.onMessage(message); this.onMessage(message);
} }
return { return {
statusCode: 200, statusCode: 200,
headers: { 'Content-Type': 'application/json' }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ status: 'ok' }) body: JSON.stringify({ status: "ok" }),
}; };
} catch (parseError) { } catch (parseError) {
console.error('[RemoteControl] Failed to parse message body:', parseError); console.error("[RemoteControl] Failed to parse message body:", parseError);
return { return {
statusCode: 400, statusCode: 400,
headers: { 'Content-Type': 'application/json' }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ error: 'Invalid JSON' }) body: JSON.stringify({ error: "Invalid JSON" }),
}; };
} }
} else if (request.method === 'POST' && request.url === '/handshake') { } else if (request.method === "POST" && request.url === "/handshake") {
this.onHandshake(); this.onHandshake();
return { return {
statusCode: 200, statusCode: 200,
headers: { 'Content-Type': 'application/json' }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ status: 'ok' }) body: JSON.stringify({ status: "ok" }),
}; };
} else { } else {
return { return {
statusCode: 404, statusCode: 404,
headers: { 'Content-Type': 'text/plain' }, headers: { "Content-Type": "text/plain" },
body: 'Not Found' body: "Not Found",
}; };
} }
} catch (error) { } catch (error) {
console.error('[RemoteControl] Request handler error:', error); console.error("[RemoteControl] Request handler error:", error);
return { return {
statusCode: 500, statusCode: 500,
headers: { 'Content-Type': 'application/json' }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ error: 'Internal Server Error' }) body: JSON.stringify({ error: "Internal Server Error" }),
}; };
} }
}); });
@@ -117,20 +118,20 @@ class RemoteControlService {
} }
public async startServer(): Promise<string> { public async startServer(): Promise<string> {
console.log('[RemoteControl] Attempting to start server...'); console.log("[RemoteControl] Attempting to start server...");
try { try {
const url = await this.httpServer.start(); const url = await this.httpServer.start();
console.log(`[RemoteControl] Server started successfully at: ${url}`); console.log(`[RemoteControl] Server started successfully at: ${url}`);
return url; return url;
} catch (error) { } catch (error) {
console.error('[RemoteControl] Failed to start server:', error); console.error("[RemoteControl] Failed to start server:", error);
throw new Error(error instanceof Error ? error.message : 'Failed to start server'); throw new Error(error instanceof Error ? error.message : "Failed to start server");
} }
} }
public stopServer() { public stopServer() {
console.log('[RemoteControl] Stopping server...'); console.log("[RemoteControl] Stopping server...");
this.httpServer.stop(); this.httpServer.stop();
} }
@@ -139,4 +140,4 @@ class RemoteControlService {
} }
} }
export const remoteControlService = new RemoteControlService(); export const remoteControlService = new RemoteControlService();

File diff suppressed because it is too large Load Diff