From 29280d6490aa37111233ecd7f5130779da2cb790 Mon Sep 17 00:00:00 2001 From: subodh Date: Sun, 8 Mar 2026 21:11:43 +0530 Subject: [PATCH] update ui --- README.md | 4 +- backend/app/main.py | 22 +- backend/app/services/r2.py | 21 +- frontend/src/app/globals.css | 68 +---- frontend/src/app/page.tsx | 546 +++++++++++------------------------ 5 files changed, 207 insertions(+), 454 deletions(-) diff --git a/README.md b/README.md index 24917ae..9f54221 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A minimal self-hosted file sharing tool. Upload a file, get a public link. Files ## How it works 1. Enter the upload password to authenticate -2. Drop a file or click to browse (50 MB max) +2. Drop a file or click to browse (250 MB max) 3. Copy the public link and share it The frontend proxies `/api/*` to the backend at `localhost:8000`, so both run separately during development. @@ -23,6 +23,8 @@ The frontend proxies `/api/*` to the backend at `localhost:8000`, so both run se - [uv](https://docs.astral.sh/uv/) (Python package manager) - A [Cloudflare R2](https://developers.cloudflare.com/r2/) bucket with public access enabled +> **Upload limit:** 250 MB per file. Files are streamed directly through the backend to R2 without being loaded into memory. + --- ## Environment setup diff --git a/backend/app/main.py b/backend/app/main.py index b6ee8b7..728e9aa 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,13 +1,13 @@ import mimetypes import secrets -from fastapi import FastAPI, File, Form, HTTPException, UploadFile +from fastapi import FastAPI, File, Form, HTTPException, Request, UploadFile from fastapi.middleware.cors import CORSMiddleware from app.config.settings import settings from app.services.r2 import upload_file -MAX_FILE_SIZE = 50 * 1024 * 1024 # 50 MB +MAX_FILE_SIZE = 250 * 1024 * 1024 # 250 MB app = FastAPI(title="File Host API") @@ -44,23 +44,21 @@ async def auth(password: str = Form(...)): @app.post("/upload") async def upload( + request: Request, file: UploadFile = File(...), password: str = Form(...), ): - """Validate password, enforce size limit, and upload the file to R2.""" + """Validate password, enforce size limit, and stream the file to R2.""" if password != settings.UPLOAD_PASSWORD: raise HTTPException(status_code=401, detail="Invalid password.") - content = await file.read() - - if not content: - raise HTTPException(status_code=400, detail="Uploaded file is empty.") - - if len(content) > MAX_FILE_SIZE: - mb = len(content) / 1024 / 1024 + # Reject oversized requests early, before reading the body. + # Content-Length covers the whole multipart body; form overhead is negligible. + content_length = request.headers.get("content-length") + if content_length and int(content_length) > MAX_FILE_SIZE: raise HTTPException( status_code=413, - detail=f"File is too large ({mb:.1f} MB). Maximum allowed size is 50 MB.", + detail="File too large. Maximum allowed size is 250 MB.", ) content_type = ( @@ -70,7 +68,7 @@ async def upload( try: url = await upload_file( - file_bytes=content, + file_obj=file.file, object_name=object_name, content_type=content_type, ) diff --git a/backend/app/services/r2.py b/backend/app/services/r2.py index 71b4531..3cd21c1 100644 --- a/backend/app/services/r2.py +++ b/backend/app/services/r2.py @@ -1,5 +1,6 @@ import asyncio from functools import lru_cache +from typing import BinaryIO import boto3 from botocore.client import Config @@ -21,25 +22,25 @@ def _get_r2_client(): ) -def _put_object(object_name: str, file_bytes: bytes, content_type: str) -> str: - """Blocking S3 put""" +def _upload_fileobj(file_obj: BinaryIO, object_name: str, content_type: str) -> str: + """Stream file to R2. boto3 automatically uses multipart for large files.""" key = f"files/{object_name}" - _get_r2_client().put_object( - Bucket=settings.R2_BUCKET, - Key=key, - Body=file_bytes, - ContentType=content_type, + _get_r2_client().upload_fileobj( + file_obj, + settings.R2_BUCKET, + key, + ExtraArgs={"ContentType": content_type}, ) return f"{settings.PUBLIC_URL}/files/{object_name}" -async def upload_file(file_bytes: bytes, object_name: str, content_type: str) -> str: - """Upload a file to R2 storage""" +async def upload_file(file_obj: BinaryIO, object_name: str, content_type: str) -> str: + """Upload a file to R2 storage.""" try: url = await asyncio.to_thread( - _put_object, object_name, file_bytes, content_type + _upload_fileobj, file_obj, object_name, content_type ) except (BotoCoreError, ClientError) as exc: raise RuntimeError(f"R2 upload failed: {exc}") from exc diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 1f78a6c..ad16c0f 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -3,8 +3,8 @@ @tailwind utilities; :root { - --background: #06070f; - --foreground: #f8fafc; + --background: #313338; + --foreground: #f2f3f5; } * { @@ -19,8 +19,8 @@ body { } ::selection { - background: rgba(139, 92, 246, 0.35); - color: #f8fafc; + background: rgba(88, 101, 242, 0.3); + color: #f2f3f5; } ::-webkit-scrollbar { @@ -28,68 +28,14 @@ body { } ::-webkit-scrollbar-track { - background: #0d0f1a; + background: #2b2d31; } ::-webkit-scrollbar-thumb { - background: rgba(255, 255, 255, 0.08); + background: rgba(255, 255, 255, 0.1); border-radius: 3px; } ::-webkit-scrollbar-thumb:hover { - background: rgba(255, 255, 255, 0.14); -} - -@keyframes shimmer { - 0% { - background-position: -200% center; - } - 100% { - background-position: 200% center; - } -} - -@keyframes pulse-soft { - 0%, - 100% { - opacity: 1; - } - 50% { - opacity: 0.6; - } -} - -@keyframes float-orb { - 0%, - 100% { - transform: translateY(0px) scale(1); - } - 50% { - transform: translateY(-20px) scale(1.04); - } -} - -.progress-bar { - background: linear-gradient( - 90deg, - #7c3aed, - #3b82f6, - #06b6d4, - #3b82f6, - #7c3aed - ); - background-size: 300% auto; - animation: shimmer 2.5s linear infinite; -} - -.orb-1 { - animation: float-orb 12s ease-in-out infinite; -} - -.orb-2 { - animation: float-orb 16s ease-in-out infinite reverse; -} - -.orb-3 { - animation: float-orb 10s ease-in-out infinite 4s; + background: rgba(255, 255, 255, 0.18); } diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 7f02387..3500fc6 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -3,13 +3,11 @@ import { AlertCircle, CheckCircle2, - CloudUpload, Copy, ExternalLink, Lock, - LockOpen, - RefreshCw, - UploadCloud, + RotateCcw, + Upload, } from "lucide-react"; import { ChangeEvent, DragEvent, useCallback, useRef, useState } from "react"; @@ -134,7 +132,7 @@ export default function Home() { [uploadFile], ); - // ── Copy URL ────────────────────────────────────────────────────────────── + // ── Copy ────────────────────────────────────────────────────────────────── const handleCopy = async () => { await navigator.clipboard.writeText(resultUrl); @@ -151,119 +149,38 @@ export default function Home() { // ── Render ──────────────────────────────────────────────────────────────── return ( -
- {/* ── Ambient background orbs ──────────────────────────────────── */} -
-
-
-
-
+
+
+ {/* ── Header ─────────────────────────────────────────────────────── */} +
+
+ +
+
+

