37 lines
862 B
Go
Executable File
37 lines
862 B
Go
Executable File
package notes
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"local/notes-server/filetree"
|
|
"strings"
|
|
)
|
|
|
|
func (n *Notes) Edit(urlPath string) (string, error) {
|
|
p := filetree.NewPathFromURL(urlPath)
|
|
if p.IsDir() {
|
|
return "", errors.New("path is dir")
|
|
}
|
|
return editFile(p), nil
|
|
}
|
|
|
|
func editFile(p filetree.Path) string {
|
|
href := p.HREF
|
|
href = strings.TrimPrefix(href, "/")
|
|
hrefs := strings.SplitN(href, "/", 2)
|
|
href = hrefs[0]
|
|
if len(hrefs) > 1 {
|
|
href = hrefs[1]
|
|
}
|
|
b, _ := ioutil.ReadFile(p.Local)
|
|
return fmt.Sprintf(`
|
|
<form action="/submit/%s" method="post" style="width:100%%; height: 90%%">
|
|
<table style="width:100%%; height: 90%%">
|
|
<textarea name="content" style="width:100%%; min-height:90%%; cursor:crosshair;">%s</textarea>
|
|
</table>
|
|
<button type="submit">Submit</button>
|
|
</form>
|
|
`, href, b)
|
|
}
|