server supports ReadOnly header
This commit is contained in:
@@ -123,6 +123,7 @@ crawl_with() {
|
|||||||
export CONTENT="$(
|
export CONTENT="$(
|
||||||
echo "**!! WARNING !! This page is autogenerated and prone to destruction and replacement**"
|
echo "**!! WARNING !! This page is autogenerated and prone to destruction and replacement**"
|
||||||
echo "**[See the original]($human_url)**"
|
echo "**[See the original]($human_url)**"
|
||||||
|
echo ""
|
||||||
$backend get "$crawlable_source" "$i" \
|
$backend get "$crawlable_source" "$i" \
|
||||||
| sed 's/](\([^#h]\)/]\(%%%\1/g'
|
| sed 's/](\([^#h]\)/]\(%%%\1/g'
|
||||||
)"
|
)"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ type Leaf struct {
|
|||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
Title string
|
Title string
|
||||||
|
ReadOnly bool
|
||||||
Deleted bool
|
Deleted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,19 +29,27 @@ func NewHTTPRequestLeaf(r *http.Request) (Leaf, error) {
|
|||||||
if leaf.Meta.Title = r.Header.Get("Title"); leaf.Meta.Title == "" {
|
if leaf.Meta.Title = r.Header.Get("Title"); leaf.Meta.Title == "" {
|
||||||
leaf.Meta.Title = "Untitled"
|
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
|
leaf.Meta.Deleted = r.Method == http.MethodDelete
|
||||||
return leaf, nil
|
return leaf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLeaf(title string, content string) (Leaf, error) {
|
func NewLeaf(title string, content string) (Leaf, error) {
|
||||||
return NewHTTPRequestLeaf(&http.Request{
|
return NewHTTPRequestLeaf(&http.Request{
|
||||||
Header: http.Header{"Title": []string{title}},
|
Header: http.Header{
|
||||||
|
"Title": []string{title},
|
||||||
|
},
|
||||||
Body: io.NopCloser(strings.NewReader(content)),
|
Body: io.NopCloser(strings.NewReader(content)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (leaf Leaf) WriteHTTP(w http.ResponseWriter) error {
|
func (leaf Leaf) WriteHTTP(w http.ResponseWriter) error {
|
||||||
w.Header().Set("Title", leaf.Meta.Title)
|
w.Header().Set("Title", leaf.Meta.Title)
|
||||||
|
w.Header().Set("Read-Only", strconv.FormatBool(leaf.Meta.ReadOnly))
|
||||||
_, err := w.Write([]byte(leaf.Content))
|
_, err := w.Write([]byte(leaf.Content))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ func (server *Server) uiFilesHandler(w http.ResponseWriter, r *http.Request) err
|
|||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"This": map[string]interface{}{
|
"This": map[string]interface{}{
|
||||||
"Title": leaf.Meta.Title,
|
"Title": leaf.Meta.Title,
|
||||||
|
"ReadOnly": leaf.Meta.ReadOnly,
|
||||||
"Content": leaf.Content,
|
"Content": leaf.Content,
|
||||||
"ID": id.String(),
|
"ID": id.String(),
|
||||||
"PID": id.Pop().String(),
|
"PID": id.Pop().String(),
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ func TestServerPutTreeGetFile(t *testing.T) {
|
|||||||
if w.Code != http.StatusOK {
|
if w.Code != http.StatusOK {
|
||||||
t.Fatal(w)
|
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)
|
t.Fatal(w)
|
||||||
}
|
}
|
||||||
var branch Branch
|
var branch Branch
|
||||||
|
|||||||
Reference in New Issue
Block a user