Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,13 @@ import requests
|
|
12 |
from watchdog.observers import Observer
|
13 |
from watchdog.events import FileSystemEventHandler
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
class FileHandler(FileSystemEventHandler):
|
16 |
def __init__(self, websocket,connected):
|
17 |
super().__init__()
|
@@ -192,7 +199,8 @@ async def get_file_content(websocket, key,project_name, path,rpath,name,connecte
|
|
192 |
file_path = os.path.join(os.getcwd(), 'projects', key,project_name, rpath)
|
193 |
|
194 |
try:
|
195 |
-
|
|
|
196 |
content = file.read()
|
197 |
event = {
|
198 |
"type": "content",
|
@@ -242,20 +250,14 @@ async def create_folder(websocket, key,project_name, path,name,root,targetElemen
|
|
242 |
# print(folder_path,'created')
|
243 |
websockets.broadcast(connected,json.dumps(event))
|
244 |
|
245 |
-
|
246 |
-
if isinstance(content, str):
|
247 |
-
return 'w' # If content is a string, it's text
|
248 |
-
elif isinstance(content, bytes):
|
249 |
-
return 'wb' # If content is bytes, it's binary
|
250 |
-
else:
|
251 |
-
raise ValueError("Unsupported content type. Expected str or bytes.")
|
252 |
|
253 |
async def wirte_file(websocket, key,project_name, path, content, connected):
|
254 |
try:
|
255 |
file_path = os.path.join(os.getcwd(), 'projects', key,project_name, path)
|
256 |
file_content = content
|
257 |
mode = auto_detect_mode(content)
|
258 |
-
with open(file_path,
|
259 |
file.write(file_content)
|
260 |
|
261 |
event = {
|
@@ -599,7 +601,7 @@ async def create_file_structure(websocket, data, base_path='.'):
|
|
599 |
elif data['type'] == 'file':
|
600 |
mode = auto_detect_mode(data['content'])
|
601 |
file_path = os.path.join(base_path, data['name'])
|
602 |
-
with open(file_path,
|
603 |
file.write(data['content'])
|
604 |
|
605 |
event = {
|
|
|
12 |
from watchdog.observers import Observer
|
13 |
from watchdog.events import FileSystemEventHandler
|
14 |
|
15 |
+
def auto_detect_mode(content):
|
16 |
+
if isinstance(content, str):
|
17 |
+
return 'w' # If content is a string, it's text
|
18 |
+
elif isinstance(content, bytes):
|
19 |
+
return 'wb' # If content is bytes, it's binary
|
20 |
+
else:
|
21 |
+
raise ValueError("Unsupported content type. Expected str or bytes.")
|
22 |
class FileHandler(FileSystemEventHandler):
|
23 |
def __init__(self, websocket,connected):
|
24 |
super().__init__()
|
|
|
199 |
file_path = os.path.join(os.getcwd(), 'projects', key,project_name, rpath)
|
200 |
|
201 |
try:
|
202 |
+
mode = auto_detect_mode(content)
|
203 |
+
with open(file_path, mode) as file:
|
204 |
content = file.read()
|
205 |
event = {
|
206 |
"type": "content",
|
|
|
250 |
# print(folder_path,'created')
|
251 |
websockets.broadcast(connected,json.dumps(event))
|
252 |
|
253 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
async def wirte_file(websocket, key,project_name, path, content, connected):
|
256 |
try:
|
257 |
file_path = os.path.join(os.getcwd(), 'projects', key,project_name, path)
|
258 |
file_content = content
|
259 |
mode = auto_detect_mode(content)
|
260 |
+
with open(file_path, mode) as file:
|
261 |
file.write(file_content)
|
262 |
|
263 |
event = {
|
|
|
601 |
elif data['type'] == 'file':
|
602 |
mode = auto_detect_mode(data['content'])
|
603 |
file_path = os.path.join(base_path, data['name'])
|
604 |
+
with open(file_path,mode) as file:
|
605 |
file.write(data['content'])
|
606 |
|
607 |
event = {
|