diff --git a/islands/Decrypt.tsx b/islands/Decrypt.tsx index 8c48739..0c27ea9 100644 --- a/islands/Decrypt.tsx +++ b/islands/Decrypt.tsx @@ -23,11 +23,15 @@ export default function Decrypt() { setStatus('Decrypting file...') - // Fetch encrypted file - const response = await fetch( - `/${encodedFilename}.enc`, - ) - if (!response.ok) throw new Error('File not found') + // Fetch encrypted file using key as filename + const response = await fetch(`/${key}.enc`) + if (!response.ok) { + throw new Error( + response.status === 404 + ? 'File not found or expired' + : 'Failed to fetch file', + ) + } const encryptedData = await response.arrayBuffer() const keyMatches = key.match(/.{2}/g) @@ -88,12 +92,11 @@ export default function Decrypt() { const hash = globalThis.location.hash.slice(1) const key = hash.slice(0, 64) const iv = hash.slice(64, 96) - const encodedFilename = hash.slice(96) - const response = await fetch(`/${encodedFilename}.enc`, { + const response = await fetch(`/${key}.enc`, { method: 'DELETE', headers: { - 'Authorization': `Bearer ${key}${iv}`, // Use key+iv as deletion authorization + 'Authorization': `Bearer ${key}${iv}`, }, }) diff --git a/routes/upload.sh.ts b/routes/upload.sh.ts index a8979e2..df01727 100644 --- a/routes/upload.sh.ts +++ b/routes/upload.sh.ts @@ -1,5 +1,5 @@ // routes/upload.sh.ts -import { Handlers } from "$fresh/server.ts" +import { Handlers } from '$fresh/server.ts' const script = `#!/bin/bash if [ "$#" -ne 1 ]; then @@ -12,8 +12,9 @@ KEY=$(openssl rand -hex 32) IV=$(openssl rand -hex 16) ENCODED_FILENAME=$(echo -n "$FILENAME" | xxd -plain | tr -d '\n' | sed 's/\\(.\\{2\\}\\)/%\\1/g') +# Use key as hash for storage openssl enc -aes-256-cbc -in "$1" -K "$KEY" -iv "$IV" | \\ -curl -s -X PUT "https://cryptsend.thingylabs.io/\${ENCODED_FILENAME}.enc" \\ +curl -s -X PUT "https://cryptsend.thingylabs.io/\${KEY}.enc" \\ -H "Content-Type: application/octet-stream" \\ --data-binary @- > /dev/null && \\ echo "https://cryptsend.thingylabs.io/d/#\${KEY}\${IV}\${ENCODED_FILENAME}" @@ -23,9 +24,9 @@ export const handler: Handlers = { GET() { return new Response(script, { headers: { - "content-type": "text/plain", - "cache-control": "no-cache" - } + 'content-type': 'text/plain', + 'cache-control': 'no-cache', + }, }) - } -} \ No newline at end of file + }, +}