|
|
|
@ -37,6 +37,7 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
|
"p83.nl/go/ekster/pkg/util"
|
|
|
|
|
"p83.nl/go/indieauth"
|
|
|
|
|
"p83.nl/go/wiki/link"
|
|
|
|
@ -1114,7 +1115,7 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
http.HandleFunc("/api/block/append", wrapAuth(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
http.HandleFunc("/api/block/replace", wrapAuth(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
err := r.ParseForm()
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, err.Error(), 400)
|
|
|
|
@ -1125,47 +1126,51 @@ func main() {
|
|
|
|
|
http.Error(w, "missing id", 400)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: loads the whole page to save one new block
|
|
|
|
|
page := mp.Get(id)
|
|
|
|
|
log.Println(page.Content)
|
|
|
|
|
var listItems []ListItem
|
|
|
|
|
id = page.Name // Use the name that was actually loaded
|
|
|
|
|
|
|
|
|
|
err = json.NewDecoder(strings.NewReader(page.Content)).Decode(&listItems)
|
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
|
http.Error(w, fmt.Sprintf("while decoding: %s", err.Error()), 500)
|
|
|
|
|
return
|
|
|
|
|
repo := blockRepo{
|
|
|
|
|
dirname: "data",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newId := &ID{"1", true}
|
|
|
|
|
generatedID := newId.NewID()
|
|
|
|
|
listItems = append(listItems, ListItem{
|
|
|
|
|
ID: generatedID,
|
|
|
|
|
Indented: 0,
|
|
|
|
|
Text: r.Form.Get("text"),
|
|
|
|
|
Fleeting: false,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
|
|
err = json.NewEncoder(&buf).Encode(&listItems)
|
|
|
|
|
block, err := repo.Load(id)
|
|
|
|
|
block.Text = r.Form.Get("text")
|
|
|
|
|
err = repo.Save(id, block)
|
|
|
|
|
searchObjects, err := createSearchObjects(id)
|
|
|
|
|
for _, so := range searchObjects {
|
|
|
|
|
searchIndex.Index(so.ID, so)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}))
|
|
|
|
|
http.HandleFunc("/api/block/append", wrapAuth(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
err := r.ParseForm()
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, fmt.Sprintf("while encoding: %s", err.Error()), 500)
|
|
|
|
|
http.Error(w, err.Error(), 400)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
id := r.Form.Get("id")
|
|
|
|
|
if id == "" {
|
|
|
|
|
http.Error(w, "missing id", 400)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
repo := blockRepo{
|
|
|
|
|
dirname: "data",
|
|
|
|
|
}
|
|
|
|
|
newBlock := Block{
|
|
|
|
|
Text: r.Form.Get("text"),
|
|
|
|
|
Children: []string{},
|
|
|
|
|
Parent: id,
|
|
|
|
|
}
|
|
|
|
|
newId := &ID{"1", true}
|
|
|
|
|
generatedID := newId.NewID()
|
|
|
|
|
err = repo.Save(generatedID, newBlock)
|
|
|
|
|
block, err := repo.Load(id)
|
|
|
|
|
block.Children = append(block.Children, generatedID)
|
|
|
|
|
err = repo.Save(id, block)
|
|
|
|
|
|
|
|
|
|
page.Content = buf.String()
|
|
|
|
|
page.Name = id
|
|
|
|
|
page.Title = id
|
|
|
|
|
searchObjects, err := createSearchObjects(id)
|
|
|
|
|
spew.Dump("searchObjects", searchObjects)
|
|
|
|
|
|
|
|
|
|
err = mp.Save(id, page, "", "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, fmt.Sprintf("while saving: %s", err.Error()), 500)
|
|
|
|
|
return
|
|
|
|
|
for _, so := range searchObjects {
|
|
|
|
|
searchIndex.Index(so.ID, so)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println(generatedID)
|
|
|
|
|
return
|
|
|
|
|
}))
|
|
|
|
|
http.HandleFunc("/links.json", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|