Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,17 @@ JOIN = {}
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
async def execute_command(websocket, project_name, command):
|
| 20 |
base_path = os.path.join(os.getcwd(), 'projects', project_name)
|
| 21 |
|
|
@@ -159,8 +170,8 @@ async def exe(websocket,connected):
|
|
| 159 |
if "command" in event:
|
| 160 |
await execute_command(websocket, event["project_name"], event["command"])
|
| 161 |
elif "write" in event:
|
| 162 |
-
|
| 163 |
-
await
|
| 164 |
|
| 165 |
else:
|
| 166 |
# First player starts a new game.
|
|
|
|
| 16 |
|
| 17 |
WATCH = {}
|
| 18 |
|
| 19 |
+
async def wirte_file(websocket, project_name, path, content):
|
| 20 |
+
try:
|
| 21 |
+
file_path = os.path.join(os.getcwd(), 'projects', project_name, path)
|
| 22 |
+
file_content = content
|
| 23 |
+
with open(file_path, 'w', encoding='utf-8') as file:
|
| 24 |
+
file.write(file_content)
|
| 25 |
+
await websocket.send(f"Content written to {file_path}")
|
| 26 |
+
except FileNotFoundError as e:
|
| 27 |
+
await websocket.send(f"Error: {str(e)}")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
async def execute_command(websocket, project_name, command):
|
| 31 |
base_path = os.path.join(os.getcwd(), 'projects', project_name)
|
| 32 |
|
|
|
|
| 170 |
if "command" in event:
|
| 171 |
await execute_command(websocket, event["project_name"], event["command"])
|
| 172 |
elif "write" in event:
|
| 173 |
+
|
| 174 |
+
await wirte_file(websocket, event["project_name"], event["path"], event["content"]) #Todo
|
| 175 |
|
| 176 |
else:
|
| 177 |
# First player starts a new game.
|