server supports ReadOnly header
parent
2bec0dd1b6
commit
3a0c49157a
|
|
@ -123,6 +123,7 @@ crawl_with() {
|
|||
export CONTENT="$(
|
||||
echo "**!! WARNING !! This page is autogenerated and prone to destruction and replacement**"
|
||||
echo "**[See the original]($human_url)**"
|
||||
echo ""
|
||||
$backend get "$crawlable_source" "$i" \
|
||||
| sed 's/](\([^#h]\)/]\(%%%\1/g'
|
||||
)"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -13,8 +14,9 @@ type Leaf struct {
|
|||
}
|
||||
|
||||
type Meta struct {
|
||||
Title string
|
||||
Deleted bool
|
||||
Title string
|
||||
ReadOnly bool
|
||||
Deleted bool
|
||||
}
|
||||
|
||||
func NewHTTPRequestLeaf(r *http.Request) (Leaf, error) {
|
||||
|
|
@ -27,19 +29,27 @@ func NewHTTPRequestLeaf(r *http.Request) (Leaf, error) {
|
|||
if leaf.Meta.Title = r.Header.Get("Title"); leaf.Meta.Title == "" {
|
||||
leaf.Meta.Title = "Untitled"
|
||||
}
|
||||
if readOnly := r.Header.Get("Read-Only"); readOnly == "true" {
|
||||
leaf.Meta.ReadOnly = true
|
||||
} else if readOnly == "false" {
|
||||
leaf.Meta.ReadOnly = false
|
||||
}
|
||||
leaf.Meta.Deleted = r.Method == http.MethodDelete
|
||||
return leaf, nil
|
||||
}
|
||||
|
||||
func NewLeaf(title string, content string) (Leaf, error) {
|
||||
return NewHTTPRequestLeaf(&http.Request{
|
||||
Header: http.Header{"Title": []string{title}},
|
||||
Body: io.NopCloser(strings.NewReader(content)),
|
||||
Header: http.Header{
|
||||
"Title": []string{title},
|
||||
},
|
||||
Body: io.NopCloser(strings.NewReader(content)),
|
||||
})
|
||||
}
|
||||
|
||||
func (leaf Leaf) WriteHTTP(w http.ResponseWriter) error {
|
||||
w.Header().Set("Title", leaf.Meta.Title)
|
||||
w.Header().Set("Read-Only", strconv.FormatBool(leaf.Meta.ReadOnly))
|
||||
_, err := w.Write([]byte(leaf.Content))
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,11 +271,12 @@ func (server *Server) uiFilesHandler(w http.ResponseWriter, r *http.Request) err
|
|||
}
|
||||
data := map[string]interface{}{
|
||||
"This": map[string]interface{}{
|
||||
"Title": leaf.Meta.Title,
|
||||
"Content": leaf.Content,
|
||||
"ID": id.String(),
|
||||
"PID": id.Pop().String(),
|
||||
"PTitle": parent.Meta.Title,
|
||||
"Title": leaf.Meta.Title,
|
||||
"ReadOnly": leaf.Meta.ReadOnly,
|
||||
"Content": leaf.Content,
|
||||
"ID": id.String(),
|
||||
"PID": id.Pop().String(),
|
||||
"PTitle": parent.Meta.Title,
|
||||
},
|
||||
"Tree": string(branchesJSON),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ func TestServerPutTreeGetFile(t *testing.T) {
|
|||
if w.Code != http.StatusOK {
|
||||
t.Fatal(w)
|
||||
}
|
||||
if !bytes.Contains(w.Body.Bytes(), []byte(`{"Meta":{"Title":"my title","Deleted":false},"Content":"`)) {
|
||||
if !bytes.Contains(w.Body.Bytes(), []byte(`{"Meta":{"Title":"my title","ReadOnly":false,"Deleted":false},"Content":"`)) {
|
||||
t.Fatal(w)
|
||||
}
|
||||
var branch Branch
|
||||
|
|
|
|||
Loading…
Reference in New Issue