allow modifying url patterns to better imitate other software. kinda.
This commit is contained in:
parent
eb7b75f809
commit
26cb0ee381
|
@ -237,7 +237,7 @@ func needxonk(user *WhatAbout, x *Honk) bool {
|
||||||
return needxonkid(user, x.XID)
|
return needxonkid(user, x.XID)
|
||||||
}
|
}
|
||||||
func needxonkid(user *WhatAbout, xid string) bool {
|
func needxonkid(user *WhatAbout, xid string) bool {
|
||||||
if strings.HasPrefix(xid, user.URL+"/h/") {
|
if strings.HasPrefix(xid, user.URL+"/") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if iszonked(user.ID, xid) {
|
if iszonked(user.ID, xid) {
|
||||||
|
|
29
honk.go
29
honk.go
|
@ -99,6 +99,9 @@ var serverName string
|
||||||
var iconName = "icon.png"
|
var iconName = "icon.png"
|
||||||
var serverMsg = "Things happen."
|
var serverMsg = "Things happen."
|
||||||
|
|
||||||
|
var userSep = "u"
|
||||||
|
var honkSep = "h"
|
||||||
|
|
||||||
var readviews *templates.Template
|
var readviews *templates.Template
|
||||||
|
|
||||||
func getuserstyle(u *login.UserInfo) template.CSS {
|
func getuserstyle(u *login.UserInfo) template.CSS {
|
||||||
|
@ -121,6 +124,7 @@ func getInfo(r *http.Request) map[string]interface{} {
|
||||||
templinfo["ServerName"] = serverName
|
templinfo["ServerName"] = serverName
|
||||||
templinfo["IconName"] = iconName
|
templinfo["IconName"] = iconName
|
||||||
templinfo["UserInfo"] = u
|
templinfo["UserInfo"] = u
|
||||||
|
templinfo["UserSep"] = userSep
|
||||||
return templinfo
|
return templinfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +260,7 @@ func butwhatabout(name string) (*WhatAbout, error) {
|
||||||
var user WhatAbout
|
var user WhatAbout
|
||||||
var options string
|
var options string
|
||||||
err := row.Scan(&user.ID, &user.Name, &user.Display, &user.About, &user.Key, &options)
|
err := row.Scan(&user.ID, &user.Name, &user.Display, &user.About, &user.Key, &options)
|
||||||
user.URL = fmt.Sprintf("https://%s/u/%s", serverName, user.Name)
|
user.URL = fmt.Sprintf("https://%s/%s/%s", serverName, userSep, user.Name)
|
||||||
user.SkinnyCSS = strings.Contains(options, " skinny ")
|
user.SkinnyCSS = strings.Contains(options, " skinny ")
|
||||||
return &user, err
|
return &user, err
|
||||||
}
|
}
|
||||||
|
@ -537,6 +541,7 @@ func showuser(w http.ResponseWriter, r *http.Request) {
|
||||||
name := mux.Vars(r)["name"]
|
name := mux.Vars(r)["name"]
|
||||||
user, err := butwhatabout(name)
|
user, err := butwhatabout(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("user not found %s: %s", name, err)
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -936,7 +941,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
user, _ := butwhatabout(userinfo.Username)
|
user, _ := butwhatabout(userinfo.Username)
|
||||||
|
|
||||||
dt := time.Now().UTC()
|
dt := time.Now().UTC()
|
||||||
xid := fmt.Sprintf("https://%s/u/%s/h/%s", serverName, userinfo.Username, xfiltrate())
|
xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate())
|
||||||
what := "honk"
|
what := "honk"
|
||||||
if rid != "" {
|
if rid != "" {
|
||||||
what = "tonk"
|
what = "tonk"
|
||||||
|
@ -1319,7 +1324,7 @@ func fingerlicker(w http.ResponseWriter, r *http.Request) {
|
||||||
idx := strings.LastIndexByte(name, '/')
|
idx := strings.LastIndexByte(name, '/')
|
||||||
if idx != -1 {
|
if idx != -1 {
|
||||||
name = name[idx+1:]
|
name = name[idx+1:]
|
||||||
if "https://"+serverName+"/u/"+name != orig {
|
if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig {
|
||||||
log.Printf("foreign request rejected")
|
log.Printf("foreign request rejected")
|
||||||
name = ""
|
name = ""
|
||||||
}
|
}
|
||||||
|
@ -1412,7 +1417,7 @@ func nomoroboto(w http.ResponseWriter, r *http.Request) {
|
||||||
io.WriteString(w, "Disallow: /d\n")
|
io.WriteString(w, "Disallow: /d\n")
|
||||||
io.WriteString(w, "Disallow: /meme\n")
|
io.WriteString(w, "Disallow: /meme\n")
|
||||||
for _, u := range allusers() {
|
for _, u := range allusers() {
|
||||||
fmt.Fprintf(w, "Disallow: /u/%s/h/\n", u.Username)
|
fmt.Fprintf(w, "Disallow: /%s/%s/%s/\n", userSep, u.Username, honkSep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1461,13 +1466,13 @@ func serve() {
|
||||||
getters.HandleFunc("/front", homepage)
|
getters.HandleFunc("/front", homepage)
|
||||||
getters.HandleFunc("/robots.txt", nomoroboto)
|
getters.HandleFunc("/robots.txt", nomoroboto)
|
||||||
getters.HandleFunc("/rss", showrss)
|
getters.HandleFunc("/rss", showrss)
|
||||||
getters.HandleFunc("/u/{name:[[:alnum:]]+}", showuser)
|
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
|
||||||
getters.HandleFunc("/u/{name:[[:alnum:]]+}/h/{xid:[[:alnum:]]+}", showhonk)
|
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/"+honkSep+"/{xid:[[:alnum:]]+}", showhonk)
|
||||||
getters.HandleFunc("/u/{name:[[:alnum:]]+}/rss", showrss)
|
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/rss", showrss)
|
||||||
posters.HandleFunc("/u/{name:[[:alnum:]]+}/inbox", inbox)
|
posters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/inbox", inbox)
|
||||||
getters.HandleFunc("/u/{name:[[:alnum:]]+}/outbox", outbox)
|
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/outbox", outbox)
|
||||||
getters.HandleFunc("/u/{name:[[:alnum:]]+}/followers", emptiness)
|
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/followers", emptiness)
|
||||||
getters.HandleFunc("/u/{name:[[:alnum:]]+}/following", emptiness)
|
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/following", emptiness)
|
||||||
getters.HandleFunc("/a", avatate)
|
getters.HandleFunc("/a", avatate)
|
||||||
getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
|
getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
|
||||||
getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu)
|
getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu)
|
||||||
|
@ -1609,6 +1614,8 @@ func main() {
|
||||||
}
|
}
|
||||||
getconfig("servermsg", &serverMsg)
|
getconfig("servermsg", &serverMsg)
|
||||||
getconfig("servername", &serverName)
|
getconfig("servername", &serverName)
|
||||||
|
getconfig("usersep", &userSep)
|
||||||
|
getconfig("honksep", &honkSep)
|
||||||
getconfig("dnf", &donotfedafterdark)
|
getconfig("dnf", &donotfedafterdark)
|
||||||
prepareStatements(db)
|
prepareStatements(db)
|
||||||
switch cmd {
|
switch cmd {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<span><a href="/">honk</a></span>
|
<span><a href="/">honk</a></span>
|
||||||
{{ if .UserInfo }}
|
{{ if .UserInfo }}
|
||||||
<span><a href="/atme">@me</a></span>
|
<span><a href="/atme">@me</a></span>
|
||||||
<span><a href="/u/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span>
|
<span><a href="/{{ .UserSep }}/{{ .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>
|
<details>
|
||||||
|
|
Loading…
Reference in New Issue