Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,6 +98,27 @@ async def delete_item(websocket, key,project_name, path, connected):
|
|
| 98 |
# print(e)
|
| 99 |
websockets.broadcast(connected,str(e))
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
async def create_file(websocket, key,project_name, path,name, connected):
|
| 102 |
file_path = os.path.join(os.getcwd(), 'projects', key,project_name, path,name)
|
| 103 |
# Create the file
|
|
@@ -310,6 +331,9 @@ async def exe(websocket,connected,key):
|
|
| 310 |
elif event["command"]["type"]=="delete":
|
| 311 |
|
| 312 |
await delete_item(websocket, key,event["project_name"], event["path"], connected)
|
|
|
|
|
|
|
|
|
|
| 313 |
elif event["command"]["type"]=="rename":
|
| 314 |
|
| 315 |
await rename_item(websocket, key,event["project_name"], event["path"], event["name"], connected)
|
|
|
|
| 98 |
# print(e)
|
| 99 |
websockets.broadcast(connected,str(e))
|
| 100 |
|
| 101 |
+
async def get_file_content(websocket, key,project_name, path,connected):
|
| 102 |
+
|
| 103 |
+
file_path = path
|
| 104 |
+
|
| 105 |
+
try:
|
| 106 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 107 |
+
content = file.read()
|
| 108 |
+
event = {
|
| 109 |
+
"type": "content",
|
| 110 |
+
"content": content,
|
| 111 |
+
}
|
| 112 |
+
await websocket.send(json.dumps(event))
|
| 113 |
+
except Exception as e:
|
| 114 |
+
event = {
|
| 115 |
+
"type": "error",
|
| 116 |
+
"message": f"Failed to read file content: {str(e)}"},
|
| 117 |
+
}
|
| 118 |
+
await websocket.send(json.dumps(event))
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
|
| 122 |
async def create_file(websocket, key,project_name, path,name, connected):
|
| 123 |
file_path = os.path.join(os.getcwd(), 'projects', key,project_name, path,name)
|
| 124 |
# Create the file
|
|
|
|
| 331 |
elif event["command"]["type"]=="delete":
|
| 332 |
|
| 333 |
await delete_item(websocket, key,event["project_name"], event["path"], connected)
|
| 334 |
+
elif event["command"]["type"]=="get_content":
|
| 335 |
+
|
| 336 |
+
await get_file_content(websocket, key,event["project_name"], event["path"], connected)
|
| 337 |
elif event["command"]["type"]=="rename":
|
| 338 |
|
| 339 |
await rename_item(websocket, key,event["project_name"], event["path"], event["name"], connected)
|