Spaces:
Configuration error
Configuration error
Upload 5 files
Browse files- Dockerfile +30 -0
- README.md +1 -10
- main.py +106 -0
- requirements.txt +6 -0
- templates/index.html +441 -0
Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python 3.9 slim image as base
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
build-essential \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Copy requirements first to leverage Docker cache
|
| 13 |
+
COPY requirements.txt .
|
| 14 |
+
|
| 15 |
+
# Install Python dependencies
|
| 16 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 17 |
+
|
| 18 |
+
# Copy the rest of the application
|
| 19 |
+
COPY . .
|
| 20 |
+
|
| 21 |
+
# Create a non-root user for security
|
| 22 |
+
RUN adduser --disabled-password --gecos '' appuser
|
| 23 |
+
RUN chown -R appuser:appuser /app
|
| 24 |
+
USER appuser
|
| 25 |
+
|
| 26 |
+
# Expose port 7860
|
| 27 |
+
EXPOSE 7860
|
| 28 |
+
|
| 29 |
+
# Run the application
|
| 30 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,10 +1 @@
|
|
| 1 |
-
-
|
| 2 |
-
title: Shortner
|
| 3 |
-
emoji: β‘
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: pink
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
---
|
| 9 |
-
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
# link-shortner
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
import random
|
| 3 |
+
import string
|
| 4 |
+
from typing import Optional
|
| 5 |
+
from contextlib import contextmanager
|
| 6 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 7 |
+
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 8 |
+
from fastapi.templating import Jinja2Templates
|
| 9 |
+
from fastapi.staticfiles import StaticFiles
|
| 10 |
+
from pydantic import BaseModel, HttpUrl
|
| 11 |
+
import validators
|
| 12 |
+
|
| 13 |
+
app = FastAPI()
|
| 14 |
+
templates = Jinja2Templates(directory="templates")
|
| 15 |
+
|
| 16 |
+
BASE_URL = "https://arevedudaa-shortner.hf.space"
|
| 17 |
+
DB_FILE = "shortener.db"
|
| 18 |
+
|
| 19 |
+
class URLRequest(BaseModel):
|
| 20 |
+
original_url: str
|
| 21 |
+
|
| 22 |
+
@contextmanager
|
| 23 |
+
def get_db_connection():
|
| 24 |
+
conn = sqlite3.connect(DB_FILE)
|
| 25 |
+
try:
|
| 26 |
+
yield conn
|
| 27 |
+
finally:
|
| 28 |
+
conn.close()
|
| 29 |
+
|
| 30 |
+
def init_db():
|
| 31 |
+
with get_db_connection() as conn:
|
| 32 |
+
cursor = conn.cursor()
|
| 33 |
+
cursor.execute('''CREATE TABLE IF NOT EXISTS links (
|
| 34 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 35 |
+
original_url TEXT NOT NULL,
|
| 36 |
+
short_code TEXT UNIQUE NOT NULL,
|
| 37 |
+
short_url TEXT UNIQUE NOT NULL,
|
| 38 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
| 39 |
+
)''')
|
| 40 |
+
conn.commit()
|
| 41 |
+
|
| 42 |
+
def generate_short_code(length: int = 6) -> str:
|
| 43 |
+
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
|
| 44 |
+
|
| 45 |
+
def store_link(original_url: str) -> str:
|
| 46 |
+
with get_db_connection() as conn:
|
| 47 |
+
cursor = conn.cursor()
|
| 48 |
+
|
| 49 |
+
# Check if URL already exists
|
| 50 |
+
cursor.execute("SELECT short_url FROM links WHERE original_url = ?", (original_url,))
|
| 51 |
+
existing = cursor.fetchone()
|
| 52 |
+
if existing:
|
| 53 |
+
return existing[0]
|
| 54 |
+
|
| 55 |
+
# Generate unique short code
|
| 56 |
+
while True:
|
| 57 |
+
short_code = generate_short_code()
|
| 58 |
+
short_url = f"{BASE_URL}/{short_code}"
|
| 59 |
+
cursor.execute("SELECT id FROM links WHERE short_code = ?", (short_code,))
|
| 60 |
+
if not cursor.fetchone():
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
# Store new shortened URL
|
| 64 |
+
cursor.execute(
|
| 65 |
+
"INSERT INTO links (original_url, short_code, short_url) VALUES (?, ?, ?)",
|
| 66 |
+
(original_url, short_code, short_url)
|
| 67 |
+
)
|
| 68 |
+
conn.commit()
|
| 69 |
+
return short_url
|
| 70 |
+
|
| 71 |
+
@app.get("/", response_class=HTMLResponse)
|
| 72 |
+
async def read_root(request: Request):
|
| 73 |
+
return templates.TemplateResponse("index.html", {"request": request})
|
| 74 |
+
|
| 75 |
+
@app.post("/shorten/")
|
| 76 |
+
async def shorten_url(url_request: URLRequest):
|
| 77 |
+
if not url_request.original_url:
|
| 78 |
+
raise HTTPException(status_code=400, detail="URL is required")
|
| 79 |
+
|
| 80 |
+
if not url_request.original_url.startswith(('http://', 'https://')):
|
| 81 |
+
raise HTTPException(status_code=400, detail="URL must start with http:// or https://")
|
| 82 |
+
|
| 83 |
+
try:
|
| 84 |
+
short_url = store_link(url_request.original_url)
|
| 85 |
+
return {"original_url": url_request.original_url, "shortened_url": short_url}
|
| 86 |
+
except Exception as e:
|
| 87 |
+
raise HTTPException(status_code=500, detail="Error creating shortened URL")
|
| 88 |
+
|
| 89 |
+
@app.get("/{short_code}")
|
| 90 |
+
async def redirect_to_url(short_code: str):
|
| 91 |
+
with get_db_connection() as conn:
|
| 92 |
+
cursor = conn.cursor()
|
| 93 |
+
cursor.execute("SELECT original_url FROM links WHERE short_code = ?", (short_code,))
|
| 94 |
+
result = cursor.fetchone()
|
| 95 |
+
|
| 96 |
+
if not result:
|
| 97 |
+
raise HTTPException(status_code=404, detail="Short URL not found")
|
| 98 |
+
|
| 99 |
+
return RedirectResponse(url=result[0])
|
| 100 |
+
|
| 101 |
+
# Initialize database on startup
|
| 102 |
+
init_db()
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
import uvicorn
|
| 106 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
pydantic
|
| 4 |
+
python-multipart
|
| 5 |
+
validators
|
| 6 |
+
jinja2
|
templates/index.html
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
<title>URL Shortener</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
|
| 9 |
+
<style>
|
| 10 |
+
:root {
|
| 11 |
+
--bg-primary: #000000;
|
| 12 |
+
--text-primary: #ffffff;
|
| 13 |
+
--text-secondary: #888888;
|
| 14 |
+
--accent: #FF3B30;
|
| 15 |
+
}
|
| 16 |
+
body {
|
| 17 |
+
font-family: 'Roboto', sans-serif;
|
| 18 |
+
background-color: var(--bg-primary);
|
| 19 |
+
color: var(--text-primary);
|
| 20 |
+
min-height: 100vh;
|
| 21 |
+
overflow-x: hidden;
|
| 22 |
+
}
|
| 23 |
+
.input-container {
|
| 24 |
+
transition: transform 0.3s ease-out;
|
| 25 |
+
}
|
| 26 |
+
.input-container.focused {
|
| 27 |
+
transform: translateY(-60vh);
|
| 28 |
+
}
|
| 29 |
+
.history-item {
|
| 30 |
+
transition: all 0.3s ease;
|
| 31 |
+
}
|
| 32 |
+
.history-item:hover {
|
| 33 |
+
background: rgba(255, 255, 255, 0.05);
|
| 34 |
+
}
|
| 35 |
+
@keyframes glowAnimation {
|
| 36 |
+
0% { box-shadow: 0 0 0 rgba(255, 59, 48, 0); }
|
| 37 |
+
50% { box-shadow: 0 0 20px rgba(255, 59, 48, 0.3); }
|
| 38 |
+
100% { box-shadow: 0 0 0 rgba(255, 59, 48, 0); }
|
| 39 |
+
}
|
| 40 |
+
.success-animation {
|
| 41 |
+
animation: glowAnimation 1s ease-out;
|
| 42 |
+
}
|
| 43 |
+
#developerInfo {
|
| 44 |
+
transition: all 0.3s ease-out;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
#developerInfo > div {
|
| 48 |
+
transition: all 0.3s ease-out;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.social-link {
|
| 52 |
+
transition: all 0.2s ease;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.social-link:hover {
|
| 56 |
+
transform: translateY(-2px);
|
| 57 |
+
}
|
| 58 |
+
</style>
|
| 59 |
+
</head>
|
| 60 |
+
<body class="p-0 m-0">
|
| 61 |
+
<!-- Time and Location -->
|
| 62 |
+
<div class="fixed top-0 left-0 right-0 p-6 z-10">
|
| 63 |
+
<div class="text-2xl font-light" id="time"></div>
|
| 64 |
+
<div class="text-sm text-gray-400" id="date"></div>
|
| 65 |
+
</div>
|
| 66 |
+
|
| 67 |
+
<!-- History Section -->
|
| 68 |
+
<div class="pt-24 px-6 pb-32">
|
| 69 |
+
<div class="text-xs uppercase tracking-wider text-gray-500 mb-4">Recent Links</div>
|
| 70 |
+
<div id="history" class="space-y-4">
|
| 71 |
+
<!-- History items will be added here -->
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<!-- Bottom Input Section -->
|
| 76 |
+
<div id="inputContainer" class="input-container fixed bottom-0 left-0 right-0 p-6 bg-black">
|
| 77 |
+
<form id="urlForm" class="space-y-4">
|
| 78 |
+
<div class="relative">
|
| 79 |
+
<input type="text" id="url"
|
| 80 |
+
class="w-full bg-white/10 text-white px-4 py-3 rounded-2xl border-0
|
| 81 |
+
focus:outline-none focus:ring-2 focus:ring-red-500/30
|
| 82 |
+
placeholder-gray-500 text-base"
|
| 83 |
+
placeholder="Paste your URL here"
|
| 84 |
+
autocomplete="off">
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
<button type="submit"
|
| 88 |
+
class="w-full bg-white/10 text-white py-4 rounded-2xl font-medium
|
| 89 |
+
active:scale-[0.98] transition-all duration-300
|
| 90 |
+
hover:bg-red-500/20 focus:outline-none">
|
| 91 |
+
Shorten URL
|
| 92 |
+
</button>
|
| 93 |
+
</form>
|
| 94 |
+
|
| 95 |
+
<!-- Result Section -->
|
| 96 |
+
<div id="result" class="mt-4 hidden">
|
| 97 |
+
<div class="bg-white/5 rounded-2xl p-4">
|
| 98 |
+
<div class="flex items-center justify-between">
|
| 99 |
+
<input type="text" id="shortUrl" readonly
|
| 100 |
+
class="flex-1 bg-transparent border-none focus:outline-none
|
| 101 |
+
text-white font-light">
|
| 102 |
+
<button onclick="copyToClipboard()"
|
| 103 |
+
class="ml-2 p-2 rounded-xl bg-white/5 text-white/80 hover:bg-white/10
|
| 104 |
+
transition-colors duration-200">
|
| 105 |
+
Copy
|
| 106 |
+
</button>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
|
| 112 |
+
<!-- Developer Info Popup -->
|
| 113 |
+
<div id="developerInfo" class="fixed inset-0 z-50 flex items-center justify-center px-4 bg-black/80 backdrop-blur-sm">
|
| 114 |
+
<div class="bg-white/10 rounded-3xl p-6 max-w-md w-full backdrop-blur-md border border-white/10">
|
| 115 |
+
<div class="flex justify-between items-start mb-6">
|
| 116 |
+
<div class="text-xl font-light">About Developer</div>
|
| 117 |
+
<button onclick="closeDeveloperInfo()"
|
| 118 |
+
class="text-white/60 hover:text-white transition-colors">
|
| 119 |
+
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 120 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
| 121 |
+
</svg>
|
| 122 |
+
</button>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<div class="space-y-4">
|
| 126 |
+
<p class="text-gray-300 leading-relaxed">
|
| 127 |
+
Aditya Devarshi is an AI Engineer passionate about creating innovative projects
|
| 128 |
+
and continuous learning. This URL shortener is one of his many projects
|
| 129 |
+
showcasing modern design principles and functionality.
|
| 130 |
+
</p>
|
| 131 |
+
|
| 132 |
+
<div class="space-y-3 mt-6">
|
| 133 |
+
<div class="text-sm text-gray-400 uppercase tracking-wider">Connect & Follow</div>
|
| 134 |
+
<div class="grid grid-cols-2 gap-3">
|
| 135 |
+
<a href="https://www.adityadevarshi.online/" target="_blank" rel="noopener"
|
| 136 |
+
class="flex items-center gap-2 px-4 py-3 rounded-xl bg-white/5 hover:bg-white/10
|
| 137 |
+
transition-colors text-sm text-white/80 hover:text-white">
|
| 138 |
+
<span>π</span>
|
| 139 |
+
<span>Portfolio</span>
|
| 140 |
+
</a>
|
| 141 |
+
<a href="https://www.linkedin.com/in/aditya-devarshi/" target="_blank" rel="noopener"
|
| 142 |
+
class="flex items-center gap-2 px-4 py-3 rounded-xl bg-white/5 hover:bg-white/10
|
| 143 |
+
transition-colors text-sm text-white/80 hover:text-white">
|
| 144 |
+
<span>πΌ</span>
|
| 145 |
+
<span>LinkedIn</span>
|
| 146 |
+
</a>
|
| 147 |
+
<a href="https://github.com/devarshiadi/" target="_blank" rel="noopener"
|
| 148 |
+
class="flex items-center gap-2 px-4 py-3 rounded-xl bg-white/5 hover:bg-white/10
|
| 149 |
+
transition-colors text-sm text-white/80 hover:text-white">
|
| 150 |
+
<span>π¦</span>
|
| 151 |
+
<span>GitHub</span>
|
| 152 |
+
</a>
|
| 153 |
+
<a href="https://medium.com/@devarshia5" target="_blank" rel="noopener"
|
| 154 |
+
class="flex items-center gap-2 px-4 py-3 rounded-xl bg-white/5 hover:bg-white/10
|
| 155 |
+
transition-colors text-sm text-white/80 hover:text-white">
|
| 156 |
+
<span>π</span>
|
| 157 |
+
<span>Medium</span>
|
| 158 |
+
</a>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
|
| 162 |
+
<div class="mt-6 text-center">
|
| 163 |
+
<button onclick="closeDeveloperInfo()"
|
| 164 |
+
class="px-6 py-2 rounded-xl bg-white/10 text-white/80 hover:bg-white/20
|
| 165 |
+
transition-all duration-300 text-sm">
|
| 166 |
+
Close
|
| 167 |
+
</button>
|
| 168 |
+
</div>
|
| 169 |
+
</div>
|
| 170 |
+
</div>
|
| 171 |
+
</div>
|
| 172 |
+
|
| 173 |
+
<script>
|
| 174 |
+
// Initialize localStorage history
|
| 175 |
+
let urlHistory = JSON.parse(localStorage.getItem('urlHistory') || '[]');
|
| 176 |
+
updateHistoryDisplay(); // Show saved history on load
|
| 177 |
+
// Time and Date Update
|
| 178 |
+
function updateDateTime() {
|
| 179 |
+
const now = new Date();
|
| 180 |
+
const timeString = now.toLocaleTimeString('en-US', {
|
| 181 |
+
hour12: false,
|
| 182 |
+
hour: '2-digit',
|
| 183 |
+
minute: '2-digit'
|
| 184 |
+
});
|
| 185 |
+
const dateString = now.toLocaleDateString('en-US', {
|
| 186 |
+
weekday: 'short',
|
| 187 |
+
month: 'short',
|
| 188 |
+
day: 'numeric'
|
| 189 |
+
});
|
| 190 |
+
|
| 191 |
+
document.getElementById('time').textContent = timeString;
|
| 192 |
+
document.getElementById('date').textContent = dateString;
|
| 193 |
+
}
|
| 194 |
+
updateDateTime();
|
| 195 |
+
setInterval(updateDateTime, 1000);
|
| 196 |
+
// Input Focus Behavior with improved UX
|
| 197 |
+
const inputContainer = document.getElementById('inputContainer');
|
| 198 |
+
const urlInput = document.getElementById('url');
|
| 199 |
+
const historySection = document.querySelector('.pt-24');
|
| 200 |
+
urlInput.addEventListener('focus', () => {
|
| 201 |
+
inputContainer.classList.add('focused');
|
| 202 |
+
historySection.style.opacity = '0.3';
|
| 203 |
+
navigator.vibrate(1);
|
| 204 |
+
});
|
| 205 |
+
document.addEventListener('click', (e) => {
|
| 206 |
+
if (!inputContainer.contains(e.target)) {
|
| 207 |
+
inputContainer.classList.remove('focused');
|
| 208 |
+
historySection.style.opacity = '1';
|
| 209 |
+
}
|
| 210 |
+
});
|
| 211 |
+
// Clear input on successful submission
|
| 212 |
+
function resetForm() {
|
| 213 |
+
urlInput.value = '';
|
| 214 |
+
document.getElementById('result').classList.add('hidden');
|
| 215 |
+
}
|
| 216 |
+
// Form Submission with improved error handling
|
| 217 |
+
document.getElementById('urlForm').addEventListener('submit', async (e) => {
|
| 218 |
+
e.preventDefault();
|
| 219 |
+
const url = urlInput.value.trim();
|
| 220 |
+
|
| 221 |
+
if (!url) {
|
| 222 |
+
showNotification('Please enter a URL', 'error');
|
| 223 |
+
return;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
| 227 |
+
showNotification('Please enter a valid URL starting with http:// or https://', 'error');
|
| 228 |
+
return;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
const submitButton = e.target.querySelector('button');
|
| 232 |
+
submitButton.disabled = true;
|
| 233 |
+
submitButton.innerHTML = '<span class="inline-block animate-pulse">Shortening...</span>';
|
| 234 |
+
|
| 235 |
+
try {
|
| 236 |
+
const response = await fetch('/shorten/', {
|
| 237 |
+
method: 'POST',
|
| 238 |
+
headers: { 'Content-Type': 'application/json' },
|
| 239 |
+
body: JSON.stringify({ original_url: url })
|
| 240 |
+
});
|
| 241 |
+
|
| 242 |
+
const data = await response.json();
|
| 243 |
+
if (response.ok) {
|
| 244 |
+
document.getElementById('result').classList.remove('hidden');
|
| 245 |
+
document.getElementById('shortUrl').value = data.shortened_url;
|
| 246 |
+
|
| 247 |
+
// Add to history and save to localStorage
|
| 248 |
+
addToHistory(url, data.shortened_url);
|
| 249 |
+
|
| 250 |
+
// Success animation and feedback
|
| 251 |
+
inputContainer.classList.add('success-animation');
|
| 252 |
+
setTimeout(() => inputContainer.classList.remove('success-animation'), 1000);
|
| 253 |
+
navigator.vibrate([50, 50, 50]);
|
| 254 |
+
|
| 255 |
+
// Clear input after short delay
|
| 256 |
+
setTimeout(resetForm, 3000);
|
| 257 |
+
} else {
|
| 258 |
+
showNotification(data.detail || 'Error shortening URL', 'error');
|
| 259 |
+
}
|
| 260 |
+
} catch (error) {
|
| 261 |
+
showNotification('Network error occurred', 'error');
|
| 262 |
+
} finally {
|
| 263 |
+
submitButton.disabled = false;
|
| 264 |
+
submitButton.textContent = 'Shorten URL';
|
| 265 |
+
}
|
| 266 |
+
});
|
| 267 |
+
function addToHistory(originalUrl, shortUrl) {
|
| 268 |
+
const historyItem = {
|
| 269 |
+
original: originalUrl,
|
| 270 |
+
shortened: shortUrl,
|
| 271 |
+
timestamp: new Date().toISOString()
|
| 272 |
+
};
|
| 273 |
+
|
| 274 |
+
urlHistory.unshift(historyItem);
|
| 275 |
+
if (urlHistory.length > 10) urlHistory.pop(); // Keep last 10 items
|
| 276 |
+
|
| 277 |
+
// Save to localStorage
|
| 278 |
+
localStorage.setItem('urlHistory', JSON.stringify(urlHistory));
|
| 279 |
+
updateHistoryDisplay();
|
| 280 |
+
}
|
| 281 |
+
function updateHistoryDisplay() {
|
| 282 |
+
const historyContainer = document.getElementById('history');
|
| 283 |
+
if (urlHistory.length === 0) {
|
| 284 |
+
historyContainer.innerHTML = `
|
| 285 |
+
<div class="text-center text-gray-500 py-8">
|
| 286 |
+
No shortened URLs yet
|
| 287 |
+
</div>
|
| 288 |
+
`;
|
| 289 |
+
return;
|
| 290 |
+
}
|
| 291 |
+
historyContainer.innerHTML = urlHistory.map(item => `
|
| 292 |
+
<div class="history-item rounded-xl p-4 bg-white/5 backdrop-blur-sm">
|
| 293 |
+
<div class="flex justify-between items-start">
|
| 294 |
+
<div class="text-sm font-light text-gray-400 truncate flex-1">
|
| 295 |
+
${item.original}
|
| 296 |
+
</div>
|
| 297 |
+
<div class="text-xs text-gray-500 ml-2">
|
| 298 |
+
${new Date(item.timestamp).toLocaleDateString()}
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
<div class="flex justify-between items-center mt-2">
|
| 302 |
+
<div class="text-white truncate flex-1">${item.shortened}</div>
|
| 303 |
+
<div class="flex gap-2">
|
| 304 |
+
<button onclick="copyUrl('${item.shortened}')"
|
| 305 |
+
class="text-xs text-white/60 hover:text-white px-3 py-1 rounded-lg bg-white/10 transition-colors">
|
| 306 |
+
Copy
|
| 307 |
+
</button>
|
| 308 |
+
<button onclick="deleteHistoryItem('${item.timestamp}')"
|
| 309 |
+
class="text-xs text-red-400/60 hover:text-red-400 px-3 py-1 rounded-lg bg-red-500/10 transition-colors">
|
| 310 |
+
Delete
|
| 311 |
+
</button>
|
| 312 |
+
</div>
|
| 313 |
+
</div>
|
| 314 |
+
</div>
|
| 315 |
+
`).join('');
|
| 316 |
+
}
|
| 317 |
+
function deleteHistoryItem(timestamp) {
|
| 318 |
+
urlHistory = urlHistory.filter(item => item.timestamp !== timestamp);
|
| 319 |
+
localStorage.setItem('urlHistory', JSON.stringify(urlHistory));
|
| 320 |
+
updateHistoryDisplay();
|
| 321 |
+
navigator.vibrate(50);
|
| 322 |
+
}
|
| 323 |
+
function copyUrl(url) {
|
| 324 |
+
navigator.clipboard.writeText(url).then(() => {
|
| 325 |
+
showNotification('Copied to clipboard', 'success');
|
| 326 |
+
navigator.vibrate(50);
|
| 327 |
+
});
|
| 328 |
+
}
|
| 329 |
+
function copyToClipboard() {
|
| 330 |
+
const shortUrl = document.getElementById('shortUrl');
|
| 331 |
+
navigator.clipboard.writeText(shortUrl.value).then(() => {
|
| 332 |
+
showNotification('Copied to clipboard', 'success');
|
| 333 |
+
navigator.vibrate(50);
|
| 334 |
+
});
|
| 335 |
+
}
|
| 336 |
+
function showNotification(message, type) {
|
| 337 |
+
const notification = document.createElement('div');
|
| 338 |
+
notification.className = `fixed bottom-32 left-1/2 transform -translate-x-1/2
|
| 339 |
+
px-6 py-3 rounded-2xl text-white text-center text-sm
|
| 340 |
+
${type === 'error' ? 'bg-red-500/90' : 'bg-white/10'}
|
| 341 |
+
opacity-0 transition-opacity duration-300 z-50
|
| 342 |
+
backdrop-blur-sm shadow-lg`;
|
| 343 |
+
notification.textContent = message;
|
| 344 |
+
|
| 345 |
+
document.body.appendChild(notification);
|
| 346 |
+
requestAnimationFrame(() => notification.classList.add('opacity-100'));
|
| 347 |
+
setTimeout(() => {
|
| 348 |
+
notification.classList.remove('opacity-100');
|
| 349 |
+
setTimeout(() => notification.remove(), 300);
|
| 350 |
+
}, 2000);
|
| 351 |
+
}
|
| 352 |
+
function closeDeveloperInfo() {
|
| 353 |
+
const popup = document.getElementById('developerInfo');
|
| 354 |
+
popup.style.opacity = '0';
|
| 355 |
+
popup.style.transform = 'scale(0.95)';
|
| 356 |
+
setTimeout(() => {
|
| 357 |
+
popup.style.display = 'none';
|
| 358 |
+
}, 300);
|
| 359 |
+
// Save to localStorage so it doesn't show again in this session
|
| 360 |
+
localStorage.setItem('developerInfoShown', 'true');
|
| 361 |
+
}
|
| 362 |
+
// Check if we should show the popup
|
| 363 |
+
window.addEventListener('DOMContentLoaded', () => {
|
| 364 |
+
const popup = document.getElementById('developerInfo');
|
| 365 |
+
if (!localStorage.getItem('developerInfoShown')) {
|
| 366 |
+
popup.style.display = 'flex';
|
| 367 |
+
popup.style.opacity = '0';
|
| 368 |
+
popup.style.transform = 'scale(0.95)';
|
| 369 |
+
|
| 370 |
+
// Trigger animation
|
| 371 |
+
setTimeout(() => {
|
| 372 |
+
popup.style.opacity = '1';
|
| 373 |
+
popup.style.transform = 'scale(1)';
|
| 374 |
+
}, 100);
|
| 375 |
+
} else {
|
| 376 |
+
popup.style.display = 'none';
|
| 377 |
+
}
|
| 378 |
+
// Console Developer Info
|
| 379 |
+
console.log(`%c
|
| 380 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 381 |
+
β Aditya Devarshi β
|
| 382 |
+
β AI Engineer & Full Stack Developer β
|
| 383 |
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
|
| 384 |
+
β β
|
| 385 |
+
β π Portfolio: https://www.adityadevarshi.online β
|
| 386 |
+
β πΌ LinkedIn: https://www.linkedin.com/in/aditya-devarshi β
|
| 387 |
+
β π¦ GitHub: https://github.com/devarshiadi β
|
| 388 |
+
β π Medium: https://medium.com/@devarshia5 β
|
| 389 |
+
β β
|
| 390 |
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
|
| 391 |
+
β β
|
| 392 |
+
β π Skills: AI/ML, Full Stack Development, Cloud Computing β
|
| 393 |
+
β π§ Contact: devarshia5@gmail.com β
|
| 394 |
+
β β
|
| 395 |
+
β π‘ "Building the future with AI and innovation" β
|
| 396 |
+
β β
|
| 397 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 398 |
+
`, 'font-family: monospace; color: #00ff00; font-size: 12px;');
|
| 399 |
+
console.log('%cWelcome to URL Shortener!', 'color: #FF3B30; font-size: 20px; font-weight: bold;');
|
| 400 |
+
console.log('%cDeveloped with β€οΈ by Aditya Devarshi', 'color: #888; font-size: 14px;');
|
| 401 |
+
// Tech stack info
|
| 402 |
+
console.log('%cTech Stack:', 'color: #00ff00; font-size: 16px; font-weight: bold;');
|
| 403 |
+
console.table({
|
| 404 |
+
'Frontend': ['HTML5', 'TailwindCSS', 'JavaScript'],
|
| 405 |
+
'Backend': ['Python', 'FastAPI', 'SQLite'],
|
| 406 |
+
'Deployment': ['Docker', 'Cloud Ready'],
|
| 407 |
+
'Design': ['Nothing OS Inspired', 'Modern Minimal UI']
|
| 408 |
+
});
|
| 409 |
+
// Contact info as an object
|
| 410 |
+
console.log('%cContact Information:', 'color: #00ff00; font-size: 16px; font-weight: bold;');
|
| 411 |
+
console.table({
|
| 412 |
+
'Email': 'devarshia5@gmail.com',
|
| 413 |
+
'LinkedIn': 'https://www.linkedin.com/in/aditya-devarshi',
|
| 414 |
+
'Portfolio': 'https://www.adityadevarshi.online',
|
| 415 |
+
'GitHub': 'https://github.com/devarshiadi',
|
| 416 |
+
'Medium': 'https://medium.com/@devarshia5'
|
| 417 |
+
});
|
| 418 |
+
// Project info
|
| 419 |
+
console.log('%cProject Information:', 'color: #00ff00; font-size: 16px; font-weight: bold;');
|
| 420 |
+
console.table({
|
| 421 |
+
'Name': 'Modern URL Shortener',
|
| 422 |
+
'Version': '1.0.0',
|
| 423 |
+
'License': 'MIT',
|
| 424 |
+
'Repository': 'https://github.com/devarshiadi/url-shortener',
|
| 425 |
+
'Design Inspiration': 'Nothing OS',
|
| 426 |
+
'Features': [
|
| 427 |
+
'Modern UI/UX',
|
| 428 |
+
'URL Shortening',
|
| 429 |
+
'History Management',
|
| 430 |
+
'Responsive Design',
|
| 431 |
+
'Dark Mode',
|
| 432 |
+
'Local Storage'
|
| 433 |
+
]
|
| 434 |
+
});
|
| 435 |
+
// Easter egg message
|
| 436 |
+
console.log('%cπ Hey there, curious developer!', 'color: #FF3B30; font-size: 16px; font-weight: bold;');
|
| 437 |
+
console.log('%cLooking for opportunities or collaboration? Feel free to reach out!', 'color: #888; font-size: 14px;');
|
| 438 |
+
});
|
| 439 |
+
</script>
|
| 440 |
+
</body>
|
| 441 |
+
</html>
|