Skip to content

Commit 281cecc

Browse files
committed
Textarea handler working
1 parent d21e876 commit 281cecc

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

cmd/server/clipboardHandler.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"net/http"
6+
7+
"github.com/FileFormatInfo/svgan/internal/common"
8+
svgan "github.com/FileFormatInfo/svgan/lib"
9+
"github.com/FileFormatInfo/svgan/ui"
10+
)
11+
12+
func clipboardHandler(w http.ResponseWriter, r *http.Request, e error) {
13+
ui.RunTemplate(w, r, "clipboard.tmpl", map[string]interface{}{
14+
"Err": e,
15+
"Title": "SVG Text Analysis",
16+
})
17+
}
18+
19+
func clipboardGetHandler(w http.ResponseWriter, r *http.Request) {
20+
clipboardHandler(w, r, nil)
21+
}
22+
23+
func clipboardPostHandler(w http.ResponseWriter, r *http.Request) {
24+
clipboard := r.FormValue("xml")
25+
if clipboard == "" {
26+
clipboardHandler(w, r, errors.New("no clipboard data provided"))
27+
return
28+
}
29+
30+
svgInfo, svgErr := svgan.SvgCheck(common.Logger, []byte(clipboard))
31+
if svgErr != nil {
32+
clipboardHandler(w, r, svgErr)
33+
return
34+
}
35+
36+
ui.RunTemplate(w, r, "_results.tmpl", map[string]interface{}{
37+
"source": "clipboard",
38+
"size": len(clipboard),
39+
"data": svgInfo,
40+
"Title": "SVG Analysis Results",
41+
})
42+
}

cmd/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func main() {
2828
http.HandleFunc("POST /upload.html", uploadPostHandler)
2929
http.HandleFunc("GET /url.html", urlGetHandler)
3030
http.HandleFunc("POST /url.html", urlPostHandler)
31-
http.HandleFunc("GET /clipboard.html", func(w http.ResponseWriter, r *http.Request) { ui.RunTemplate(w, r, "clipboard.tmpl", nil) })
32-
http.HandleFunc("POST /clipboard.html", uploadGetHandler)
31+
http.HandleFunc("GET /clipboard.html", clipboardGetHandler)
32+
http.HandleFunc("POST /clipboard.html", clipboardPostHandler)
3333

3434
err := http.ListenAndServe(listenAddress+":"+strconv.Itoa(listenPort), nil)
3535
if err != nil {

ui/views/clipboard.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
<form class="pt-3" method="post" action="clipboard.html" enctype="multipart/form-data">
1616
<div class="mb-3">
17-
<label class="form-label" for="svgxml">SVG Source</label>
18-
<textarea class="form-control" name="svgxml" rows="10"></textarea>
17+
<label class="form-label" for="xml">SVG Source</label>
18+
<textarea class="form-control" name="xml" rows="10"></textarea>
1919
</div>
2020
<input class="btn btn-primary" id="submit" type="submit" value="Upload" />
2121
<a class="btn btn-outline-primary" href="index.html">Cancel</a>

0 commit comments

Comments
 (0)