xzone to start importing external content

This commit is contained in:
Ted Unangst 2019-06-10 22:28:09 -04:00
parent 1f5d1ff144
commit 6ee7cbcf24
4 changed files with 52 additions and 1 deletions

30
honk.go
View File

@ -25,6 +25,7 @@ import (
"log" "log"
notrand "math/rand" notrand "math/rand"
"net/http" "net/http"
"net/url"
"os" "os"
"sort" "sort"
"strconv" "strconv"
@ -378,6 +379,32 @@ func inbox(w http.ResponseWriter, r *http.Request) {
} }
} }
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) { func outbox(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"] name := mux.Vars(r)["name"]
user, err := butwhatabout(name) user, err := butwhatabout(name)
@ -1275,6 +1302,7 @@ func serve() {
"views/account.html", "views/account.html",
"views/about.html", "views/about.html",
"views/login.html", "views/login.html",
"views/xzone.html",
"views/header.html", "views/header.html",
) )
if !debug { if !debug {
@ -1321,11 +1349,13 @@ func serve() {
loggedin.HandleFunc("/chpass", dochpass) loggedin.HandleFunc("/chpass", dochpass)
loggedin.HandleFunc("/atme", homepage) loggedin.HandleFunc("/atme", homepage)
loggedin.HandleFunc("/zonkzone", zonkzone) loggedin.HandleFunc("/zonkzone", zonkzone)
loggedin.HandleFunc("/xzone", xzone)
loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(savehonk))) loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(savehonk)))
loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(savebonk))) loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(savebonk)))
loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit))) loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
loggedin.Handle("/zonkzonk", login.CSRFWrap("zonkzonk", http.HandlerFunc(zonkzonk))) loggedin.Handle("/zonkzonk", login.CSRFWrap("zonkzonk", http.HandlerFunc(zonkzonk)))
loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser))) loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
loggedin.Handle("/ximport", login.CSRFWrap("ximport", http.HandlerFunc(ximport)))
loggedin.HandleFunc("/honkers", showhonkers) loggedin.HandleFunc("/honkers", showhonkers)
loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", showhonker) loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", showhonker)
loggedin.HandleFunc("/c/{name:[[:alnum:]]+}", showcombo) loggedin.HandleFunc("/c/{name:[[:alnum:]]+}", showcombo)

View File

@ -17,8 +17,12 @@
<span><a href="/u/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span> <span><a href="/u/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span>
<span><a href="/honkers">honkers</a></span> <span><a href="/honkers">honkers</a></span>
<span><a href="/c">combos</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="/zonkzone">zonkzone</a></span>
<span><a href="/account">account</a></span> <span><a href="/account">account</a></span>
</details>
{{ else }} {{ else }}
<span><a href="/about">about</a></span> <span><a href="/about">about</a></span>
{{ if .ShowRSS }} {{ if .ShowRSS }}

View File

@ -44,6 +44,12 @@ body > header {
body > header span { body > header span {
margin-right: 2em; margin-right: 2em;
} }
header details {
display: inline;
}
header details[open] summary {
display: none;
}
main { main {
max-width: 1200px; max-width: 1200px;
margin: auto; margin: auto;
@ -162,7 +168,7 @@ button a {
} }
.inlineform select { .inlineform select {
} }
details summary { .honk details summary {
color: #aab; color: #aab;
} }
.limited details summary { .limited details summary {

11
views/xzone.html Normal file
View File

@ -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>