Browse Source

and Abel was a keeper of sheep

jordyn 4 years ago
parent
commit
eb32aeb752
2 changed files with 19 additions and 5 deletions
  1. 16 4
      main.go
  2. 3 1
      pages/dryfig.html

+ 16 - 4
main.go

@@ -4,6 +4,7 @@ import (
 	"log"
 	"os"
 	"io"
+	"strings"
 
 	"encoding/json"
 	"html/template"
@@ -33,11 +34,17 @@ func homeHandler(w http.ResponseWriter, r *http.Request) {
 
 func figHandler(w http.ResponseWriter, r *http.Request) {
 	r.ParseMultipartForm(32 << 20)
-	file, _, err := r.FormFile("newfig")
+	var figstuff io.Reader
+	file, _, err := r.FormFile("newfigfile")
 	if err != nil {
-		panic(err)
+		figtxt := r.FormValue("newfigtxt")
+		if len(figtxt) == 0 {
+			panic(err)
+		}
+		figstuff = strings.NewReader(figtxt)
+	} else {
+		defer file.Close()
 	}
-	defer file.Close()
 
 	fighome, newfig, err := figtree.HarvestFig(
 		r.FormValue("name"),
@@ -58,8 +65,13 @@ func figHandler(w http.ResponseWriter, r *http.Request) {
 	if err != nil {
 		panic(err)
 	}
+
 	defer f.Close()
-	io.Copy(f, file)
+	if file != nil {
+		io.Copy(f, file)
+	} else {
+		io.Copy(f, figstuff)
+	}
 
 	figtree.DryFig(newfig)
 

+ 3 - 1
pages/dryfig.html

@@ -12,7 +12,9 @@
 		<input type="date" id="birth" name="birth"><br>
 
 		<label for="newfig">newfig:</label><br>
-		<input type="file" id="newfig" name="newfig"><br>
+		<input type="file" id="newfigfile" name="newfig"><br>
+
+		<textarea id="newfig" name="newfigtxt" rows="15" cols="80">new fig</textarea><br>
 
 		<input type="submit" value="go">
 	</form>