Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -525,21 +525,30 @@ async def handle_user_input(websocket,key, process, connected,process_ids):
|
|
525 |
elif event["command"]["type"]=="write":
|
526 |
|
527 |
await wirte_file(websocket, key,event["project_name"], event["path"], event["content"], connected)
|
528 |
-
elif event["command"]["type"]=="curl":
|
529 |
method = event.get("method", "GET")
|
530 |
url = event["url"]
|
531 |
body = event.get("data", "")
|
532 |
headers = event.get("headers", {})
|
533 |
-
|
534 |
-
|
535 |
if method.upper() == "GET":
|
536 |
response = requests.get(url, headers=headers)
|
537 |
elif method.upper() == "POST":
|
538 |
response = requests.post(url, data=body, headers=headers)
|
539 |
else:
|
540 |
response = {"error": "Unsupported method"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
# Parse HTML content
|
542 |
souptmp = BeautifulSoup(response.text, "html.parser")
|
|
|
543 |
# Step 1: Define the initial HTML string
|
544 |
html_str = """
|
545 |
<!DOCTYPE html>
|
@@ -547,7 +556,7 @@ async def handle_user_input(websocket,key, process, connected,process_ids):
|
|
547 |
<head>
|
548 |
<meta charset="UTF-8">
|
549 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
550 |
-
|
551 |
</head>
|
552 |
<body>
|
553 |
<h1>Hello, World!</h1>
|
@@ -558,25 +567,23 @@ async def handle_user_input(websocket,key, process, connected,process_ids):
|
|
558 |
# Step 2: Parse the initial HTML content
|
559 |
soup = BeautifulSoup(html_str, 'html.parser')
|
560 |
|
561 |
-
# Step 3:
|
562 |
-
new_body_content = souptmp
|
563 |
-
|
564 |
-
# Step 4: Parse the new HTML snippet
|
565 |
-
new_body = BeautifulSoup(new_body_content, 'html.parser')
|
566 |
-
|
567 |
-
# Step 5: Replace the existing body content with the new content
|
568 |
if soup.body:
|
569 |
soup.body.clear()
|
570 |
-
|
|
|
571 |
else:
|
572 |
print("No <body> tag found in the HTML")
|
573 |
-
|
|
|
574 |
soup = inline_resources(soup, url)
|
|
|
575 |
response_data = {
|
576 |
"type": "web-data",
|
577 |
"data": str(soup),
|
578 |
}
|
579 |
await websocket.send(json.dumps(response_data))
|
|
|
580 |
elif event["command"]["type"]=="create":
|
581 |
if event["item"]=="folder":
|
582 |
await create_folder(websocket, key,event["project_name"], event["path"],event["name"],event['root'],event['targetElementData'],event["rpath"], connected)
|
@@ -910,57 +917,65 @@ async def exe(websocket,connected,key,process_ids):
|
|
910 |
elif event["command"]["type"]=="write":
|
911 |
|
912 |
await wirte_file(websocket, key,event["project_name"], event["path"], event["content"], connected)
|
913 |
-
elif event["command"]["type"]=="curl":
|
914 |
method = event.get("method", "GET")
|
915 |
url = event["url"]
|
916 |
body = event.get("data", "")
|
917 |
headers = event.get("headers", {})
|
918 |
-
|
919 |
if method.upper() == "GET":
|
920 |
response = requests.get(url, headers=headers)
|
921 |
elif method.upper() == "POST":
|
922 |
response = requests.post(url, data=body, headers=headers)
|
923 |
else:
|
924 |
response = {"error": "Unsupported method"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
925 |
# Parse HTML content
|
926 |
souptmp = BeautifulSoup(response.text, "html.parser")
|
927 |
-
|
|
|
928 |
html_str = """
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
soup = BeautifulSoup(html_str, 'html.parser')
|
944 |
-
|
945 |
-
|
946 |
-
new_body_content = souptmp
|
947 |
-
|
948 |
-
# Step 4: Parse the new HTML snippet
|
949 |
-
new_body = BeautifulSoup(new_body_content, 'html.parser')
|
950 |
-
|
951 |
-
# Step 5: Replace the existing body content with the new content
|
952 |
if soup.body:
|
953 |
-
|
954 |
-
|
|
|
955 |
else:
|
956 |
-
|
957 |
-
|
|
|
958 |
soup = inline_resources(soup, url)
|
|
|
959 |
response_data = {
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
await websocket.send(json.dumps(response_data))
|
|
|
964 |
elif event["command"]["type"]=="create":
|
965 |
if event["item"]=="folder":
|
966 |
await create_folder(websocket, key,event["project_name"], event["path"],event["name"],event['root'],event['targetElementData'],event["rpath"], connected)
|
|
|
525 |
elif event["command"]["type"]=="write":
|
526 |
|
527 |
await wirte_file(websocket, key,event["project_name"], event["path"], event["content"], connected)
|
528 |
+
elif event["command"]["type"] == "curl":
|
529 |
method = event.get("method", "GET")
|
530 |
url = event["url"]
|
531 |
body = event.get("data", "")
|
532 |
headers = event.get("headers", {})
|
533 |
+
|
|
|
534 |
if method.upper() == "GET":
|
535 |
response = requests.get(url, headers=headers)
|
536 |
elif method.upper() == "POST":
|
537 |
response = requests.post(url, data=body, headers=headers)
|
538 |
else:
|
539 |
response = {"error": "Unsupported method"}
|
540 |
+
|
541 |
+
if isinstance(response, dict):
|
542 |
+
response_data = {
|
543 |
+
"type": "error",
|
544 |
+
"data": response,
|
545 |
+
}
|
546 |
+
await websocket.send(json.dumps(response_data))
|
547 |
+
return
|
548 |
+
|
549 |
# Parse HTML content
|
550 |
souptmp = BeautifulSoup(response.text, "html.parser")
|
551 |
+
|
552 |
# Step 1: Define the initial HTML string
|
553 |
html_str = """
|
554 |
<!DOCTYPE html>
|
|
|
556 |
<head>
|
557 |
<meta charset="UTF-8">
|
558 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
559 |
+
|
560 |
</head>
|
561 |
<body>
|
562 |
<h1>Hello, World!</h1>
|
|
|
567 |
# Step 2: Parse the initial HTML content
|
568 |
soup = BeautifulSoup(html_str, 'html.parser')
|
569 |
|
570 |
+
# Step 3: Replace the existing body content with the new content from souptmp
|
|
|
|
|
|
|
|
|
|
|
|
|
571 |
if soup.body:
|
572 |
soup.body.clear()
|
573 |
+
for content in souptmp.body.contents:
|
574 |
+
soup.body.append(content)
|
575 |
else:
|
576 |
print("No <body> tag found in the HTML")
|
577 |
+
|
578 |
+
# Inline CSS and JavaScript
|
579 |
soup = inline_resources(soup, url)
|
580 |
+
|
581 |
response_data = {
|
582 |
"type": "web-data",
|
583 |
"data": str(soup),
|
584 |
}
|
585 |
await websocket.send(json.dumps(response_data))
|
586 |
+
|
587 |
elif event["command"]["type"]=="create":
|
588 |
if event["item"]=="folder":
|
589 |
await create_folder(websocket, key,event["project_name"], event["path"],event["name"],event['root'],event['targetElementData'],event["rpath"], connected)
|
|
|
917 |
elif event["command"]["type"]=="write":
|
918 |
|
919 |
await wirte_file(websocket, key,event["project_name"], event["path"], event["content"], connected)
|
920 |
+
elif event["command"]["type"] == "curl":
|
921 |
method = event.get("method", "GET")
|
922 |
url = event["url"]
|
923 |
body = event.get("data", "")
|
924 |
headers = event.get("headers", {})
|
925 |
+
|
926 |
if method.upper() == "GET":
|
927 |
response = requests.get(url, headers=headers)
|
928 |
elif method.upper() == "POST":
|
929 |
response = requests.post(url, data=body, headers=headers)
|
930 |
else:
|
931 |
response = {"error": "Unsupported method"}
|
932 |
+
|
933 |
+
if isinstance(response, dict):
|
934 |
+
response_data = {
|
935 |
+
"type": "error",
|
936 |
+
"data": response,
|
937 |
+
}
|
938 |
+
await websocket.send(json.dumps(response_data))
|
939 |
+
return
|
940 |
+
|
941 |
# Parse HTML content
|
942 |
souptmp = BeautifulSoup(response.text, "html.parser")
|
943 |
+
|
944 |
+
# Step 1: Define the initial HTML string
|
945 |
html_str = """
|
946 |
+
<!DOCTYPE html>
|
947 |
+
<html lang="en">
|
948 |
+
<head>
|
949 |
+
<meta charset="UTF-8">
|
950 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
951 |
+
|
952 |
+
</head>
|
953 |
+
<body>
|
954 |
+
<h1>Hello, World!</h1>
|
955 |
+
</body>
|
956 |
+
</html>
|
957 |
+
"""
|
958 |
+
|
959 |
+
# Step 2: Parse the initial HTML content
|
960 |
soup = BeautifulSoup(html_str, 'html.parser')
|
961 |
+
|
962 |
+
# Step 3: Replace the existing body content with the new content from souptmp
|
|
|
|
|
|
|
|
|
|
|
|
|
963 |
if soup.body:
|
964 |
+
soup.body.clear()
|
965 |
+
for content in souptmp.body.contents:
|
966 |
+
soup.body.append(content)
|
967 |
else:
|
968 |
+
print("No <body> tag found in the HTML")
|
969 |
+
|
970 |
+
# Inline CSS and JavaScript
|
971 |
soup = inline_resources(soup, url)
|
972 |
+
|
973 |
response_data = {
|
974 |
+
"type": "web-data",
|
975 |
+
"data": str(soup),
|
976 |
+
}
|
977 |
await websocket.send(json.dumps(response_data))
|
978 |
+
|
979 |
elif event["command"]["type"]=="create":
|
980 |
if event["item"]=="folder":
|
981 |
await create_folder(websocket, key,event["project_name"], event["path"],event["name"],event['root'],event['targetElementData'],event["rpath"], connected)
|