xzone to start importing external content
Ted Unangst tedu@tedunangst.com
Mon, 10 Jun 2019 22:28:09 -0400
4 files changed,
52 insertions(+),
1 deletions(-)
M
honk.go
→
honk.go
@@ -25,6 +25,7 @@ "io"
"log" notrand "math/rand" "net/http" + "net/url" "os" "sort" "strconv"@@ -378,6 +379,32 @@ go consumeactivity(user, j, origin)
} } +func ximport(w http.ResponseWriter, r *http.Request) { + xid := r.FormValue("xid") + j, err := GetJunk(xid) + if err != nil { + log.Printf("error getting external object: %s", err) + return + } + u := login.GetUserInfo(r) + user, _ := butwhatabout(u.Username) + xonk := xonkxonk(user, j, originate(xid)) + convoy := "" + if xonk != nil { + convoy = xonk.Convoy + savexonk(user, xonk) + } + http.Redirect(w, r, "/t?c="+url.QueryEscape(convoy), http.StatusSeeOther) +} + +func xzone(w http.ResponseWriter, r *http.Request) { + templinfo := getInfo(r) + templinfo["XCSRF"] = login.GetCSRF("ximport", r) + err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo) + if err != nil { + log.Print(err) + } +} func outbox(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] user, err := butwhatabout(name)@@ -1275,6 +1302,7 @@ "views/honk.html",
"views/account.html", "views/about.html", "views/login.html", + "views/xzone.html", "views/header.html", ) if !debug {@@ -1321,11 +1349,13 @@ loggedin.HandleFunc("/account", accountpage)
loggedin.HandleFunc("/chpass", dochpass) loggedin.HandleFunc("/atme", homepage) loggedin.HandleFunc("/zonkzone", zonkzone) + loggedin.HandleFunc("/xzone", xzone) loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(savehonk))) loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(savebonk))) loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit))) loggedin.Handle("/zonkzonk", login.CSRFWrap("zonkzonk", http.HandlerFunc(zonkzonk))) loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser))) + loggedin.Handle("/ximport", login.CSRFWrap("ximport", http.HandlerFunc(ximport))) loggedin.HandleFunc("/honkers", showhonkers) loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", showhonker) loggedin.HandleFunc("/c/{name:[[:alnum:]]+}", showcombo)
M
views/header.html
→
views/header.html
@@ -17,8 +17,12 @@ <span><a href="/atme">@me</a></span>
<span><a href="/u/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span> <span><a href="/honkers">honkers</a></span> <span><a href="/c">combos</a></span> +<details> +<summary>more</summary> +<span><a href="/xzone">xzone</a></span> <span><a href="/zonkzone">zonkzone</a></span> <span><a href="/account">account</a></span> +</details> {{ else }} <span><a href="/about">about</a></span> {{ if .ShowRSS }}
M
views/style.css
→
views/style.css
@@ -44,6 +44,12 @@ }
body > header span { margin-right: 2em; } +header details { + display: inline; +} +header details[open] summary { + display: none; +} main { max-width: 1200px; margin: auto;@@ -162,7 +168,7 @@ display: inline;
} .inlineform select { } -details summary { +.honk details summary { color: #aab; } .limited details summary {
A
views/xzone.html
@@ -0,0 +1,11 @@
+{{ template "header.html" . }} +<main> +<div class="info"> +<form action="/ximport" method="POST"> +<input type="hidden" name="CSRF" value="{{ .XCSRF }}"> +<p><span class="title">import</span> +<p><input tabindex=1 type="text" name="xid" autocomplete=off> - xid +<p><input tabindex=1 type="submit" name="fetch" value="fetch"> +</form> +</div> +</main>