Initial commit
This commit is contained in:
commit
0e35933ee3
19 files changed
+3217
No files matched your search
+48
@@ -0,0 +1,48 @@
|
||||
# ── Python ────────────────────────────────────────────────────────────────────
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.pyo
|
||||
*.pyd
|
||||
*.so
|
||||
*.egg
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
.eggs/
|
||||
|
||||
# Virtual environment
|
||||
.venv/
|
||||
venv/
|
||||
env/
|
||||
|
||||
# uv
|
||||
.uv/
|
||||
|
||||
# ── Environment / secrets ─────────────────────────────────────────────────────
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# ── Next.js ───────────────────────────────────────────────────────────────────
|
||||
frontend/.next/
|
||||
frontend/out/
|
||||
|
||||
# ── Node ──────────────────────────────────────────────────────────────────────
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# ── TypeScript ────────────────────────────────────────────────────────────────
|
||||
*.tsbuildinfo
|
||||
|
||||
# ── OS ────────────────────────────────────────────────────────────────────────
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# ── Editor ────────────────────────────────────────────────────────────────────
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
@@ -0,0 +1,92 @@
|
||||
# filehost
|
||||
|
||||
A minimal self-hosted file sharing tool. Upload a file, get a public link. Files are stored on Cloudflare R2 and expire after 24 hours.
|
||||
|
||||
**Stack:** Next.js 15 (frontend) · FastAPI (backend) · Cloudflare R2 (storage)
|
||||
|
||||
---
|
||||
|
||||
## How it works
|
||||
|
||||
1. Enter the upload password to authenticate
|
||||
2. Drop a file or click to browse (50 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.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- [Node.js](https://nodejs.org/) 18+
|
||||
- [Python](https://www.python.org/) 3.11+
|
||||
- [uv](https://docs.astral.sh/uv/) (Python package manager)
|
||||
- A [Cloudflare R2](https://developers.cloudflare.com/r2/) bucket with public access enabled
|
||||
|
||||
---
|
||||
|
||||
## Environment setup
|
||||
|
||||
Create `backend/.env`:
|
||||
|
||||
```
|
||||
R2_ENDPOINT=https://<account-id>.r2.cloudflarestorage.com
|
||||
R2_ACCESS_KEY=<your-r2-access-key-id>
|
||||
R2_SECRET_KEY=<your-r2-secret-access-key>
|
||||
R2_BUCKET=<your-bucket-name>
|
||||
PUBLIC_URL=https://<your-public-bucket-url>
|
||||
UPLOAD_PASSWORD=<choose-a-password>
|
||||
```
|
||||
|
||||
> `PUBLIC_URL` is the public base URL of your R2 bucket (e.g. `https://pub-xxx.r2.dev` or a custom domain). It must include `https://`.
|
||||
|
||||
---
|
||||
|
||||
## Running locally
|
||||
|
||||
### Backend
|
||||
|
||||
```sh
|
||||
cd backend
|
||||
uv venv
|
||||
source .venv/bin/activate
|
||||
uv pip install -r requirements.txt
|
||||
uvicorn app.main:app --reload
|
||||
```
|
||||
|
||||
Runs on `http://localhost:8000`.
|
||||
|
||||
### Frontend
|
||||
|
||||
```sh
|
||||
cd frontend
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Runs on `http://localhost:3000`.
|
||||
|
||||
Open `http://localhost:3000` in your browser.
|
||||
|
||||
---
|
||||
|
||||
## Project structure
|
||||
|
||||
```
|
||||
filehost/
|
||||
├── backend/
|
||||
│ ├── app/
|
||||
│ │ ├── config/
|
||||
│ │ │ └── settings.py # Pydantic settings (reads .env)
|
||||
│ │ ├── services/
|
||||
│ │ │ └── r2.py # Cloudflare R2 upload logic
|
||||
│ │ └── main.py # FastAPI app, /auth and /upload routes
|
||||
│ ├── requirements.txt
|
||||
│ └── .env # ← you create this
|
||||
└── frontend/
|
||||
├── src/app/
|
||||
│ ├── page.tsx # Upload UI
|
||||
│ ├── layout.tsx
|
||||
│ └── globals.css
|
||||
└── next.config.ts # Proxies /api/* → localhost:8000
|
||||
```
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,16 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
R2_ENDPOINT: str
|
||||
R2_ACCESS_KEY: str
|
||||
R2_SECRET_KEY: str
|
||||
R2_BUCKET: str
|
||||
PUBLIC_URL: str
|
||||
UPLOAD_PASSWORD: str
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -0,0 +1,80 @@
|
||||
import mimetypes
|
||||
import secrets
|
||||
|
||||
from fastapi import FastAPI, File, Form, HTTPException, 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
|
||||
|
||||
app = FastAPI(title="File Host API")
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["https://filehost.subodh.xyz"],
|
||||
allow_methods=["POST"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
def _resolve_object_name(filename: str, content_type: str) -> str:
|
||||
file_id = secrets.token_urlsafe(16)
|
||||
|
||||
ext = ""
|
||||
if filename and "." in filename:
|
||||
ext = filename.rsplit(".", 1)[-1].strip().lower()
|
||||
|
||||
if not ext and content_type:
|
||||
guessed = mimetypes.guess_extension(content_type.split(";")[0].strip())
|
||||
if guessed:
|
||||
ext = guessed.lstrip(".")
|
||||
|
||||
return f"{file_id}.{ext}" if ext else file_id
|
||||
|
||||
|
||||
@app.post("/auth")
|
||||
async def auth(password: str = Form(...)):
|
||||
"""Validate the upload password."""
|
||||
if password != settings.UPLOAD_PASSWORD:
|
||||
raise HTTPException(status_code=401, detail="Invalid password.")
|
||||
return {"valid": True}
|
||||
|
||||
|
||||
@app.post("/upload")
|
||||
async def upload(
|
||||
file: UploadFile = File(...),
|
||||
password: str = Form(...),
|
||||
):
|
||||
"""Validate password, enforce size limit, and upload 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
|
||||
raise HTTPException(
|
||||
status_code=413,
|
||||
detail=f"File is too large ({mb:.1f} MB). Maximum allowed size is 50 MB.",
|
||||
)
|
||||
|
||||
content_type = (
|
||||
(file.content_type or "application/octet-stream").split(";")[0].strip()
|
||||
)
|
||||
object_name = _resolve_object_name(file.filename or "", content_type)
|
||||
|
||||
try:
|
||||
url = await upload_file(
|
||||
file_bytes=content,
|
||||
object_name=object_name,
|
||||
content_type=content_type,
|
||||
)
|
||||
except RuntimeError as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
||||
|
||||
return {"url": url}
|
||||
Whitespace-only changes.
@@ -0,0 +1,47 @@
|
||||
import asyncio
|
||||
from functools import lru_cache
|
||||
|
||||
import boto3
|
||||
from botocore.client import Config
|
||||
from botocore.exceptions import BotoCoreError, ClientError
|
||||
|
||||
from app.config.settings import settings
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _get_r2_client():
|
||||
"""Return a module-level singleton boto3 S3 client for R2."""
|
||||
return boto3.client(
|
||||
"s3",
|
||||
endpoint_url=settings.R2_ENDPOINT,
|
||||
aws_access_key_id=settings.R2_ACCESS_KEY,
|
||||
aws_secret_access_key=settings.R2_SECRET_KEY,
|
||||
config=Config(signature_version="s3v4"),
|
||||
region_name="auto",
|
||||
)
|
||||
|
||||
|
||||
def _put_object(object_name: str, file_bytes: bytes, content_type: str) -> str:
|
||||
"""Blocking S3 put"""
|
||||
key = f"files/{object_name}"
|
||||
|
||||
_get_r2_client().put_object(
|
||||
Bucket=settings.R2_BUCKET,
|
||||
Key=key,
|
||||
Body=file_bytes,
|
||||
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"""
|
||||
try:
|
||||
url = await asyncio.to_thread(
|
||||
_put_object, object_name, file_bytes, content_type
|
||||
)
|
||||
except (BotoCoreError, ClientError) as exc:
|
||||
raise RuntimeError(f"R2 upload failed: {exc}") from exc
|
||||
|
||||
return url
|
||||
@@ -0,0 +1,6 @@
|
||||
fastapi
|
||||
uvicorn[standard]
|
||||
python-multipart
|
||||
boto3
|
||||
botocore
|
||||
pydantic-settings
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
async rewrites() {
|
||||
return [
|
||||
{
|
||||
source: "/api/:path*",
|
||||
destination: "http://localhost:8000/:path*",
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
Generated
+2123
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "filehost-frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"lucide-react": "^0.474.0",
|
||||
"next": "15.1.7",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"autoprefixer": "^10.0.1",
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/** @type {import('postcss-load-config').Config} */
|
||||
const config = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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 · 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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { Config } from "tailwindcss";
|
||||
|
||||
const config: Config = {
|
||||
content: [
|
||||
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
slate: {
|
||||
950: "#0f172a",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [{ "name": "next" }],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in new issue
Block a user