Ramesh-vani commited on
Commit
f493a93
·
verified ·
1 Parent(s): a1b1f1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -199,17 +199,28 @@ async def get_file_content(websocket, key,project_name, path,rpath,name,connecte
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",
207
- "content": content,
208
- 'fileName':name,
209
- 'rfilePath':rpath,
210
- 'filePath':path,
211
- }
212
- await websocket.send(json.dumps(event))
 
 
 
 
 
 
 
 
 
 
 
213
  except Exception as e:
214
  event = {
215
  "type": "error",
 
199
  file_path = os.path.join(os.getcwd(), 'projects', key,project_name, rpath)
200
 
201
  try:
202
+ try:
203
+ with open(file_path, 'r') as file:
204
+ content = file.read()
205
+ event = {
206
+ "type": "content",
207
+ "content": content,
208
+ 'fileName':name,
209
+ 'rfilePath':rpath,
210
+ 'filePath':path,
211
+ }
212
+ await websocket.send(json.dumps(event))
213
+ except UnicodeDecodeError:
214
+ with open(file_path, 'rb') as file:
215
+ content = file.read()
216
+ event = {
217
+ "type": "content",
218
+ "content": content,
219
+ 'fileName':name,
220
+ 'rfilePath':rpath,
221
+ 'filePath':path,
222
+ }
223
+ await websocket.send(json.dumps(event))
224
  except Exception as e:
225
  event = {
226
  "type": "error",