Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-infra] Qr code deploy urls #45078

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
qr
  • Loading branch information
Janpot committed Jan 21, 2025
commit 8672181a319c8b5ed79ae5d5abfac674d23ffc5f
4 changes: 2 additions & 2 deletions dangerFileContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ async function addDeployPreviewUrls() {

async function formatMdLinkWithQrCode(path: string) {
const url = String(formatFileToLink(path));
const qrDataUrl = await QRCode.toDataURL(url, {});
return `<details><summary>[${path}](${url})</summary>![${path}](${qrDataUrl})</details>`;
const qr = `${netlifyPreview}edge-functions/qr-code?text=${encodeURIComponent(url)}`;
return `<details><summary><a href="${url}">${path}</a></summary><img src="${qr}" alt="QR code" /></details>`;
}

const files = [...danger.git.created_files, ...danger.git.modified_files];
Expand Down
6 changes: 6 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# run `pnpm --package netlify-cli dlx netlify dev --cwd .` to run functions locally
[dev]
command = "pnpm docs:dev"
targetPort = 3000
port = 8888

[build]
# Directory (relative to root of your repo) that contains the deploy-ready
# HTML files and assets generated by the build. If a base directory has
Expand Down
33 changes: 33 additions & 0 deletions netlify/edge-functions/qr-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import qr from 'https://esm.sh/qr-image@3.2.0';

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',
};
Loading