@@ -70,6 +70,72 @@ app.get("/qr/png/:id", async (c) => {
7070 } ) ;
7171} ) ;
7272
73+ app . get ( "/qr/raw/url/:encoded_url" , ( c ) => {
74+ const logger = createLogger ( "qr-render-raw" ) ;
75+ const encodedUrl = c . req . param ( "encoded_url" ) . trim ( ) . toLowerCase ( ) ;
76+
77+ const url = decodeURIComponent ( encodedUrl ) ;
78+
79+ logger . info ( "Rendering QR code for url" , { url } ) ;
80+ const svg = QR ( url ) ;
81+
82+ return c . text ( svg ) ;
83+ } ) ;
84+
85+ app . get ( "/qr/svg/url/:encoded_url" , ( c ) => {
86+ const logger = createLogger ( "qr-render-svg" ) ;
87+ const encodedUrl = c . req . param ( "encoded_url" ) . trim ( ) . toLowerCase ( ) ;
88+
89+ const url = decodeURIComponent ( encodedUrl ) ;
90+
91+ logger . info ( "Rendering QR code for url" , { url } ) ;
92+ const svg = QR ( url ) ;
93+
94+ c . res . headers . set ( "Content-Type" , "image/svg+xml" ) ;
95+
96+ return c . text ( svg ) ;
97+ } ) ;
98+
99+ app . get ( "/qr/png/url/:encoded_url" , ( c ) => {
100+ const logger = createLogger ( "qr-render-png" ) ;
101+ const encodedUrl = c . req . param ( "encoded_url" ) . trim ( ) . toLowerCase ( ) ;
102+
103+ try {
104+ const url = decodeURIComponent ( encodedUrl ) ;
105+
106+ logger . info ( "Rendering QR code for url" , { url } ) ;
107+
108+ const svg = QR ( url ) ;
109+
110+ const resvg = new Resvg ( svg , {
111+ background : "white" ,
112+ fitTo : {
113+ mode : "width" ,
114+ value : 1200 ,
115+ } ,
116+ font : {
117+ loadSystemFonts : false ,
118+ } ,
119+ } ) ;
120+
121+ const pngData = resvg . render ( ) ;
122+ const pngBuffer = pngData . asPng ( ) ;
123+
124+ c . res . headers . set ( "Content-Type" , "image/png" ) ;
125+
126+ return new Response ( pngBuffer , {
127+ headers : {
128+ "Content-Type" : "image/png" ,
129+ "Cache-Control" : "public, immutable, no-transform, max-age=31536000" ,
130+ } ,
131+ status : 200 ,
132+ } ) ;
133+ } catch ( error ) {
134+ logger . error ( "Error rendering QR code for url" , { error } ) ;
135+ throw error ;
136+ }
137+ } ) ;
138+
73139app . get ( "/" , ( c ) => {
74140 return c . json ( {
75141 message : "Greetings and salutations from the CommunityOS team" ,
0 commit comments