diff --git a/secret-worker/src/index.ts b/secret-worker/src/index.ts index 34b6a37..151de58 100644 --- a/secret-worker/src/index.ts +++ b/secret-worker/src/index.ts @@ -15,7 +15,7 @@ app.use(logger()) const api = new Hono(); -api.get(`/secret/:id{${UUID_REGEX}}`, async (c) => { +api.post(`/secret/:id{${UUID_REGEX}}`, async (c) => { const { id } = c.req.param(); const db = drizzle(c.env.DB); const result = await db.delete(secrets).where(eq(secrets.id, id)).returning(); diff --git a/src/App.tsx b/src/App.tsx index 030b551..2f1fb5c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,102 +1,19 @@ -import { useState } from 'react'; -import { Copy, Link, AlertCircle } from 'lucide-react'; +import { useEffect } from 'react'; +import Home from './components/Home'; +import View from './components/View'; +import { isValidUUID } from './lib/utils'; -const OneTimeSecret = () => { - const [secret, setSecret] = useState(''); - const [generatedLink, setGeneratedLink] = useState(''); - const [inputEnabled, setInputEnabled] = useState(true); - const [error, setError] = useState(''); - const handleCreateLink = () => { - const data = secret.trim(); - if (!data.trim()) { - setError('Please enter a secret to create a link.'); - return; - } - - setInputEnabled(false); - - const fetchData = async () => { - const response = await fetch('/api/secret/new', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ data: data.trim() }), - }); - - if (response.ok) { - const data = await response.json(); - setGeneratedLink(`${window.location.origin}/${data.id}`); - } else { - setGeneratedLink(''); - setError('An error occurred while creating the secret link. Please refresh and try again.'); - } - }; - - fetchData(); +const App = () => { + const hash = window.location.hash.substring(1); + if (!isValidUUID(hash) && window.location.pathname !== '/') { + window.location.replace('/'); } - const handleCopyLink = () => { - navigator.clipboard.writeText(generatedLink); - }; - return ( -
-
-

Create One-Time Secret

-