diff --git a/backend/app/main.py b/backend/app/main.py index 728e9aa..3f34fc8 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -7,7 +7,8 @@ from fastapi.middleware.cors import CORSMiddleware from app.config.settings import settings from app.services.r2 import upload_file -MAX_FILE_SIZE = 250 * 1024 * 1024 # 250 MB +UNAUTH_LIMIT = 50 * 1024 * 1024 # 50 MB — unauthenticated +AUTH_LIMIT = 250 * 1024 * 1024 # 250 MB — authenticated app = FastAPI(title="File Host API") @@ -46,19 +47,27 @@ async def auth(password: str = Form(...)): async def upload( request: Request, file: UploadFile = File(...), - password: str = Form(...), + password: str = Form(default=""), ): - """Validate password, enforce size limit, and stream the file to R2.""" - if password != settings.UPLOAD_PASSWORD: + """ + Upload a file to R2. + + - No password: allowed up to 50 MB. + - Correct password: allowed up to 250 MB. + - Wrong password (non-empty): rejected with 401. + """ + if password and password != settings.UPLOAD_PASSWORD: raise HTTPException(status_code=401, detail="Invalid password.") - # Reject oversized requests early, before reading the body. - # Content-Length covers the whole multipart body; form overhead is negligible. + is_authenticated = password == settings.UPLOAD_PASSWORD + max_size = AUTH_LIMIT if is_authenticated else UNAUTH_LIMIT + limit_str = "250 MB" if is_authenticated else "50 MB" + content_length = request.headers.get("content-length") - if content_length and int(content_length) > MAX_FILE_SIZE: + if content_length and int(content_length) > max_size: raise HTTPException( status_code=413, - detail="File too large. Maximum allowed size is 250 MB.", + detail=f"File too large. Maximum allowed size is {limit_str}.", ) content_type = ( diff --git a/frontend/next-env.d.ts b/frontend/next-env.d.ts index 1b3be08..9edff1c 100644 --- a/frontend/next-env.d.ts +++ b/frontend/next-env.d.ts @@ -1,5 +1,6 @@ /// /// +import "./.next/types/routes.d.ts"; // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index ad16c0f..a992fb1 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -3,8 +3,8 @@ @tailwind utilities; :root { - --background: #313338; - --foreground: #f2f3f5; + --background: #282828; + --foreground: #ebdbb2; } * { @@ -19,8 +19,8 @@ body { } ::selection { - background: rgba(88, 101, 242, 0.3); - color: #f2f3f5; + background: rgba(215, 153, 33, 0.3); + color: #ebdbb2; } ::-webkit-scrollbar { @@ -28,14 +28,14 @@ body { } ::-webkit-scrollbar-track { - background: #2b2d31; + background: #1d2021; } ::-webkit-scrollbar-thumb { - background: rgba(255, 255, 255, 0.1); + background: #504945; border-radius: 3px; } ::-webkit-scrollbar-thumb:hover { - background: rgba(255, 255, 255, 0.18); + background: #665c54; } diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 3500fc6..8a65ac4 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -11,10 +11,10 @@ import { } from "lucide-react"; import { ChangeEvent, DragEvent, useCallback, useRef, useState } from "react"; -type Status = "locked" | "unlocked" | "uploading" | "done"; +type Status = "idle" | "authenticated" | "uploading" | "done"; export default function Home() { - const [status, setStatus] = useState("locked"); + const [status, setStatus] = useState("idle"); const [password, setPassword] = useState(""); const [passwordError, setPasswordError] = useState(false); const [isDragging, setIsDragging] = useState(false); @@ -25,6 +25,7 @@ export default function Home() { const [pendingFileName, setPendingFileName] = useState(""); const fileInputRef = useRef(null); + const preUploadStatus = useRef<"idle" | "authenticated">("idle"); // ── Auth ────────────────────────────────────────────────────────────────── @@ -34,7 +35,7 @@ export default function Home() { const res = await fetch("/api/auth", { method: "POST", body }); if (res.ok) { setPasswordError(false); - setStatus("unlocked"); + setStatus("authenticated"); } else { setPasswordError(true); } @@ -44,6 +45,8 @@ export default function Home() { const uploadFile = useCallback( (file: File) => { + preUploadStatus.current = + status === "authenticated" ? "authenticated" : "idle"; setStatus("uploading"); setProgress(0); setResultUrl(""); @@ -52,7 +55,9 @@ export default function Home() { const formData = new FormData(); formData.append("file", file); - formData.append("password", password); + if (status === "authenticated") { + formData.append("password", password); + } const xhr = new XMLHttpRequest(); @@ -81,19 +86,19 @@ export default function Home() { // ignore } setErrorMessage(detail); - setStatus("unlocked"); + setStatus(preUploadStatus.current); } }; xhr.onerror = () => { setErrorMessage("Network error — could not reach the server."); - setStatus("unlocked"); + setStatus(preUploadStatus.current); }; xhr.open("POST", "/api/upload"); xhr.send(formData); }, - [password], + [status, password], ); // ── Drag and drop ───────────────────────────────────────────────────────── @@ -101,7 +106,7 @@ export default function Home() { const handleDragOver = useCallback( (e: DragEvent) => { e.preventDefault(); - if (status === "locked" || status === "uploading") return; + if (status === "uploading") return; setIsDragging(true); }, [status], @@ -116,7 +121,7 @@ export default function Home() { (e: DragEvent) => { e.preventDefault(); setIsDragging(false); - if (status === "locked" || status === "uploading") return; + if (status === "uploading") return; const file = e.dataTransfer.files[0]; if (file) uploadFile(file); }, @@ -142,16 +147,18 @@ export default function Home() { // ── Helpers ─────────────────────────────────────────────────────────────── - const isLocked = status === "locked"; + const isAuthenticated = status === "authenticated"; const isUploading = status === "uploading"; - const isInteractable = status === "unlocked" || status === "done"; + const isInteractable = status !== "uploading"; + const limitLabel = isAuthenticated ? "250 MB" : "50 MB"; // ── Render ──────────────────────────────────────────────────────────────── return (
{/* ── Header ─────────────────────────────────────────────────────── */}
-
- +
+
-

- File Host +

+ filehost

-

- 250 MB max · expires in 24 h +

+ {limitLabel} max · expires in 24 h

{/* ── Card ───────────────────────────────────────────────────────── */} -
+
{/* Auth row */} -
- {isLocked ? ( +
+ {isAuthenticated ? ( +
+
+ + Authenticated · 250 MB limit + +
+ ) : (
-
- ) : ( -
-
- - Unlocked - -
)}
@@ -227,23 +283,36 @@ export default function Home() { /* ── Uploading ─────────────────────────────────────────────── */
-
+
-

+

{pendingFileName}

- + {progress}%
-
+
@@ -252,10 +321,14 @@ export default function Home() {
- + Upload complete
@@ -264,20 +337,31 @@ export default function Home() { readOnly value={resultUrl} onClick={(e) => (e.target as HTMLInputElement).select()} - 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" + className="w-full h-10 px-3 rounded-xl text-[12px] font-mono outline-none cursor-text transition-colors" + style={{ + background: "#1d2021", + border: "1px solid #504945", + color: "#d5c4a1", + }} />
)} {/* ── Error ────────────────────────────────────────────────── */} {errorMessage && ( -
+
-

+

{errorMessage}

@@ -387,7 +470,10 @@ export default function Home() {
{/* ── Footer ─────────────────────────────────────────────────────── */} -

+

Files are automatically deleted after 24 hours