4
4
"encoding/json"
5
5
"fmt"
6
6
"net/http"
7
- "text/template"
8
7
9
8
"github.com/gin-gonic/gin"
10
9
)
@@ -15,9 +14,10 @@ type QRValue struct {
15
14
16
15
func generateQRPage (apiEndpoint string ) gin.HandlerFunc {
17
16
return func (c * gin.Context ) {
18
- apiEndpoint := c .Request .Host + apiEndpoint
17
+ fullApiEndpoint := c .Request .Host + apiEndpoint
18
+ // Create QRValue and marshal to JSON
19
19
qrValue , err := json .Marshal (QRValue {
20
- ApiEndpoint : apiEndpoint ,
20
+ ApiEndpoint : fullApiEndpoint ,
21
21
})
22
22
if err != nil {
23
23
c .JSON (http .StatusInternalServerError , gin.H {
@@ -26,40 +26,39 @@ func generateQRPage(apiEndpoint string) gin.HandlerFunc {
26
26
return
27
27
}
28
28
29
- qrValueEscaped := template .JSEscapeString (string (qrValue ))
30
-
29
+ // Generate HTML content
31
30
htmlContent := fmt .Sprintf (`
32
31
<!DOCTYPE html>
33
32
<html lang="en">
34
33
<head>
35
- <meta charset="UTF-8">
36
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
37
- <title>QR Code</title>
38
- <link href="https://cdn.jsdelivr.net/npm/[email protected] /dist/tailwind.min.css" rel="stylesheet">
39
- <script src="https://cdn.jsdelivr.net/npm/qrious@latest/dist/qrious.min.js"></script>
34
+ <meta charset="UTF-8">
35
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
36
+ <title>QR Code</title>
37
+ <link href="https://cdn.jsdelivr.net/npm/[email protected] /dist/tailwind.min.css" rel="stylesheet">
38
+ <script src="https://cdn.jsdelivr.net/npm/qrious@latest/dist/qrious.min.js"></script>
40
39
</head>
41
40
<body class="bg-gray-100 h-screen flex items-center justify-center">
42
41
<!-- QR Code Container -->
43
42
<div class="bg-white p-8 rounded-lg shadow-md text-center">
44
- <p class="text-xl mb-4">Scan QR code with Adder Mobile to connect to the Adder Server on <span class="font-semibold">%s</span></p>
45
- <canvas id="qrCanvas" class="mx-auto"></canvas>
43
+ <p class="text-xl mb-4">Scan QR code with Adder Mobile to connect to the Adder Server on <span class="font-semibold">%s</span></p>
44
+ <canvas id="qrCanvas" class="mx-auto"></canvas>
46
45
</div>
47
46
48
47
<!-- Generate QR Code using JavaScript -->
49
48
<script>
50
- window.onload = function() {
51
- const canvas = document.getElementById('qrCanvas');
52
- const qrValue = "%s";
53
- const qr = new QRious({
54
- element: canvas,
55
- value: qrValue,
56
- size: 250
57
- });
58
- }
49
+ window.onload = function() {
50
+ const canvas = document.getElementById('qrCanvas');
51
+ const qrValue = %s; // Directly embed the JSON object
52
+ const qr = new QRious({
53
+ element: canvas,
54
+ value: JSON.stringify( qrValue) ,
55
+ size: 250
56
+ });
57
+ }
59
58
</script>
60
59
</body>
61
60
</html>
62
- ` , apiEndpoint , qrValueEscaped )
61
+ ` , fullApiEndpoint , qrValue )
63
62
64
63
c .Data (http .StatusOK , "text/html; charset=utf-8" , []byte (htmlContent ))
65
64
}
0 commit comments