Initial commit

This commit is contained in:
subodh committed 2026-03-08 17:25:31 +05:30
commit 0e35933ee3
19 files changed
+3217

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
:root {
--background: #06070f;
--foreground: #f8fafc;
}
* {
box-sizing: border-box;
}
body {
background: var(--background);
color: var(--foreground);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
::selection {
background: rgba(139, 92, 246, 0.35);
color: #f8fafc;
}
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: #0d0f1a;
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.08);
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;
}
+22
View File
@@ -0,0 +1,22 @@
import type { Metadata } from "next";
import { Geist } from "next/font/google";
import "./globals.css";
const geist = Geist({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "File Host",
description: "Simple temporary file hosting",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={geist.className}>{children}</body>
</html>
);
}
+590
View File
@@ -0,0 +1,590 @@
"use client";
import {
AlertCircle,
CheckCircle2,
CloudUpload,
Copy,
ExternalLink,
Lock,
LockOpen,
RefreshCw,
UploadCloud,
} from "lucide-react";
import { ChangeEvent, DragEvent, useCallback, useRef, useState } from "react";
type Status = "locked" | "unlocked" | "uploading" | "done";
export default function Home() {
const [status, setStatus] = useState<Status>("locked");
const [password, setPassword] = useState("");
const [passwordError, setPasswordError] = useState(false);
const [isDragging, setIsDragging] = useState(false);
const [progress, setProgress] = useState(0);
const [resultUrl, setResultUrl] = useState("");
const [errorMessage, setErrorMessage] = useState("");
const [copied, setCopied] = useState(false);
const [pendingFileName, setPendingFileName] = useState("");
const fileInputRef = useRef<HTMLInputElement>(null);
// ── Auth ──────────────────────────────────────────────────────────────────
const handleUnlock = async () => {
if (!password.trim()) return;
const body = new URLSearchParams({ password });
const res = await fetch("/api/auth", { method: "POST", body });
if (res.ok) {
setPasswordError(false);
setStatus("unlocked");
} else {
setPasswordError(true);
}
};
// ── Upload ────────────────────────────────────────────────────────────────
const uploadFile = useCallback(
(file: File) => {
setStatus("uploading");
setProgress(0);
setResultUrl("");
setErrorMessage("");
setPendingFileName(file.name);
const formData = new FormData();
formData.append("file", file);
formData.append("password", password);
const xhr = new XMLHttpRequest();
xhr.upload.onprogress = (e) => {
if (e.lengthComputable) {
setProgress(Math.round((e.loaded / e.total) * 100));
}
};
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
const data = JSON.parse(xhr.responseText) as { url: string };
const raw = data.url ?? "";
const absolute = raw.startsWith("http")
? raw
: `https://${raw.replace(/^\/\//, "")}`;
setResultUrl(absolute);
setProgress(100);
setStatus("done");
} else {
let detail = "Upload failed.";
try {
const data = JSON.parse(xhr.responseText) as { detail?: string };
if (data.detail) detail = data.detail;
} catch {
// ignore
}
setErrorMessage(detail);
setStatus("unlocked");
}
};
xhr.onerror = () => {
setErrorMessage("Network error — could not reach the server.");
setStatus("unlocked");
};
xhr.open("POST", "/api/upload");
xhr.send(formData);
},
[password],
);
// ── Drag and drop ─────────────────────────────────────────────────────────
const handleDragOver = useCallback(
(e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
if (status === "locked" || status === "uploading") return;
setIsDragging(true);
},
[status],
);
const handleDragLeave = useCallback((e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(false);
}, []);
const handleDrop = useCallback(
(e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(false);
if (status === "locked" || status === "uploading") return;
const file = e.dataTransfer.files[0];
if (file) uploadFile(file);
},
[status, uploadFile],
);
const handleFileChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) uploadFile(file);
if (fileInputRef.current) fileInputRef.current.value = "";
},
[uploadFile],
);
// ── Copy URL ──────────────────────────────────────────────────────────────
const handleCopy = async () => {
await navigator.clipboard.writeText(resultUrl);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
// ── Helpers ───────────────────────────────────────────────────────────────
const isLocked = status === "locked";
const isUploading = status === "uploading";
const isInteractable = status === "unlocked" || status === "done";
// ── Render ────────────────────────────────────────────────────────────────
return (
<main className="min-h-screen flex items-center justify-center p-6 relative overflow-hidden bg-[#06070f]">
{/* ── Ambient background orbs ──────────────────────────────────── */}
<div className="pointer-events-none fixed inset-0 overflow-hidden">
<div
className="orb-1 absolute -top-56 -left-56 w-[600px] h-[600px] rounded-full"
style={{
background:
"radial-gradient(circle, rgba(109,40,217,0.18) 0%, transparent 70%)",
filter: "blur(40px)",
}}
/>
<div
className="orb-2 absolute -bottom-56 -right-56 w-[600px] h-[600px] rounded-full"
style={{
background:
"radial-gradient(circle, rgba(37,99,235,0.18) 0%, transparent 70%)",
filter: "blur(40px)",
}}
/>
<div
className="orb-3 absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[400px] h-[400px] rounded-full"
style={{
background:
"radial-gradient(circle, rgba(79,70,229,0.1) 0%, transparent 70%)",
filter: "blur(60px)",
}}
/>
</div>
{/* ── Subtle dot grid ──────────────────────────────────────────── */}
<div
className="pointer-events-none fixed inset-0"
style={{
backgroundImage:
"radial-gradient(rgba(255,255,255,0.06) 1px, transparent 1px)",
backgroundSize: "28px 28px",
maskImage:
"radial-gradient(ellipse 80% 80% at 50% 50%, black 40%, transparent 100%)",
WebkitMaskImage:
"radial-gradient(ellipse 80% 80% at 50% 50%, black 40%, transparent 100%)",
}}
/>
{/* ── Card ─────────────────────────────────────────────────────── */}
<div className="w-full max-w-md relative z-10">
<div
className="rounded-2xl overflow-hidden"
style={{
background: "rgba(255,255,255,0.032)",
backdropFilter: "blur(28px)",
WebkitBackdropFilter: "blur(28px)",
border: "1px solid rgba(255,255,255,0.07)",
boxShadow:
"0 0 0 1px rgba(255,255,255,0.03) inset, 0 32px 64px -16px rgba(0,0,0,0.7), 0 8px 32px rgba(109,40,217,0.08)",
}}
>
{/* Gradient top-bar accent */}
<div
className="h-[2px] w-full"
style={{
background: "linear-gradient(90deg, #7c3aed, #3b82f6, #06b6d4)",
}}
/>
<div className="p-8 flex flex-col gap-6">
{/* ── Header ─────────────────────────────────────────────── */}
<div className="flex flex-col items-center gap-3 pt-1">
<div
className="w-16 h-16 rounded-2xl flex items-center justify-center"
style={{
background:
"linear-gradient(135deg, rgba(124,58,237,0.22), rgba(59,130,246,0.22))",
border: "1px solid rgba(124,58,237,0.28)",
boxShadow: "0 8px 24px rgba(124,58,237,0.18)",
}}
>
<CloudUpload
className="w-8 h-8 text-violet-300"
strokeWidth={1.5}
/>
</div>
<div className="text-center">
<h1
className="text-[1.6rem] font-bold tracking-tight leading-tight"
style={{
background:
"linear-gradient(135deg, #c4b5fd 0%, #93c5fd 100%)",
WebkitBackgroundClip: "text",
WebkitTextFillColor: "transparent",
backgroundClip: "text",
}}
>
File Host
</h1>
<p className="text-xs text-slate-600 mt-1 tracking-wide">
50 MB max &nbsp;·&nbsp; expires in 24 h
</p>
</div>
</div>
{/* Divider */}
<div
className="h-px"
style={{
background:
"linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent)",
}}
/>
{/* ── Auth ───────────────────────────────────────────────── */}
{isLocked ? (
<div className="flex gap-2">
<input
type="password"
value={password}
onChange={(e) => {
setPassword(e.target.value);
setPasswordError(false);
}}
onKeyDown={(e) => 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";
}
}}
/>
<button
onClick={handleUnlock}
className="flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold text-white shrink-0 transition-all duration-150 hover:brightness-110 active:scale-[0.96]"
style={{
background: "linear-gradient(135deg, #7c3aed, #2563eb)",
boxShadow: "0 4px 18px rgba(124,58,237,0.35)",
}}
>
<Lock className="w-3.5 h-3.5" />
Unlock
</button>
</div>
) : (
<div
className="flex items-center gap-2.5 px-4 py-2.5 rounded-xl text-sm"
style={{
background: "rgba(52,211,153,0.08)",
border: "1px solid rgba(52,211,153,0.18)",
}}
>
<LockOpen className="w-4 h-4 text-emerald-400" />
<span className="font-medium text-emerald-400">
Authenticated
</span>
</div>
)}
{/* ── Upload zone ────────────────────────────────────────── */}
<div
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
onClick={() => 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,
}}
>
<input
ref={fileInputRef}
type="file"
className="hidden"
onChange={handleFileChange}
/>
{isUploading ? (
/* Uploading state */
<>
<div
className="w-14 h-14 rounded-2xl flex items-center justify-center"
style={{
background:
"linear-gradient(135deg, rgba(124,58,237,0.2), rgba(59,130,246,0.2))",
border: "1px solid rgba(124,58,237,0.3)",
}}
>
<UploadCloud
className="w-7 h-7 text-violet-300"
style={{
animation: "pulse-soft 1.8s ease-in-out infinite",
}}
strokeWidth={1.5}
/>
</div>
<div className="w-full flex flex-col gap-2.5">
<p className="text-sm text-slate-300 font-medium truncate max-w-[220px] mx-auto">
{pendingFileName}
</p>
<div
className="relative w-full rounded-full overflow-hidden"
style={{
height: "5px",
background: "rgba(255,255,255,0.06)",
}}
>
<div
className="absolute inset-y-0 left-0 rounded-full progress-bar transition-[width] duration-300 ease-out"
style={{ width: `${progress}%` }}
/>
</div>
<p className="text-xs text-slate-500 tabular-nums">
{progress}%
</p>
</div>
</>
) : isDragging ? (
/* Drag-over state */
<>
<div
className="w-14 h-14 rounded-2xl flex items-center justify-center"
style={{
background:
"linear-gradient(135deg, rgba(124,58,237,0.3), rgba(59,130,246,0.3))",
border: "1px solid rgba(124,58,237,0.5)",
boxShadow: "0 0 24px rgba(124,58,237,0.2)",
}}
>
<UploadCloud
className="w-7 h-7 text-violet-200"
strokeWidth={1.5}
/>
</div>
<p className="text-sm font-semibold text-violet-300">
Drop to upload
</p>
</>
) : (
/* Idle state */
<>
<div
className="w-14 h-14 rounded-2xl flex items-center justify-center transition-all duration-200"
style={
isLocked
? {
background: "rgba(255,255,255,0.04)",
border: "1px solid rgba(255,255,255,0.06)",
}
: {
background:
"linear-gradient(135deg, rgba(124,58,237,0.14), rgba(59,130,246,0.14))",
border: "1px solid rgba(124,58,237,0.22)",
}
}
>
<UploadCloud
className={
isLocked
? "w-7 h-7 text-slate-700"
: "w-7 h-7 text-slate-400"
}
strokeWidth={1.5}
/>
</div>
<div className="flex flex-col gap-1.5">
<p
className={`text-sm font-medium ${isLocked ? "text-slate-700" : "text-slate-300"}`}
>
{isLocked
? "Enter password to unlock"
: "Drop a file here or click to browse"}
</p>
{!isLocked && (
<p className="text-xs text-slate-600">
Any file type · up to 50 MB
</p>
)}
</div>
</>
)}
</div>
{/* ── Error ──────────────────────────────────────────────── */}
{errorMessage && (
<div
className="rounded-xl flex items-start gap-3 px-4 py-3.5"
style={{
background: "rgba(239,68,68,0.07)",
border: "1px solid rgba(239,68,68,0.2)",
}}
>
<AlertCircle className="w-4 h-4 text-red-400 mt-0.5 shrink-0" />
<p className="text-sm text-red-400 break-all leading-relaxed">
{errorMessage}
</p>
</div>
)}
{/* ── Success ────────────────────────────────────────────── */}
{status === "done" && resultUrl && (
<div
className="rounded-xl flex flex-col gap-4 p-4"
style={{
background: "rgba(52,211,153,0.06)",
border: "1px solid rgba(52,211,153,0.15)",
}}
>
<div className="flex items-center gap-2.5">
<div
className="w-5 h-5 rounded-full flex items-center justify-center shrink-0"
style={{ background: "rgba(52,211,153,0.15)" }}
>
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-400" />
</div>
<span className="text-sm font-semibold text-emerald-400">
Upload complete
</span>
</div>
<input
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)";
}}
/>
<div className="flex gap-2">
<button
onClick={handleCopy}
className="flex-1 flex items-center justify-center gap-2 py-2.5 rounded-xl text-sm font-medium transition-all duration-200 active:scale-[0.97]"
style={
copied
? {
background: "rgba(52,211,153,0.12)",
border: "1px solid rgba(52,211,153,0.25)",
color: "#6ee7b7",
}
: {
background: "rgba(255,255,255,0.05)",
border: "1px solid rgba(255,255,255,0.09)",
color: "#cbd5e1",
}
}
>
<Copy className="w-3.5 h-3.5" />
{copied ? "Copied!" : "Copy URL"}
</button>
<a
href={resultUrl}
target="_blank"
rel="noopener noreferrer"
className="flex-1 flex items-center justify-center gap-2 py-2.5 rounded-xl text-sm font-medium transition-all duration-200 hover:brightness-110 active:scale-[0.97]"
style={{
background:
"linear-gradient(135deg, rgba(124,58,237,0.18), rgba(59,130,246,0.18))",
border: "1px solid rgba(124,58,237,0.25)",
color: "#c4b5fd",
}}
>
<ExternalLink className="w-3.5 h-3.5" />
Open
</a>
</div>
<button
onClick={() => {
setResultUrl("");
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"
>
<RefreshCw className="w-3 h-3" />
Upload another file
</button>
</div>
)}
</div>
</div>
{/* Footer */}
<p className="text-center text-[11px] text-slate-700 mt-5 tracking-wide">
Files are automatically deleted after 24 hours
</p>
</div>
</main>
);
}