Skip to content

Commit

Permalink
Fix upload path
Browse files Browse the repository at this point in the history
  • Loading branch information
perguth committed Jan 29, 2025
1 parent f7cbf92 commit 569fcb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
19 changes: 11 additions & 8 deletions islands/Decrypt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}`,
},
})

Expand Down
15 changes: 8 additions & 7 deletions routes/upload.sh.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}"
Expand All @@ -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',
},
})
}
}
},
}

0 comments on commit 569fcb4

Please sign in to comment.