|
1 | 1 | from typing import Union |
2 | 2 | from fastapi import FastAPI, HTTPException |
3 | 3 | from fastapi.responses import HTMLResponse |
| 4 | +from fastapi.staticfiles import StaticFiles |
4 | 5 | from datetime import datetime |
5 | 6 | from atproto import Client, client_utils |
6 | 7 | from pydantic import BaseModel |
|
11 | 12 |
|
12 | 13 | app = FastAPI() |
13 | 14 |
|
| 15 | + |
| 16 | +# Mount the `static` directory to serve static files |
| 17 | +app.mount("/static", StaticFiles(directory="static"), name="static") |
| 18 | + |
14 | 19 | class SocialPost(BaseModel): |
15 | 20 | username: str |
16 | 21 | password: str |
@@ -59,24 +64,71 @@ def read_root(): |
59 | 64 | print(f"Error: {e}") |
60 | 65 | uptime_seconds, current_time, logs = "N/A", "N/A", ["Error reading metrics or logs"] |
61 | 66 |
|
| 67 | + # Get app version from environment variable |
| 68 | + app_version = os.environ.get("VERSION", "unknown") |
| 69 | + |
62 | 70 | return f""" |
63 | | - <pre> |
64 | | - ______ ______ ______ _ |
65 | | - | ___ \ | ___ \ | ___ \ | | |
66 | | - | |_/ / _ _ | |_/ / ___ | |_/ / ___ ___ | |_ ___ _ __ |
67 | | - | __/ | | | || ___ \/ __|| __/ / _ \ / __|| __| / _ \| '__| |
68 | | - | | | |_| || |_/ /\__ \| | | (_) |\__ \| |_ | __/| | |
69 | | - \_| \__, |\____/ |___/\_| \___/ |___/ \__| \___||_| |
70 | | - __/ | |
71 | | - |___/ |
72 | | - </pre> |
73 | | - <br/> |
74 | | - <br/> |
75 | | - <h1>Container Metrics</h1> |
76 | | - <p>Uptime: {uptimeoutput}</p> |
77 | | - <p>Last Updated: {current_time}</p> |
78 | | - <h2>Recent Logs:</h2> |
79 | | - <ul>{''.join(f'<li>{log}</li>' for log in logs)}</ul> |
| 71 | + <!DOCTYPE html> |
| 72 | + <html lang="en"> |
| 73 | + <head> |
| 74 | + <meta charset="UTF-8"> |
| 75 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 76 | + <title>PyBsPoster</title> |
| 77 | + <link rel="icon" href="/static/favicon.ico" type="image/x-icon"> |
| 78 | + <style> |
| 79 | + body {{ |
| 80 | + font-family: Arial, sans-serif; |
| 81 | + background-color: #f4f4f9; |
| 82 | + margin: 0; |
| 83 | + padding: 0; |
| 84 | + display: flex; |
| 85 | + justify-content: center; |
| 86 | + align-items: center; |
| 87 | + height: 100vh; |
| 88 | + }} |
| 89 | + .container {{ |
| 90 | + text-align: center; |
| 91 | + background: #ffffff; |
| 92 | + padding: 2em; |
| 93 | + border-radius: 8px; |
| 94 | + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); |
| 95 | + }} |
| 96 | + .logo {{ |
| 97 | + max-width: 200px; |
| 98 | + }} |
| 99 | + .title {{ |
| 100 | + color: #333; |
| 101 | + font-size: 1.2em; |
| 102 | + margin: 20px 0; |
| 103 | + }} |
| 104 | + h1 {{ |
| 105 | + color: #333; |
| 106 | + font-size: 2em; |
| 107 | + }} |
| 108 | + p {{ |
| 109 | + color: #555; |
| 110 | + font-size: 1.2em; |
| 111 | + }} |
| 112 | + .version {{ |
| 113 | + margin-top: 1em; |
| 114 | + font-weight: bold; |
| 115 | + color: #007BFF; |
| 116 | + }} |
| 117 | + </style> |
| 118 | + </head> |
| 119 | + <body> |
| 120 | + <div class="container"> |
| 121 | + <img src="/static/logo3.png" alt="Logo" class="logo"> |
| 122 | + <h1 class="title">Welcome to PyBSPoster</h1> |
| 123 | + <p>The application is running smoothly.</p> |
| 124 | + <p>Documentation for this instance can be found:</p> |
| 125 | + <div class="title"><a href="/docs">Swagger (OpenAPI)</a><br/><a href="/redoc">Redocs</a><br/></div> |
| 126 | + <div class="version">Version: {app_version}</div><br/><br/> |
| 127 | + <div>Uptime: {uptimeoutput}</div><br/><br/> |
| 128 | + <div>Last Updated: {current_time}</div> |
| 129 | + </div> |
| 130 | + </body> |
| 131 | + </html> |
80 | 132 | """ |
81 | 133 |
|
82 | 134 |
|
@@ -112,6 +164,18 @@ async def preview_social(post: SocialPost): |
112 | 164 |
|
113 | 165 | @app.post("/post") |
114 | 166 | async def post_social(post: SocialPost): |
| 167 | + """ |
| 168 | + Post to BlueSky. |
| 169 | +
|
| 170 | + Args: |
| 171 | + post (SocialPost): Contains the text, optional link |
| 172 | + username and password for your BlueSky account. |
| 173 | +
|
| 174 | + NOTE: baseURL is not used for BlueSky, but is included for consistency. |
| 175 | +
|
| 176 | + Returns: |
| 177 | + Response from Bluesky or status message. |
| 178 | + """ |
115 | 179 | # Debug |
116 | 180 | # print(f"Received username: {post.username}", flush=True) |
117 | 181 | # print(f"Received password: {post.password}", flush=True) |
@@ -162,8 +226,10 @@ async def post_to_mastodon(post: SocialPost): |
162 | 226 | post (SocialPost): Contains the text, optional link, and the Mastodon instance URL (baseURL). |
163 | 227 | the password is the API key for Mastodon. |
164 | 228 |
|
| 229 | + NOTE: The username is not used for Mastodon, but is included for consistency. |
| 230 | +
|
165 | 231 | Returns: |
166 | | - dict: Response from Mastodon or status message. |
| 232 | + Response from Mastodon or status message. |
167 | 233 | """ |
168 | 234 | # Ensure the baseURL is provided for Mastodon posts |
169 | 235 | if not post.baseURL: |
|
0 commit comments