all repos — honk @ 36c7c21e5ff514592050d276d176b33b4faf3476

my fork of honk

more robust shortcut.. return hash of long xid instead of tail.
sometimes the suffix is common to many activities.
noticed by micropub.
Ted Unangst tedu@tedunangst.com
Tue, 22 Oct 2019 13:06:43 -0400
commit

36c7c21e5ff514592050d276d176b33b4faf3476

parent

6fa77e6b0dd73cb8c9f901e02806264ac6e06063

2 files changed, 17 insertions(+), 11 deletions(-)

jump to
M activity.goactivity.go

@@ -1176,6 +1176,8 @@ var buf bytes.Buffer

jonk.Write(&buf) msg := buf.Bytes() + log.Printf("obj for transmission: %s", msg) + rcpts := make(map[string]bool) for _, a := range honk.Audience { if a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") {
M fun.gofun.go

@@ -18,8 +18,10 @@

import ( "crypto/rand" "crypto/rsa" + "crypto/sha512" "fmt" "html/template" + "io" "log" "net/http" "os"

@@ -230,23 +232,25 @@ honk.Donks = honk.Donks[:j]

} } -func shortxid(xid string) string { - idx := strings.LastIndexByte(xid, '/') - if idx == -1 { - return xid +func xcelerate(b []byte) string { + letters := "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz1234567891234567891234" + for i, c := range b { + b[i] = letters[c&63] } - return xid[idx+1:] + s := string(b) + return s +} + +func shortxid(xid string) string { + h := sha512.New512_256() + io.WriteString(h, xid) + return xcelerate(h.Sum(nil)[:20]) } func xfiltrate() string { - letters := "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz1234567891234567891234" var b [18]byte rand.Read(b[:]) - for i, c := range b { - b[i] = letters[c&63] - } - s := string(b[:]) - return s + return xcelerate(b[:]) } var re_hashes = regexp.MustCompile(`(?:^| )#[[:alnum:]][[:alnum:]_-]*`)