all repos — honk @ c6eb3d0ef8d3377155150dcd5db2de2cb0baa3d3

my fork of honk

refactor server url a bit instead of sprintf everywhere
Ted Unangst tedu@tedunangst.com
Mon, 19 Feb 2024 03:24:40 -0500
commit

c6eb3d0ef8d3377155150dcd5db2de2cb0baa3d3

parent

4e677416490459a50a90d3254867b208a2ef0164

4 files changed, 22 insertions(+), 17 deletions(-)

jump to
M activity.goactivity.go

@@ -1419,7 +1419,7 @@ for _, o := range h.Onts {

t := junk.New() t["type"] = "Hashtag" o = strings.ToLower(o) - t["href"] = fmt.Sprintf("https://%s/o/%s", serverName, o[1:]) + t["href"] = serverURL("/o/%s", o[1:]) t["name"] = o tags = append(tags, t) }

@@ -1703,7 +1703,7 @@ j["type"] = "Add"

j["id"] = user.URL + "/add/" + shortxid(ont+honk.XID) j["actor"] = user.URL j["object"] = honk.XID - j["target"] = fmt.Sprintf("https://%s/o/%s", serverName, ont[1:]) + j["target"] = serverURL("/o/%s", ont[1:]) rcpts := make(map[string]bool) for _, dub := range dubs { box, ok := boxofboxes.Get(dub.XID)

@@ -1734,7 +1734,7 @@ for _, o := range user.Onts {

t := junk.New() t["type"] = "Hashtag" o = strings.ToLower(o) - t["href"] = fmt.Sprintf("https://%s/o/%s", serverName, o[1:]) + t["href"] = serverURL("/o/%s", o[1:]) t["name"] = o tags = append(tags, t) }
M database.godatabase.go

@@ -52,7 +52,7 @@ if err != nil {

return nil, err } if user.ID > 0 { - user.URL = fmt.Sprintf("https://%s/%s/%s", serverName, userSep, user.Name) + user.URL = serverURL("/%s/%s", userSep, user.Name) err = unjsonify(options, &user.Options) if err != nil { elog.Printf("error processing user options: %s", err)

@@ -60,7 +60,7 @@ }

user.ChatPubKey.key, _ = b64tokey(user.Options.ChatPubKey) user.ChatSecKey.key, _ = b64tokey(user.Options.ChatSecKey) } else { - user.URL = fmt.Sprintf("https://%s/%s", serverName, user.Name) + user.URL = serverURL("/%s", user.Name) } if user.Options.Reaction == "" { user.Options.Reaction = "none"

@@ -585,7 +585,7 @@ elog.Printf("error checking file hash: %s", err)

return 0, "", err } if url == "" { - url = fmt.Sprintf("https://%s/d/%s", serverName, xid) + url = serverURL("/d/%s", xid) } }
M main.gomain.go

@@ -46,6 +46,10 @@ var serverMsg template.HTML

var aboutMsg template.HTML var loginMsg template.HTML +func serverURL(u string, args ...interface{}) string { + return fmt.Sprintf("https://"+serverName+u, args...) +} + func ElaborateUnitTests() { }
M web.goweb.go

@@ -253,7 +253,7 @@ honks = getpublichonks()

} reverbolate(-1, honks) - home := fmt.Sprintf("https://%s/", serverName) + home := serverURL("/") base := home if name != "" { home += "u/" + name

@@ -330,7 +330,7 @@ func ping(user *WhatAbout, who string) {

if targ := fullname(who, user.ID); targ != "" { who = targ } - if !strings.HasPrefix(who, "https:") { + if !strings.HasPrefix(who, "https://") { who = gofish(who) } if who == "" {

@@ -565,7 +565,7 @@ }

if rejectactor(user.ID, who) { return } - re_ont := regexp.MustCompile("https://" + serverName + "/o/([\\pL[:digit:]]+)") + re_ont := regexp.MustCompile(serverURL("/o") + "/([\\pL[:digit:]]+)") what := firstofmany(j, "type") dlog.Printf("server got a %s", what) switch what {

@@ -737,7 +737,7 @@ colname := "/followers"

if strings.HasSuffix(url, "/following") { colname = "/following" } - user := fmt.Sprintf("https://%s%s", serverName, url[:len(url)-10]) + user := serverURL("%s", url[:len(url)-10]) j := junk.New() j["@context"] = itiswhatitis j["id"] = user + colname

@@ -900,7 +900,7 @@ user := getserveruser()

j := junk.New() j["@context"] = itiswhatitis - j["id"] = fmt.Sprintf("https://%s/o/%s", serverName, name) + j["id"] = serverURL("/o/%s", name) j["name"] = "#" + name j["attributedTo"] = user.URL j["type"] = "OrderedCollection"

@@ -1240,7 +1240,7 @@ if stealthmode(user.ID, r) {

http.NotFound(w, r) return } - xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path) + xid := serverURL("%s", r.URL.Path) if friendorfoe(r.Header.Get("Accept")) { j, ok := gimmejonk(xid)

@@ -1350,7 +1350,7 @@ ava = ava[7:]

if ava[0] == ' ' { ava = ava[1:] } - ava = fmt.Sprintf("https://%s/meme/%s", serverName, ava) + ava = serverURL("/meme/%s", ava) } if ava != options.Avatar { options.Avatar = ava

@@ -1363,7 +1363,7 @@ ban = ban[7:]

if ban[0] == ' ' { ban = ban[1:] } - ban = fmt.Sprintf("https://%s/meme/%s", serverName, ban) + ban = serverURL("/meme/%s", ban) } if ban != options.Banner { options.Banner = ban

@@ -1786,7 +1786,8 @@ h := submithonk(w, r)

if h == nil { return } - http.Redirect(w, r, h.XID[len(serverName)+8:], http.StatusSeeOther) + redir := h.XID[len(serverURL("")):] + http.Redirect(w, r, redir, http.StatusSeeOther) } // what a hot mess this function is

@@ -1917,7 +1918,7 @@ break

} p := strings.Split(xid, ":") xid = p[0] - url := fmt.Sprintf("https://%s/d/%s", serverName, xid) + url := serverURL("/d/%s", xid) var donk *Donk if len(p) > 1 { fileid, _ := strconv.ParseInt(p[1], 10, 0)

@@ -2254,7 +2255,7 @@ name := orig

idx := strings.LastIndexByte(name, '/') if idx != -1 { name = name[idx+1:] - if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig { + if serverURL("/%s/%s", userSep, name) != orig { ilog.Printf("foreign request rejected") name = "" }