Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -719,37 +719,20 @@ async def get_homepage():
|
|
| 719 |
</html>
|
| 720 |
"""
|
| 721 |
|
| 722 |
-
# --- ADDED FOR /last_action --- START ---
|
| 723 |
@app.get("/last_action", response_class=HTMLResponse)
|
| 724 |
async def get_last_action():
|
| 725 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 726 |
file_content_raw = ""
|
| 727 |
error_message = None
|
| 728 |
-
# --- Add Debugging ---
|
| 729 |
-
print("--- Debugging /last_action ---")
|
| 730 |
-
current_cwd = os.getcwd()
|
| 731 |
-
print(f"Current Working Directory: {current_cwd}")
|
| 732 |
-
absolute_path = os.path.abspath(LAST_ACTION_FILE)
|
| 733 |
-
print(f"Attempting to read absolute path: {absolute_path}")
|
| 734 |
-
print(f"Checking existence with os.path.exists: {os.path.exists(absolute_path)}")
|
| 735 |
-
try:
|
| 736 |
-
print(f"Listing contents of CWD ({current_cwd}): {os.listdir(current_cwd)}")
|
| 737 |
-
except Exception as list_err:
|
| 738 |
-
print(f"Could not list CWD: {list_err}")
|
| 739 |
-
try:
|
| 740 |
-
# Explicitly check /app if CWD is different
|
| 741 |
-
if current_cwd != '/app':
|
| 742 |
-
print(f"Listing contents of /app: {os.listdir('/app')}")
|
| 743 |
-
except Exception as list_err:
|
| 744 |
-
print(f"Could not list /app: {list_err}")
|
| 745 |
-
print("--- End Debugging ---")
|
| 746 |
-
# --- End Debugging ---
|
| 747 |
try:
|
| 748 |
# Read the file content fresh on each request
|
| 749 |
with open(LAST_ACTION_FILE, "r", encoding="utf-8") as f:
|
| 750 |
file_content_raw = f.read()
|
| 751 |
except FileNotFoundError:
|
| 752 |
-
error_message = f"Error:
|
| 753 |
print(f"WARN: {error_message}") # Log server-side
|
| 754 |
except Exception as e:
|
| 755 |
error_message = f"An unexpected error occurred while reading '{LAST_ACTION_FILE}': {e}"
|
|
@@ -757,10 +740,11 @@ async def get_last_action():
|
|
| 757 |
traceback.print_exc() # Log full traceback for debugging
|
| 758 |
|
| 759 |
# Escape the raw content to prevent XSS if the file contains HTML/JS
|
| 760 |
-
# Display error message if reading failed
|
| 761 |
display_content = html.escape(file_content_raw) if not error_message else error_message
|
|
|
|
|
|
|
| 762 |
|
| 763 |
-
# Create the simple HTML response
|
| 764 |
html_output = f"""
|
| 765 |
<!DOCTYPE html>
|
| 766 |
<html lang="en">
|
|
@@ -769,55 +753,93 @@ async def get_last_action():
|
|
| 769 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 770 |
<title>Last Action Log</title>
|
| 771 |
<style>
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
|
|
|
|
|
|
| 778 |
margin: 0;
|
|
|
|
| 779 |
}}
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
|
|
|
| 785 |
}}
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 798 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 799 |
.error {{
|
| 800 |
-
|
|
|
|
|
|
|
| 801 |
font-weight: bold;
|
| 802 |
-
background-color:
|
| 803 |
-
border: 1px solid #
|
| 804 |
-
padding: 15px;
|
| 805 |
-
border-radius:
|
|
|
|
|
|
|
| 806 |
}}
|
| 807 |
</style>
|
| 808 |
</head>
|
| 809 |
<body>
|
| 810 |
-
<
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
// Optional: Auto-refresh the page every N seconds
|
| 814 |
-
// setTimeout(() => window.location.reload(), 5000); // Refresh every 5 seconds
|
| 815 |
-
</script>
|
| 816 |
</body>
|
| 817 |
</html>
|
| 818 |
"""
|
| 819 |
return HTMLResponse(content=html_output)
|
| 820 |
-
# --- ADDED FOR /last_action --- END ---
|
| 821 |
|
| 822 |
|
| 823 |
@app.websocket("/ws")
|
|
|
|
| 719 |
</html>
|
| 720 |
"""
|
| 721 |
|
|
|
|
| 722 |
@app.get("/last_action", response_class=HTMLResponse)
|
| 723 |
async def get_last_action():
|
| 724 |
+
"""
|
| 725 |
+
Serves a simple HTML page displaying the content of last_action.txt,
|
| 726 |
+
styled for OBS integration.
|
| 727 |
+
"""
|
| 728 |
file_content_raw = ""
|
| 729 |
error_message = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 730 |
try:
|
| 731 |
# Read the file content fresh on each request
|
| 732 |
with open(LAST_ACTION_FILE, "r", encoding="utf-8") as f:
|
| 733 |
file_content_raw = f.read()
|
| 734 |
except FileNotFoundError:
|
| 735 |
+
error_message = f"Error: File '{LAST_ACTION_FILE}' not found."
|
| 736 |
print(f"WARN: {error_message}") # Log server-side
|
| 737 |
except Exception as e:
|
| 738 |
error_message = f"An unexpected error occurred while reading '{LAST_ACTION_FILE}': {e}"
|
|
|
|
| 740 |
traceback.print_exc() # Log full traceback for debugging
|
| 741 |
|
| 742 |
# Escape the raw content to prevent XSS if the file contains HTML/JS
|
|
|
|
| 743 |
display_content = html.escape(file_content_raw) if not error_message else error_message
|
| 744 |
+
# Use a class to differentiate normal content from error messages for styling
|
| 745 |
+
content_class = "error" if error_message else "log-content"
|
| 746 |
|
| 747 |
+
# Create the simple HTML response with updated styles for OBS
|
| 748 |
html_output = f"""
|
| 749 |
<!DOCTYPE html>
|
| 750 |
<html lang="en">
|
|
|
|
| 753 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 754 |
<title>Last Action Log</title>
|
| 755 |
<style>
|
| 756 |
+
/* Import fonts to potentially match the main stream interface */
|
| 757 |
+
/* You already import Poppins and Press Start 2P in the main '/' route's HTML */
|
| 758 |
+
/* No extra import needed here if loaded by the browser already, but safe to include */
|
| 759 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&family=Press+Start+2P&display=swap');
|
| 760 |
+
|
| 761 |
+
/* Basic Reset */
|
| 762 |
+
* {{
|
| 763 |
+
box-sizing: border-box;
|
| 764 |
margin: 0;
|
| 765 |
+
padding: 0;
|
| 766 |
}}
|
| 767 |
+
|
| 768 |
+
/* Ensure html and body take full height/width and hide overflow */
|
| 769 |
+
html, body {{
|
| 770 |
+
height: 100%;
|
| 771 |
+
width: 100%;
|
| 772 |
+
overflow: hidden; /* Crucial for OBS Browser Source */
|
| 773 |
}}
|
| 774 |
+
|
| 775 |
+
body {{
|
| 776 |
+
/* Use a font that matches your stream's text */
|
| 777 |
+
font-family: 'Poppins', sans-serif;
|
| 778 |
+
/* Fallback font */
|
| 779 |
+
/* font-family: Consolas, 'Courier New', monospace; */
|
| 780 |
+
|
| 781 |
+
line-height: 1.5; /* Adjust line spacing if needed */
|
| 782 |
+
padding: 15px; /* Add some padding inside the OBS box */
|
| 783 |
+
|
| 784 |
+
/* Make background transparent for seamless overlay in OBS */
|
| 785 |
+
background-color: transparent;
|
| 786 |
+
|
| 787 |
+
/* Set default text color to white for dark OBS backgrounds */
|
| 788 |
+
color: #FFFFFF;
|
| 789 |
+
|
| 790 |
+
/* Center the text block */
|
| 791 |
+
display: flex;
|
| 792 |
+
justify-content: center;
|
| 793 |
+
align-items: center;
|
| 794 |
+
text-align: center;
|
| 795 |
+
}}
|
| 796 |
+
|
| 797 |
+
/* Wrapper for content, useful for centering and potential future overflow */
|
| 798 |
+
.content-wrapper {{
|
| 799 |
+
max-width: 100%;
|
| 800 |
+
max-height: 100%;
|
| 801 |
+
/* Optional: Add scroll if content exceeds OBS source size */
|
| 802 |
+
/* overflow-y: auto; */
|
| 803 |
}}
|
| 804 |
+
|
| 805 |
+
/* Style for the main action text */
|
| 806 |
+
.log-content {{
|
| 807 |
+
/* Significantly larger font size */
|
| 808 |
+
font-size: 2em; /* Example: Adjust as needed */
|
| 809 |
+
/* Alternative responsive size based on OBS source width: */
|
| 810 |
+
/* font-size: calc(12px + 1.8vw); */
|
| 811 |
+
|
| 812 |
+
white-space: pre-wrap; /* Allow text wrapping */
|
| 813 |
+
word-wrap: break-word; /* Break long words */
|
| 814 |
+
color: #EAEAEA; /* Slightly off-white */
|
| 815 |
+
|
| 816 |
+
/* Optional: Add subtle shadow for better readability on complex backgrounds */
|
| 817 |
+
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
|
| 818 |
+
}}
|
| 819 |
+
|
| 820 |
+
/* Style for error messages */
|
| 821 |
.error {{
|
| 822 |
+
font-family: 'Poppins', sans-serif; /* Keep font consistent */
|
| 823 |
+
font-size: 1.6em; /* Make errors large but slightly smaller than normal */
|
| 824 |
+
color: #FFBDBD; /* Light red text, visible on dark */
|
| 825 |
font-weight: bold;
|
| 826 |
+
background-color: rgba(100, 0, 0, 0.7); /* Dark red, semi-transparent */
|
| 827 |
+
border: 1px solid #FF8080; /* Lighter red border */
|
| 828 |
+
padding: 10px 15px;
|
| 829 |
+
border-radius: 8px;
|
| 830 |
+
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
|
| 831 |
+
white-space: normal; /* Allow errors to wrap normally */
|
| 832 |
}}
|
| 833 |
</style>
|
| 834 |
</head>
|
| 835 |
<body>
|
| 836 |
+
<div class="content-wrapper">
|
| 837 |
+
<div class="{content_class}">{display_content}</div>
|
| 838 |
+
</div>
|
|
|
|
|
|
|
|
|
|
| 839 |
</body>
|
| 840 |
</html>
|
| 841 |
"""
|
| 842 |
return HTMLResponse(content=html_output)
|
|
|
|
| 843 |
|
| 844 |
|
| 845 |
@app.websocket("/ws")
|