update colorsceheme, allow anonymous 50mb uploads

This commit is contained in:
subodh committed 2026-03-13 09:56:05 +05:30
1 parent 95391d404b
commit f7c0310c91
4 files changed
+210 -114

No files matched your search

+17 -8
View File
@@ -7,7 +7,8 @@ from fastapi.middleware.cors import CORSMiddleware
from app.config.settings import settings from app.config.settings import settings
from app.services.r2 import upload_file 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") app = FastAPI(title="File Host API")
@@ -46,19 +47,27 @@ async def auth(password: str = Form(...)):
async def upload( async def upload(
request: Request, request: Request,
file: UploadFile = File(...), 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.") raise HTTPException(status_code=401, detail="Invalid password.")
# Reject oversized requests early, before reading the body. is_authenticated = password == settings.UPLOAD_PASSWORD
# Content-Length covers the whole multipart body; form overhead is negligible. 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") 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( raise HTTPException(
status_code=413, 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 = ( content_type = (
+1
View File
@@ -1,5 +1,6 @@
/// <reference types="next" /> /// <reference types="next" />
/// <reference types="next/image-types/global" /> /// <reference types="next/image-types/global" />
import "./.next/types/routes.d.ts";
// NOTE: This file should not be edited // NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information. // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
+7 -7
View File
@@ -3,8 +3,8 @@
@tailwind utilities; @tailwind utilities;
:root { :root {
--background: #313338; --background: #282828;
--foreground: #f2f3f5; --foreground: #ebdbb2;
} }
* { * {
@@ -19,8 +19,8 @@ body {
} }
::selection { ::selection {
background: rgba(88, 101, 242, 0.3); background: rgba(215, 153, 33, 0.3);
color: #f2f3f5; color: #ebdbb2;
} }
::-webkit-scrollbar { ::-webkit-scrollbar {
@@ -28,14 +28,14 @@ body {
} }
::-webkit-scrollbar-track { ::-webkit-scrollbar-track {
background: #2b2d31; background: #1d2021;
} }
::-webkit-scrollbar-thumb { ::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.1); background: #504945;
border-radius: 3px; border-radius: 3px;
} }
::-webkit-scrollbar-thumb:hover { ::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.18); background: #665c54;
} }
+185 -99
View File
@@ -11,10 +11,10 @@ import {
} from "lucide-react"; } from "lucide-react";
import { ChangeEvent, DragEvent, useCallback, useRef, useState } from "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() { export default function Home() {
const [status, setStatus] = useState<Status>("locked"); const [status, setStatus] = useState<Status>("idle");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [passwordError, setPasswordError] = useState(false); const [passwordError, setPasswordError] = useState(false);
const [isDragging, setIsDragging] = useState(false); const [isDragging, setIsDragging] = useState(false);
@@ -25,6 +25,7 @@ export default function Home() {
const [pendingFileName, setPendingFileName] = useState(""); const [pendingFileName, setPendingFileName] = useState("");
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
const preUploadStatus = useRef<"idle" | "authenticated">("idle");
// ── Auth ────────────────────────────────────────────────────────────────── // ── Auth ──────────────────────────────────────────────────────────────────
@@ -34,7 +35,7 @@ export default function Home() {
const res = await fetch("/api/auth", { method: "POST", body }); const res = await fetch("/api/auth", { method: "POST", body });
if (res.ok) { if (res.ok) {
setPasswordError(false); setPasswordError(false);
setStatus("unlocked"); setStatus("authenticated");
} else { } else {
setPasswordError(true); setPasswordError(true);
} }
@@ -44,6 +45,8 @@ export default function Home() {
const uploadFile = useCallback( const uploadFile = useCallback(
(file: File) => { (file: File) => {
preUploadStatus.current =
status === "authenticated" ? "authenticated" : "idle";
setStatus("uploading"); setStatus("uploading");
setProgress(0); setProgress(0);
setResultUrl(""); setResultUrl("");
@@ -52,7 +55,9 @@ export default function Home() {
const formData = new FormData(); const formData = new FormData();
formData.append("file", file); formData.append("file", file);
formData.append("password", password); if (status === "authenticated") {
formData.append("password", password);
}
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
@@ -81,19 +86,19 @@ export default function Home() {
// ignore // ignore
} }
setErrorMessage(detail); setErrorMessage(detail);
setStatus("unlocked"); setStatus(preUploadStatus.current);
} }
}; };
xhr.onerror = () => { xhr.onerror = () => {
setErrorMessage("Network error — could not reach the server."); setErrorMessage("Network error — could not reach the server.");
setStatus("unlocked"); setStatus(preUploadStatus.current);
}; };
xhr.open("POST", "/api/upload"); xhr.open("POST", "/api/upload");
xhr.send(formData); xhr.send(formData);
}, },
[password], [status, password],
); );
// ── Drag and drop ───────────────────────────────────────────────────────── // ── Drag and drop ─────────────────────────────────────────────────────────
@@ -101,7 +106,7 @@ export default function Home() {
const handleDragOver = useCallback( const handleDragOver = useCallback(
(e: DragEvent<HTMLDivElement>) => { (e: DragEvent<HTMLDivElement>) => {
e.preventDefault(); e.preventDefault();
if (status === "locked" || status === "uploading") return; if (status === "uploading") return;
setIsDragging(true); setIsDragging(true);
}, },
[status], [status],
@@ -116,7 +121,7 @@ export default function Home() {
(e: DragEvent<HTMLDivElement>) => { (e: DragEvent<HTMLDivElement>) => {
e.preventDefault(); e.preventDefault();
setIsDragging(false); setIsDragging(false);
if (status === "locked" || status === "uploading") return; if (status === "uploading") return;
const file = e.dataTransfer.files[0]; const file = e.dataTransfer.files[0];
if (file) uploadFile(file); if (file) uploadFile(file);
}, },
@@ -142,16 +147,18 @@ export default function Home() {
// ── Helpers ─────────────────────────────────────────────────────────────── // ── Helpers ───────────────────────────────────────────────────────────────
const isLocked = status === "locked"; const isAuthenticated = status === "authenticated";
const isUploading = status === "uploading"; const isUploading = status === "uploading";
const isInteractable = status === "unlocked" || status === "done"; const isInteractable = status !== "uploading";
const limitLabel = isAuthenticated ? "250 MB" : "50 MB";
// ── Render ──────────────────────────────────────────────────────────────── // ── Render ────────────────────────────────────────────────────────────────
return ( return (
<main <main
className="min-h-screen bg-[#313338] flex flex-col items-center justify-center px-4 py-12" className="min-h-screen flex flex-col items-center justify-center px-4 py-12"
style={{ style={{
background: "#282828",
paddingTop: "max(3rem, env(safe-area-inset-top))", paddingTop: "max(3rem, env(safe-area-inset-top))",
paddingBottom: "max(3rem, env(safe-area-inset-bottom))", paddingBottom: "max(3rem, env(safe-area-inset-bottom))",
}} }}
@@ -159,27 +166,65 @@ export default function Home() {
<div className="w-full max-w-sm"> <div className="w-full max-w-sm">
{/* ── Header ─────────────────────────────────────────────────────── */} {/* ── Header ─────────────────────────────────────────────────────── */}
<div className="flex flex-col items-center text-center mb-8 gap-3"> <div className="flex flex-col items-center text-center mb-8 gap-3">
<div className="w-12 h-12 rounded-[14px] bg-[#2b2d31] border border-white/[0.06] flex items-center justify-center"> <div
<Upload className="w-5 h-5 text-[#f2f3f5]" strokeWidth={1.75} /> className="w-12 h-12 rounded-[14px] flex items-center justify-center"
style={{
background: "#3c3836",
border: "1px solid #504945",
}}
>
<Upload
className="w-5 h-5"
style={{ color: "#d79921" }}
strokeWidth={1.75}
/>
</div> </div>
<div> <div>
<h1 className="text-[22px] font-semibold text-[#f2f3f5] tracking-tight leading-snug"> <h1
File Host className="text-[22px] font-semibold tracking-tight leading-snug"
style={{ color: "#ebdbb2" }}
>
filehost
</h1> </h1>
<p className="text-[13px] text-[#b5bac1] mt-0.5"> <p className="text-[13px] mt-0.5" style={{ color: "#a89984" }}>
250 MB max · expires in 24 h {limitLabel} max · expires in 24 h
</p> </p>
</div> </div>
</div> </div>
{/* ── Card ───────────────────────────────────────────────────────── */} {/* ── Card ───────────────────────────────────────────────────────── */}
<div className="bg-[#2b2d31] rounded-2xl border border-white/[0.06] overflow-hidden"> <div
className="rounded-2xl overflow-hidden"
style={{ background: "#32302f", border: "1px solid #504945" }}
>
{/* Auth row */} {/* Auth row */}
<div className="px-5 pt-5 pb-5 border-b border-white/[0.06]"> <div
{isLocked ? ( className="px-5 pt-5 pb-5"
style={{ borderBottom: "1px solid #504945" }}
>
{isAuthenticated ? (
<div className="flex items-center gap-2.5 py-0.5">
<div
className="w-2 h-2 rounded-full shrink-0"
style={{ background: "#b8bb26" }}
/>
<span
className="text-[14px] font-medium"
style={{ color: "#b8bb26" }}
>
Authenticated · 250 MB limit
</span>
</div>
) : (
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-3">
<label className="text-[13px] font-medium text-[#f2f3f5]"> <label
Password className="text-[13px] font-medium"
style={{ color: "#a89984" }}
>
Password{" "}
<span style={{ color: "#665c54" }} className="font-normal">
— optional, unlocks 250 MB
</span>
</label> </label>
<input <input
type="password" type="password"
@@ -191,33 +236,44 @@ export default function Home() {
onKeyDown={(e) => e.key === "Enter" && handleUnlock()} onKeyDown={(e) => e.key === "Enter" && handleUnlock()}
placeholder="Enter password" placeholder="Enter password"
className={[ className={[
"w-full h-11 px-3.5 rounded-xl text-[15px] text-[#f2f3f5]", "w-full h-11 px-3.5 rounded-xl text-[15px] outline-none",
"bg-[#1e1f22] placeholder:text-[#4e5058] outline-none",
"border transition-all duration-150", "border transition-all duration-150",
passwordError passwordError ? "ring-2" : "",
? "border-[#ed4245] ring-2 ring-[#ed4245]/15"
: "border-transparent focus:border-[#5865f2]/50 focus:ring-2 focus:ring-[#5865f2]/15",
].join(" ")} ].join(" ")}
style={{
background: "#1d2021",
color: "#ebdbb2",
caretColor: "#d79921",
borderColor: passwordError ? "#fb4934" : "#504945",
boxShadow: passwordError
? "0 0 0 2px rgba(251,73,52,0.2)"
: undefined,
}}
onFocus={(e) => {
if (!passwordError)
(e.target as HTMLInputElement).style.borderColor =
"#d79921";
}}
onBlur={(e) => {
if (!passwordError)
(e.target as HTMLInputElement).style.borderColor =
"#504945";
}}
/> />
{passwordError && ( {passwordError && (
<p className="text-[12px] text-[#ed4245] -mt-1"> <p className="text-[12px] -mt-1" style={{ color: "#fb4934" }}>
Incorrect password. Incorrect password.
</p> </p>
)} )}
<button <button
onClick={handleUnlock} onClick={handleUnlock}
className="w-full h-11 rounded-xl bg-[#5865f2] text-white text-[15px] font-medium tracking-tight transition-opacity active:opacity-75 select-none" className="w-full h-11 rounded-xl text-[15px] font-semibold tracking-tight transition-opacity active:opacity-75 select-none flex items-center justify-center gap-2"
style={{ background: "#d79921", color: "#1d2021" }}
> >
Unlock <Lock className="w-3.5 h-3.5" strokeWidth={2.5} />
Unlock 250 MB
</button> </button>
</div> </div>
) : (
<div className="flex items-center gap-2.5 py-0.5">
<div className="w-2 h-2 rounded-full bg-[#23a55a] shrink-0" />
<span className="text-[14px] font-medium text-[#f2f3f5]">
Unlocked
</span>
</div>
)} )}
</div> </div>
@@ -227,23 +283,36 @@ export default function Home() {
/* ── Uploading ─────────────────────────────────────────────── */ /* ── Uploading ─────────────────────────────────────────────── */
<div className="flex flex-col gap-3 py-1"> <div className="flex flex-col gap-3 py-1">
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<div className="w-9 h-9 rounded-[10px] bg-[#1e1f22] flex items-center justify-center shrink-0"> <div
className="w-9 h-9 rounded-[10px] flex items-center justify-center shrink-0"
style={{ background: "#3c3836" }}
>
<Upload <Upload
className="w-4 h-4 text-[#b5bac1]" className="w-4 h-4"
style={{ color: "#a89984" }}
strokeWidth={1.75} strokeWidth={1.75}
/> />
</div> </div>
<p className="text-[14px] text-[#f2f3f5] font-medium truncate flex-1 min-w-0"> <p
className="text-[14px] font-medium truncate flex-1 min-w-0"
style={{ color: "#ebdbb2" }}
>
{pendingFileName} {pendingFileName}
</p> </p>
<span className="text-[13px] text-[#b5bac1] tabular-nums shrink-0 ml-2"> <span
className="text-[13px] tabular-nums shrink-0 ml-2"
style={{ color: "#a89984" }}
>
{progress}% {progress}%
</span> </span>
</div> </div>
<div className="h-[3px] w-full rounded-full bg-[#1e1f22] overflow-hidden"> <div
className="h-[3px] w-full rounded-full overflow-hidden"
style={{ background: "#3c3836" }}
>
<div <div
className="h-full rounded-full bg-[#5865f2] transition-all duration-300 ease-out" className="h-full rounded-full transition-all duration-300 ease-out"
style={{ width: `${progress}%` }} style={{ width: `${progress}%`, background: "#d79921" }}
/> />
</div> </div>
</div> </div>
@@ -252,10 +321,14 @@ export default function Home() {
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-3">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<CheckCircle2 <CheckCircle2
className="w-4 h-4 text-[#23a55a] shrink-0" className="w-4 h-4 shrink-0"
style={{ color: "#b8bb26" }}
strokeWidth={2} strokeWidth={2}
/> />
<span className="text-[14px] font-medium text-[#f2f3f5]"> <span
className="text-[14px] font-medium"
style={{ color: "#ebdbb2" }}
>
Upload complete Upload complete
</span> </span>
</div> </div>
@@ -264,20 +337,31 @@ export default function Home() {
readOnly readOnly
value={resultUrl} value={resultUrl}
onClick={(e) => (e.target as HTMLInputElement).select()} 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",
}}
/> />
<div className="flex gap-2"> <div className="flex gap-2">
<button <button
onClick={handleCopy} onClick={handleCopy}
className={[ className="flex-1 h-11 rounded-xl text-[14px] font-medium flex items-center justify-center gap-1.5 transition-all active:opacity-70 select-none"
"flex-1 h-11 rounded-xl text-[14px] font-medium", style={
"flex items-center justify-center gap-1.5",
"transition-all active:opacity-70 select-none",
copied copied
? "bg-[#23a55a]/10 text-[#23a55a]" ? {
: "bg-[#1e1f22] text-[#f2f3f5]", background: "rgba(184,187,38,0.12)",
].join(" ")} color: "#b8bb26",
border: "1px solid rgba(184,187,38,0.25)",
}
: {
background: "#3c3836",
color: "#ebdbb2",
border: "1px solid #504945",
}
}
> >
<Copy className="w-3.5 h-3.5" strokeWidth={2} /> <Copy className="w-3.5 h-3.5" strokeWidth={2} />
{copied ? "Copied" : "Copy"} {copied ? "Copied" : "Copy"}
@@ -287,7 +371,8 @@ export default function Home() {
href={resultUrl} href={resultUrl}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className="flex-1 h-11 rounded-xl bg-[#5865f2] text-white text-[14px] font-medium flex items-center justify-center gap-1.5 transition-opacity active:opacity-80 select-none" className="flex-1 h-11 rounded-xl text-[14px] font-semibold flex items-center justify-center gap-1.5 transition-opacity active:opacity-80 select-none"
style={{ background: "#d79921", color: "#1d2021" }}
> >
<ExternalLink className="w-3.5 h-3.5" strokeWidth={2} /> <ExternalLink className="w-3.5 h-3.5" strokeWidth={2} />
Open Open
@@ -298,9 +383,10 @@ export default function Home() {
onClick={() => { onClick={() => {
setResultUrl(""); setResultUrl("");
setErrorMessage(""); setErrorMessage("");
setStatus("unlocked"); setStatus(isAuthenticated ? "authenticated" : "idle");
}} }}
className="flex items-center justify-center gap-1.5 text-[13px] text-[#80848e] transition-colors active:text-[#f2f3f5] select-none" className="flex items-center justify-center gap-1.5 text-[13px] transition-colors active:opacity-80 select-none"
style={{ color: "#a89984" }}
> >
<RotateCcw className="w-3 h-3" strokeWidth={2} /> <RotateCcw className="w-3 h-3" strokeWidth={2} />
Upload another Upload another
@@ -313,17 +399,14 @@ export default function Home() {
onDragLeave={handleDragLeave} onDragLeave={handleDragLeave}
onDrop={handleDrop} onDrop={handleDrop}
onClick={() => isInteractable && fileInputRef.current?.click()} onClick={() => isInteractable && fileInputRef.current?.click()}
className={[ 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"
"rounded-xl border-2 border-dashed", style={{
"flex flex-col items-center justify-center gap-2.5", borderColor: isDragging ? "#83a598" : "#504945",
"py-10 px-4 text-center", background: isDragging
"transition-all duration-150 select-none", ? "rgba(131,165,152,0.06)"
isLocked : "transparent",
? "border-white/[0.06] cursor-not-allowed opacity-40" cursor: isUploading ? "default" : "pointer",
: 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(" ")}
> >
<input <input
ref={fileInputRef} ref={fileInputRef}
@@ -332,53 +415,53 @@ export default function Home() {
onChange={handleFileChange} onChange={handleFileChange}
/> />
<div <div
className={[ className="w-10 h-10 rounded-[12px] flex items-center justify-center transition-colors"
"w-10 h-10 rounded-[12px] flex items-center justify-center transition-colors", style={{
isDragging ? "bg-[#5865f2]/10" : "bg-[#1e1f22]", background: isDragging
].join(" ")} ? "rgba(131,165,152,0.12)"
: "#3c3836",
}}
> >
<Upload <Upload
className={[ className="w-4.5 h-4.5 transition-colors"
"w-4.5 h-4.5 transition-colors", style={{ color: isDragging ? "#83a598" : "#7c6f64" }}
isDragging ? "text-[#5865f2]" : "text-[#80848e]",
].join(" ")}
strokeWidth={1.75} strokeWidth={1.75}
/> />
</div> </div>
<div> <div>
<p <p
className={[ className="text-[14px] font-medium transition-colors"
"text-[14px] font-medium transition-colors", style={{ color: isDragging ? "#83a598" : "#ebdbb2" }}
isDragging
? "text-[#5865f2]"
: isLocked
? "text-[#80848e]"
: "text-[#f2f3f5]",
].join(" ")}
> >
{isLocked {isDragging
? "Enter password to unlock" ? "Drop to upload"
: isDragging : "Drop file or tap to browse"}
? "Drop to upload" </p>
: "Drop file or tap to browse"} <p className="text-[12px] mt-1" style={{ color: "#7c6f64" }}>
Any file type · up to {limitLabel}
</p> </p>
{!isLocked && (
<p className="text-[12px] text-[#80848e] mt-1">
Any file type · up to 250 MB
</p>
)}
</div> </div>
</div> </div>
)} )}
{/* ── Error ────────────────────────────────────────────────── */} {/* ── Error ────────────────────────────────────────────────── */}
{errorMessage && ( {errorMessage && (
<div className="flex items-start gap-2.5 px-3.5 py-3 rounded-xl bg-[#ed4245]/[0.08] border border-[#ed4245]/[0.15]"> <div
className="flex items-start gap-2.5 px-3.5 py-3 rounded-xl"
style={{
background: "rgba(251,73,52,0.08)",
border: "1px solid rgba(251,73,52,0.2)",
}}
>
<AlertCircle <AlertCircle
className="w-4 h-4 text-[#ed4245] shrink-0 mt-px" className="w-4 h-4 shrink-0 mt-px"
style={{ color: "#fb4934" }}
strokeWidth={2} strokeWidth={2}
/> />
<p className="text-[13px] text-[#ed4245] break-all leading-relaxed"> <p
className="text-[13px] break-all leading-relaxed"
style={{ color: "#fb4934" }}
>
{errorMessage} {errorMessage}
</p> </p>
</div> </div>
@@ -387,7 +470,10 @@ export default function Home() {
</div> </div>
{/* ── Footer ─────────────────────────────────────────────────────── */} {/* ── Footer ─────────────────────────────────────────────────────── */}
<p className="text-center text-[12px] text-[#80848e] mt-6"> <p
className="text-center text-[12px] mt-6"
style={{ color: "#665c54" }}
>
Files are automatically deleted after 24 hours Files are automatically deleted after 24 hours
</p> </p>
</div> </div>