+ File Host +

+

+ 250 MB max · expires in 24 h +

+
+
- {/* ── Subtle dot grid ──────────────────────────────────────────── */} -
- - {/* ── Card ─────────────────────────────────────────────────────── */} -
-
- {/* Gradient top-bar accent */} -
- -
- {/* ── Header ─────────────────────────────────────────────── */} -
-
- -
- -
-

- File Host -

-

- 50 MB max  ·  expires in 24 h -

-
-
- - {/* Divider */} -
- - {/* ── Auth ───────────────────────────────────────────────── */} + {/* ── Card ───────────────────────────────────────────────────────── */} +
+ {/* Auth row */} +
{isLocked ? ( -
+
+ e.key === "Enter" && handleUnlock()} - placeholder="Enter password…" - className="flex-1 rounded-xl px-4 py-2.5 text-sm text-white placeholder-slate-600 outline-none transition-all duration-200" - style={{ - background: "rgba(255,255,255,0.04)", - border: passwordError - ? "1px solid rgba(239,68,68,0.6)" - : "1px solid rgba(255,255,255,0.08)", - boxShadow: passwordError - ? "0 0 0 3px rgba(239,68,68,0.1)" - : undefined, - }} - onFocus={(e) => { - if (!passwordError) - (e.target as HTMLInputElement).style.border = - "1px solid rgba(124,58,237,0.5)"; - (e.target as HTMLInputElement).style.boxShadow = - "0 0 0 3px rgba(124,58,237,0.12)"; - }} - onBlur={(e) => { - if (!passwordError) { - (e.target as HTMLInputElement).style.border = - "1px solid rgba(255,255,255,0.08)"; - (e.target as HTMLInputElement).style.boxShadow = "none"; - } - }} + placeholder="Enter password" + className={[ + "w-full h-11 px-3.5 rounded-xl text-[15px] text-[#f2f3f5]", + "bg-[#1e1f22] placeholder:text-[#4e5058] outline-none", + "border transition-all duration-150", + passwordError + ? "border-[#ed4245] ring-2 ring-[#ed4245]/15" + : "border-transparent focus:border-[#5865f2]/50 focus:ring-2 focus:ring-[#5865f2]/15", + ].join(" ")} /> + {passwordError && ( +

+ Incorrect password. +

+ )}
) : ( -
- - - Authenticated +
+
+ + Unlocked
)} +
- {/* ── Upload zone ────────────────────────────────────────── */} -
isInteractable && fileInputRef.current?.click()} - className="relative rounded-xl border-2 border-dashed flex flex-col items-center justify-center gap-4 p-10 text-center transition-all duration-200" - style={{ - minHeight: "190px", - borderColor: isUploading - ? "rgba(124,58,237,0.45)" - : isLocked - ? "rgba(255,255,255,0.05)" - : isDragging - ? "rgba(124,58,237,0.65)" - : "rgba(255,255,255,0.09)", - background: isDragging - ? "rgba(124,58,237,0.07)" - : isUploading - ? "rgba(124,58,237,0.04)" - : "rgba(255,255,255,0.015)", - cursor: isUploading - ? "default" - : isLocked - ? "not-allowed" - : isDragging - ? "copy" - : "pointer", - opacity: isLocked ? 0.45 : 1, - }} - > - - - {isUploading ? ( - /* Uploading state */ - <> -
- + {isUploading ? ( + /* ── Uploading ─────────────────────────────────────────────── */ +
+
+
+
-
-

- {pendingFileName} -

-
-
-
-

- {progress}% -

-
- - ) : isDragging ? ( - /* Drag-over state */ - <> -
- -
-

- Drop to upload +

+ {pendingFileName}

- - ) : ( - /* Idle state */ - <> + + {progress}% + +
+
- -
-
-

- {isLocked - ? "Enter password to unlock" - : "Drop a file here or click to browse"} -

- {!isLocked && ( -

- Any file type · up to 50 MB -

- )} -
- - )} -
- - {/* ── Error ──────────────────────────────────────────────── */} - {errorMessage && ( -
- -

- {errorMessage} -

+ className="h-full rounded-full bg-[#5865f2] transition-all duration-300 ease-out" + style={{ width: `${progress}%` }} + /> +
- )} - - {/* ── Success ────────────────────────────────────────────── */} - {status === "done" && resultUrl && ( -
-
-
- -
- + ) : status === "done" && resultUrl ? ( + /* ── Done ─────────────────────────────────────────────────── */ +
+
+ + Upload complete
@@ -510,56 +264,32 @@ export default function Home() { readOnly value={resultUrl} onClick={(e) => (e.target as HTMLInputElement).select()} - className="w-full rounded-xl px-3.5 py-2.5 text-sm text-slate-300 outline-none cursor-text font-mono transition-all duration-200" - style={{ - background: "rgba(255,255,255,0.04)", - border: "1px solid rgba(255,255,255,0.08)", - }} - onFocus={(e) => { - (e.target as HTMLInputElement).style.border = - "1px solid rgba(255,255,255,0.14)"; - }} - onBlur={(e) => { - (e.target as HTMLInputElement).style.border = - "1px solid rgba(255,255,255,0.08)"; - }} + className="w-full h-10 px-3 rounded-xl bg-[#1e1f22] border border-transparent focus:border-white/[0.12] text-[12px] text-[#f2f3f5] font-mono outline-none cursor-text transition-colors" />
- + Open
@@ -570,18 +300,94 @@ export default function Home() { setErrorMessage(""); setStatus("unlocked"); }} - className="flex items-center justify-center gap-1.5 text-xs text-slate-600 hover:text-slate-400 transition-colors duration-150" + className="flex items-center justify-center gap-1.5 text-[13px] text-[#80848e] transition-colors active:text-[#f2f3f5] select-none" > - - Upload another file + + Upload another
+ ) : ( + /* ── Drop zone ─────────────────────────────────────────────── */ +
isInteractable && fileInputRef.current?.click()} + className={[ + "rounded-xl border-2 border-dashed", + "flex flex-col items-center justify-center gap-2.5", + "py-10 px-4 text-center", + "transition-all duration-150 select-none", + isLocked + ? "border-white/[0.06] cursor-not-allowed opacity-40" + : isDragging + ? "border-[#5865f2]/40 bg-[#5865f2]/[0.04] cursor-copy" + : "border-white/[0.08] cursor-pointer hover:border-white/[0.14] hover:bg-white/[0.02] active:bg-white/[0.03]", + ].join(" ")} + > + +
+ +
+
+

+ {isLocked + ? "Enter password to unlock" + : isDragging + ? "Drop to upload" + : "Drop file or tap to browse"} +

+ {!isLocked && ( +

+ Any file type · up to 250 MB +

+ )} +
+
+ )} + + {/* ── Error ────────────────────────────────────────────────── */} + {errorMessage && ( +
+ +

+ {errorMessage} +

+
)}
- {/* Footer */} -

+ {/* ── Footer ─────────────────────────────────────────────────────── */} +

Files are automatically deleted after 24 hours