|
@@ -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)
|
|
|
|