Prechádzať zdrojové kódy

【优化】压缩返回网页

PJ-568 2 rokov pred
rodič
commit
07246869a2
1 zmenil súbory, kde vykonal 2 pridanie a 44 odobranie
  1. 2 44
      server.py

+ 2 - 44
server.py

@@ -149,54 +149,12 @@ class ChatServer(http.server.BaseHTTPRequestHandler):
             self.rooms[section] = config.get(section, 'messages').split('\n')
 
     def generate_chat_html(self, nickname, roomid):
-        return f'''
-<!DOCTYPE html>
-<html lang="zh-Hans">
-<head>
-	<meta charset="UTF-8">
-	<title>聊天室 - {roomid}</title>
-	<link type="text/css" rel="stylesheet" href="html-chat.css">
-	<meta name="viewport" content="width=192, initial-scale=1.0">
-</head>
-<body>
-	<div class="container">
-		<form action="./send_message" method="post">
-			<fieldset>
-				<legend>聊天室 - {roomid}</legend>
-				<iframe src="./log?id={roomid}" frameborder="0">加载中……</iframe>
-				<br>
-				<label for="messageInput">{nickname}说:</label>
-				<input type="text" id="messageInput" name="messageInput">
-				<button type="submit">发送</button>
-				<a href=".">退出</a>
-			</fieldset>
-			<input type="text" id="nickname" name="nickname" value="{nickname}" style="display: none;">
-			<input type="text" id="roomid" name="roomid" value="{roomid}" style="display: none;">
-		</form>
-	</div>
-</body>
-</html>
-'''.encode('utf-8')
+        return f'''<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><title>聊天室 - {roomid}</title><link type="text/css" rel="stylesheet" href="html-chat.css"><meta name="viewport" content="width=192, initial-scale=1.0"></head><body><div class="container"><form action="./send_message" method="post"><fieldset><legend>聊天室 - {roomid}</legend><iframe src="./log?id={roomid}" frameborder="0">加载中……</iframe><br><label for="messageInput">{nickname}说:</label><input type="text" id="messageInput" name="messageInput"><button type="submit">发送</button><a href=".">退出</a></fieldset><input type="text" id="nickname" name="nickname" value="{nickname}" style="display: none;"><input type="text" id="roomid" name="roomid" value="{roomid}" style="display: none;"></form></div></body></html>'''.encode('utf-8')
 
     def generate_chat_log_html(self, roomid):
         messages = self.rooms.get(roomid, [])
         chat_log = '<br>'.join(messages) if messages else '<p style="color:#ccc">无聊天记录</p>'
-        return f'''
-<!DOCTYPE html>
-<html lang="zh-Hans">
-<head>
-	<meta charset="UTF-8">
-	<title>聊天记录 - {roomid}</title>
-	<meta name="viewport" content="width=device-width, initial-scale=1.0">
-	<meta http-equiv="refresh" content="60">
-</head>
-<body style="font-family: Arial, sans-serif;">
-	<span>
-		{chat_log}
-	</span>
-</body>
-</html>
-'''.encode('utf-8')
+        return f'''<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><title>聊天记录 - {roomid}</title><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="refresh" content="60"></head><body style="font-family: Arial, sans-serif;"><span>{chat_log}</span></body></html>'''.encode('utf-8')
 
     def send_file(self, filename):
         try: