From 83be91046c188646205edf54f9570e009cb3bd43 Mon Sep 17 00:00:00 2001 From: Marin Ivanov Date: Fri, 16 Jan 2026 21:16:51 +0200 Subject: paste images into form --- form.html | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 19 +++--- post.html | 31 --------- 3 files changed, 220 insertions(+), 43 deletions(-) create mode 100644 form.html delete mode 100644 post.html diff --git a/form.html b/form.html new file mode 100644 index 0000000..a5de342 --- /dev/null +++ b/form.html @@ -0,0 +1,213 @@ + + + + + + Gloginki + + + + + +
+

Bin-ки и глогинки.

+ +
+ +
+
+ Text Posting + +
+ +
+ File Upload + +
You can also paste an image directly
+
+ +
+ Submit +
+ + +
+
+
+ +
+

Image Preview

+ +
Paste an image to preview it
+
+
+ + + + diff --git a/main.go b/main.go index 2ed8b93..c4bf010 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ type Metadata struct { ContentType string `json:"contentType"` } -//go:embed post.html +//go:embed form.html var static embed.FS func detectMimetype(input io.Reader) (mimeType string, fileext string, recycled io.Reader, err error) { @@ -158,13 +158,6 @@ func (s *Server) formPost(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusFound) } -func (s *Server) formGet(w http.ResponseWriter, r *http.Request) { - f, _ := static.Open("post.html") - if _, err := io.Copy(w, f); err != nil { - w.WriteHeader(http.StatusInternalServerError) - } -} - func (s *Server) servePosting(w http.ResponseWriter, r *http.Request, name string) { filename := filepath.Join(s.data, name) m, err := readMetadata(filename + MetadataExt) @@ -240,8 +233,11 @@ func (s *Server) indexPost(w http.ResponseWriter, r *http.Request) { func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) { path := r.URL.Path if path == "/" { - w.Header().Add("content-type", "text/plain; charset=UTF-8") - w.Write([]byte("Bin-ки и глогинки.")) + w.Header().Add("content-type", "text/html; charset=UTF-8") + f, _ := static.Open("form.html") + if _, err := io.Copy(w, f); err != nil { + w.WriteHeader(http.StatusInternalServerError) + } } else { s.servePosting(w, r, filepath.Base(path)) } @@ -249,11 +245,10 @@ func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) { func (s *Server) Post(w http.ResponseWriter, r *http.Request) { switch r.Method { - case http.MethodGet: - s.formGet(w, r) case http.MethodPost: s.formPost(w, r) default: + w.WriteHeader(http.StatusBadRequest) } } diff --git a/post.html b/post.html deleted file mode 100644 index 3ed8f1b..0000000 --- a/post.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - Gloginki - - -
-
- Text Posting - -
-
- File Upload - -
-
- Submit - - - -
-
- - \ No newline at end of file -- cgit v1.2.3