Spaces:
Paused
Paused
Commit ยท
78e2e6b
1
Parent(s): 99e48df
refactor: professional Web UI overhaul with interactive Password Wall and improved Video Player
Browse files
app.py
CHANGED
|
@@ -87,23 +87,47 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
| 87 |
@app.get("/")
|
| 88 |
async def read_index(): return FileResponse("static/index.html")
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
@app.get("/view/{user_id}/{batch_id}")
|
| 91 |
async def view_batch(user_id: str, batch_id: str, password: Optional[str] = Query(None)):
|
| 92 |
user_dir = os.path.join(UPLOAD_DIR, user_id)
|
| 93 |
if not os.path.exists(user_dir): raise HTTPException(404)
|
| 94 |
|
| 95 |
-
# Check batch password
|
| 96 |
meta = get_metadata(batch_id)
|
| 97 |
if meta and meta.get("password") and meta.get("password") != password:
|
| 98 |
-
return HTMLResponse(f""
|
| 99 |
-
<html><body style="background:#121212;color:white;text-align:center;padding:50px;font-family:sans-serif;">
|
| 100 |
-
<h2>๐ Password Protected</h2>
|
| 101 |
-
<form method="get">
|
| 102 |
-
<input type="password" name="password" placeholder="Enter Password" style="padding:10px;border-radius:5px;border:none;">
|
| 103 |
-
<button type="submit" style="padding:10px 20px;background:#2196F3;color:white;border:none;border-radius:5px;cursor:pointer;">Unlock</button>
|
| 104 |
-
</form>
|
| 105 |
-
</body></html>
|
| 106 |
-
""")
|
| 107 |
|
| 108 |
files_data = []
|
| 109 |
for f in os.listdir(user_dir):
|
|
@@ -120,19 +144,27 @@ async def view_batch(user_id: str, batch_id: str, password: Optional[str] = Quer
|
|
| 120 |
if not files_data: raise HTTPException(404)
|
| 121 |
files_data.sort(key=lambda x: x["raw"])
|
| 122 |
|
| 123 |
-
|
| 124 |
-
<div
|
| 125 |
-
<
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
| 129 |
</div>
|
| 130 |
</div>""" for f in files_data])
|
| 131 |
|
| 132 |
return HTMLResponse(f"""
|
| 133 |
-
<html><head><meta name="viewport" content="width=device-width, initial-scale=1">
|
| 134 |
-
<style>
|
| 135 |
-
</head><body><div class="container"><
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
""")
|
| 137 |
|
| 138 |
@app.get("/player/{filepath:path}")
|
|
@@ -141,45 +173,51 @@ async def video_player(filepath: str, password: Optional[str] = Query(None)):
|
|
| 141 |
path = os.path.join(UPLOAD_DIR, safe_path)
|
| 142 |
if not os.path.exists(path): raise HTTPException(404)
|
| 143 |
|
| 144 |
-
# Auth check
|
| 145 |
fname = os.path.basename(path)
|
| 146 |
meta = get_metadata(fname) or get_metadata(fname.split('_')[0])
|
| 147 |
if meta and meta.get("password") and meta.get("password") != password:
|
| 148 |
-
return HTMLResponse(
|
| 149 |
|
| 150 |
return HTMLResponse(f"""
|
| 151 |
<html><head><title>Pro Player</title><meta name="viewport" content="width=device-width, initial-scale=1">
|
| 152 |
-
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
</head><body>
|
| 154 |
-
<
|
| 155 |
-
<
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
</body></html>
|
| 159 |
""")
|
| 160 |
|
| 161 |
@app.get("/download/{filepath:path}")
|
| 162 |
-
async def download_file(filepath: str, password: Optional[str] = Query(None)):
|
| 163 |
safe_path = os.path.normpath(filepath).lstrip(os.sep)
|
| 164 |
path = os.path.join(UPLOAD_DIR, safe_path)
|
| 165 |
if not os.path.exists(path): raise HTTPException(404)
|
| 166 |
|
| 167 |
fname = os.path.basename(path)
|
| 168 |
-
# Check metadata for specific file or batch
|
| 169 |
meta = get_metadata(fname) or get_metadata(fname.split('_')[0])
|
| 170 |
|
|
|
|
| 171 |
if meta and meta.get("password") and meta.get("password") != password:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
raise HTTPException(403, "Password required.")
|
| 173 |
|
| 174 |
-
# Response with filename
|
| 175 |
resp = FileResponse(path, filename="_".join(fname.split("_")[1:]))
|
| 176 |
|
| 177 |
-
# Self Destruct Logic
|
| 178 |
if meta and meta.get("self_destruct"):
|
| 179 |
-
# We need to delete AFTER the response is sent.
|
| 180 |
-
# FastAPI's background tasks are perfect for this.
|
| 181 |
async def delete_after():
|
| 182 |
-
await asyncio.sleep(
|
| 183 |
try:
|
| 184 |
os.remove(path)
|
| 185 |
delete_metadata(fname)
|
|
|
|
| 87 |
@app.get("/")
|
| 88 |
async def read_index(): return FileResponse("static/index.html")
|
| 89 |
|
| 90 |
+
# --- PROFESSIONAL UI TEMPLATES ---
|
| 91 |
+
UI_STYLE = """
|
| 92 |
+
<style>
|
| 93 |
+
:root { --primary: #2196F3; --bg: #0f0f10; --card: #1a1a1c; --text: #e0e0e0; }
|
| 94 |
+
body { background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; margin: 0; display: flex; align-items: center; justify-content: center; min-height: 100vh; overflow-x: hidden; }
|
| 95 |
+
.container { width: 90%; max-width: 500px; animation: fadeIn 0.5s ease-out; }
|
| 96 |
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
| 97 |
+
.card { background: var(--card); padding: 30px; border-radius: 20px; box-shadow: 0 15px 35px rgba(0,0,0,0.3); border: 1px solid #333; text-align: center; }
|
| 98 |
+
h2 { color: var(--primary); margin-bottom: 20px; font-weight: 700; }
|
| 99 |
+
input { background: #2a2a2e; border: 1px solid #444; color: white; padding: 15px; border-radius: 12px; width: 100%; box-sizing: border-box; margin-bottom: 20px; font-size: 16px; outline: none; transition: 0.3s; }
|
| 100 |
+
input:focus { border-color: var(--primary); box-shadow: 0 0 10px rgba(33, 150, 243, 0.2); }
|
| 101 |
+
.btn { background: linear-gradient(135deg, #2196F3, #1565C0); color: white; border: none; padding: 15px 30px; border-radius: 12px; cursor: pointer; font-weight: 600; font-size: 16px; width: 100%; transition: 0.3s; text-decoration: none; display: inline-block; }
|
| 102 |
+
.btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(33, 150, 243, 0.4); }
|
| 103 |
+
.file-item { background: #252528; margin: 10px 0; padding: 15px; border-radius: 12px; display: flex; justify-content: space-between; align-items: center; text-align: left; }
|
| 104 |
+
.file-info { max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
| 105 |
+
.badge { font-size: 11px; background: var(--primary); padding: 3px 8px; border-radius: 20px; margin-left: 8px; }
|
| 106 |
+
</style>
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
def get_password_wall(target_name: str, error: bool = False):
|
| 110 |
+
return f"""
|
| 111 |
+
<html><head><meta name="viewport" content="width=device-width, initial-scale=1">{UI_STYLE}</head>
|
| 112 |
+
<body><div class="container"><div class="card">
|
| 113 |
+
<h2>๐ Restricted Access</h2>
|
| 114 |
+
<p style="color:#aaa;">'{target_name}' is password protected.</p>
|
| 115 |
+
<form method="get">
|
| 116 |
+
<input type="password" name="password" placeholder="Enter Access Code" autofocus required>
|
| 117 |
+
{f'<p style="color:#ff5252;font-size:14px;margin-top:-10px;">Incorrect password. Try again.</p>' if error else ''}
|
| 118 |
+
<button type="submit" class="btn">Unlock & Download</button>
|
| 119 |
+
</form>
|
| 120 |
+
</div></div></body></html>
|
| 121 |
+
"""
|
| 122 |
+
|
| 123 |
@app.get("/view/{user_id}/{batch_id}")
|
| 124 |
async def view_batch(user_id: str, batch_id: str, password: Optional[str] = Query(None)):
|
| 125 |
user_dir = os.path.join(UPLOAD_DIR, user_id)
|
| 126 |
if not os.path.exists(user_dir): raise HTTPException(404)
|
| 127 |
|
|
|
|
| 128 |
meta = get_metadata(batch_id)
|
| 129 |
if meta and meta.get("password") and meta.get("password") != password:
|
| 130 |
+
return HTMLResponse(get_password_wall(f"Batch: {batch_id}", error=password is not None))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
files_data = []
|
| 133 |
for f in os.listdir(user_dir):
|
|
|
|
| 144 |
if not files_data: raise HTTPException(404)
|
| 145 |
files_data.sort(key=lambda x: x["raw"])
|
| 146 |
|
| 147 |
+
items_html = "".join([f"""
|
| 148 |
+
<div class="file-item">
|
| 149 |
+
<div class="file-info">
|
| 150 |
+
<span style="font-weight:600;">{f['name']}</span><br>
|
| 151 |
+
<span style="color:#888;font-size:12px;">{f['size']} MB</span>
|
| 152 |
+
</div>
|
| 153 |
+
<div style="display:flex; gap:8px;">
|
| 154 |
+
{f'<a href="{f["stream"]}" class="btn" style="padding:8px 15px; font-size:12px; background:#4CAF50;">Watch</a>' if f['stream'] else ''}
|
| 155 |
+
<a href="{f['url']}" class="btn" style="padding:8px 15px; font-size:12px;">Get</a>
|
| 156 |
</div>
|
| 157 |
</div>""" for f in files_data])
|
| 158 |
|
| 159 |
return HTMLResponse(f"""
|
| 160 |
+
<html><head><meta name="viewport" content="width=device-width, initial-scale=1">{UI_STYLE}
|
| 161 |
+
<style>.container{{max-width:600px;}}</style>
|
| 162 |
+
</head><body><div class="container"><div class="card" style="text-align:left;">
|
| 163 |
+
<h2 style="text-align:center;">๐ฆ Batch Archive</h2>
|
| 164 |
+
<p style="text-align:center;color:#888;margin-top:-10px;">Total Files: {len(files_data)}</p>
|
| 165 |
+
<div style="margin-top:20px;">{items_html}</div>
|
| 166 |
+
<div style="text-align:center;margin-top:20px;"><a href="/" style="color:#555;text-decoration:none;font-size:14px;">Powered by NexusShare Pro</a></div>
|
| 167 |
+
</div></div></body></html>
|
| 168 |
""")
|
| 169 |
|
| 170 |
@app.get("/player/{filepath:path}")
|
|
|
|
| 173 |
path = os.path.join(UPLOAD_DIR, safe_path)
|
| 174 |
if not os.path.exists(path): raise HTTPException(404)
|
| 175 |
|
|
|
|
| 176 |
fname = os.path.basename(path)
|
| 177 |
meta = get_metadata(fname) or get_metadata(fname.split('_')[0])
|
| 178 |
if meta and meta.get("password") and meta.get("password") != password:
|
| 179 |
+
return HTMLResponse(get_password_wall(fname, error=password is not None))
|
| 180 |
|
| 181 |
return HTMLResponse(f"""
|
| 182 |
<html><head><title>Pro Player</title><meta name="viewport" content="width=device-width, initial-scale=1">
|
| 183 |
+
<style>
|
| 184 |
+
body{{margin:0;background:#000;display:flex;align-items:center;justify-content:center;height:100vh;font-family:sans-serif;}}
|
| 185 |
+
.player-container {{ width:100%; max-width:1000px; height: auto; aspect-ratio: 16/9; position: relative; }}
|
| 186 |
+
video {{ width:100%; height:100%; border-radius: 12px; box-shadow: 0 0 50px rgba(0,0,0,0.8); }}
|
| 187 |
+
.header {{ position:absolute; top:20px; left:20px; z-index:10; background:rgba(0,0,0,0.5); padding:10px 20px; border-radius:30px; backdrop-filter:blur(10px); color:white; font-size:14px; }}
|
| 188 |
+
</style>
|
| 189 |
</head><body>
|
| 190 |
+
<div class="player-container">
|
| 191 |
+
<div class="header">๐ฌ Playing: {"_".join(fname.split("_")[1:])}</div>
|
| 192 |
+
<video controls autoplay>
|
| 193 |
+
<source src="/download/{filepath}?password={password or ''}" type="video/mp4">
|
| 194 |
+
</video>
|
| 195 |
+
</div>
|
| 196 |
</body></html>
|
| 197 |
""")
|
| 198 |
|
| 199 |
@app.get("/download/{filepath:path}")
|
| 200 |
+
async def download_file(filepath: str, request: Request, password: Optional[str] = Query(None)):
|
| 201 |
safe_path = os.path.normpath(filepath).lstrip(os.sep)
|
| 202 |
path = os.path.join(UPLOAD_DIR, safe_path)
|
| 203 |
if not os.path.exists(path): raise HTTPException(404)
|
| 204 |
|
| 205 |
fname = os.path.basename(path)
|
|
|
|
| 206 |
meta = get_metadata(fname) or get_metadata(fname.split('_')[0])
|
| 207 |
|
| 208 |
+
# Intelligently decide whether to show Password Wall or serve File
|
| 209 |
if meta and meta.get("password") and meta.get("password") != password:
|
| 210 |
+
# If it's a browser request, show the wall. If it's a direct API/download tool, return 403.
|
| 211 |
+
accept = request.headers.get("accept", "")
|
| 212 |
+
if "text/html" in accept:
|
| 213 |
+
return HTMLResponse(get_password_wall(fname, error=password is not None))
|
| 214 |
raise HTTPException(403, "Password required.")
|
| 215 |
|
|
|
|
| 216 |
resp = FileResponse(path, filename="_".join(fname.split("_")[1:]))
|
| 217 |
|
|
|
|
| 218 |
if meta and meta.get("self_destruct"):
|
|
|
|
|
|
|
| 219 |
async def delete_after():
|
| 220 |
+
await asyncio.sleep(10) # Safety delay
|
| 221 |
try:
|
| 222 |
os.remove(path)
|
| 223 |
delete_metadata(fname)
|