-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import qr from 'https://esm.sh/[email protected]'; | ||
|
||
export default async function handler(req: Request) { | ||
const params = new URL(req.url).searchParams; | ||
const text = params.get('text'); | ||
|
||
if (!text) { | ||
return new Response('Missing text query parameter', { status: 400 }); | ||
} | ||
|
||
if (text.length > 1000) { | ||
return new Response('Text query parameter is too long', { status: 400 }); | ||
} | ||
|
||
const data = qr.imageSync(text, { type: 'png' }); | ||
|
||
const v = params.get('v') || ''; | ||
|
||
const cacheKey = new URLSearchParams(); | ||
cacheKey.append('text', text); | ||
cacheKey.append('v', v); | ||
|
||
return new Response(data, { | ||
headers: { | ||
'Content-Type': 'image/png', | ||
'Cache-Control': 'public, max-age=31536000, immutable', // Cache for 1 year | ||
}, | ||
}); | ||
} | ||
export const config = { | ||
cache: 'manual', | ||
path: '/edge-functions/qr-code', | ||
}; |