more robust shortcut.. return hash of long xid instead of tail.

sometimes the suffix is common to many activities.
noticed by micropub.
master
Ted Unangst 5 years ago
parent acd96f17ee
commit aebc6c8981

@ -1176,6 +1176,8 @@ func honkworldwide(user *WhatAbout, honk *Honk) {
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") {

@ -18,8 +18,10 @@ package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"fmt"
"html/template"
"io"
"log"
"net/http"
"os"
@ -230,23 +232,25 @@ func translate(honk *Honk, redoimages bool) {
}
}
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:]_-]*`)

Loading…
Cancel
Save