Fix asset wizard, config, and optimize QR codes
This commit is contained in:
1 parent
96338e6dce
commit
3391257f6c
5 files changed
+9
-5
No files matched your search
+1
-1
@@ -21,4 +21,4 @@ length = 4
|
||||
|
||||
[upload]
|
||||
dir = "./data/uploads"
|
||||
max_size_mb = 10
|
||||
max_size_mb = 50
|
||||
@@ -56,6 +56,7 @@ func (s *Server) handleShortRedirect(w http.ResponseWriter, r *http.Request) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
slugVal = strings.ToLower(slugVal)
|
||||
|
||||
// Fetch redirect target by slug
|
||||
link, err := s.db.GetLinkBySlug(slugVal)
|
||||
|
||||
@@ -3,13 +3,14 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
||||
// GenerateQRCodePNG encodes a given string (e.g. short link URL) into a 256x256 PNG image
|
||||
func GenerateQRCodePNG(data string) ([]byte, error) {
|
||||
png, err := qrcode.Encode(data, qrcode.Medium, 256)
|
||||
png, err := qrcode.Encode(data, qrcode.Low, 256)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encoding qr code: %w", err)
|
||||
}
|
||||
@@ -34,8 +35,8 @@ func (s *Server) handleQR(w http.ResponseWriter, r *http.Request) {
|
||||
// Build the absolute short URL
|
||||
shortURL := fmt.Sprintf("%s/s/%s", s.cfg.Server.BaseURL, slug)
|
||||
|
||||
// Generate QR code PNG
|
||||
pngData, err := GenerateQRCodePNG(shortURL)
|
||||
// Generate QR code PNG in all caps for minimum redundancy alphanumeric mode
|
||||
pngData, err := GenerateQRCodePNG(strings.ToUpper(shortURL))
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to generate QR code", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -48,6 +48,7 @@ func securityHeaders(next http.Handler) http.Handler {
|
||||
// Offline-first CSP: Only allows local static resources and fonts from Google Fonts
|
||||
w.Header().Set("Content-Security-Policy",
|
||||
"default-src 'self'; "+
|
||||
"script-src 'self' 'unsafe-inline'; "+
|
||||
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; "+
|
||||
"font-src 'self' https://fonts.gstatic.com; "+
|
||||
"img-src 'self' data:; "+
|
||||
@@ -98,6 +99,7 @@ func (s *Server) Start() error {
|
||||
|
||||
// 4. Short Slug Redirect Handler
|
||||
mux.HandleFunc("GET /s/{slug}", s.handleShortRedirect)
|
||||
mux.HandleFunc("GET /S/{slug}", s.handleShortRedirect)
|
||||
|
||||
// 5. Authentication handlers
|
||||
mux.HandleFunc("GET /admin/login", s.handleLoginPage)
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
<!-- Wizard Card Box -->
|
||||
<div class="card" style="padding: 2.25rem;">
|
||||
<!-- Hidden Form to submit the selection -->
|
||||
<form id="wizard-form" action="/admin/items/new" method="POST">
|
||||
<form id="wizard-form" action="/admin/items/new" method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<input type="hidden" name="wizard_flow" value="true">
|
||||
<input type="hidden" id="input-category" name="category" value="">
|
||||
|
||||
Reference in new issue
Block a user