Add URL shortener for link tracking and shorter posts

- New short_urls and clicks tables for URL mapping and analytics
- /r/{code} redirect endpoint with click tracking
- Short URLs use 6-char base64 hash codes (26 chars total)
- Publish loop now shortens article links and enclosure URLs
- Enables podcast audio URLs to fit in posts (139 → 26 chars)
- Tracks: timestamp, referrer, user agent, anonymized IP

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
primal
2026-01-28 22:43:42 -05:00
parent f4f80e91cc
commit 94d64373ed
4 changed files with 331 additions and 1 deletions
+18 -1
View File
@@ -246,8 +246,25 @@ func (c *Crawler) StartPublishLoop() {
sessions[account] = session
}
// Shorten URLs before publishing
itemToPublish := item
if item.Link != "" {
if shortURL, err := c.GetShortURLForPost(item.Link, &item.ID, item.FeedURL); err == nil {
itemToPublish.Link = shortURL
}
}
if item.Enclosure != nil && item.Enclosure.URL != "" {
if shortURL, err := c.GetShortURLForPost(item.Enclosure.URL, &item.ID, item.FeedURL); err == nil {
itemToPublish.Enclosure = &Enclosure{
URL: shortURL,
Type: item.Enclosure.Type,
Length: item.Enclosure.Length,
}
}
}
// Publish the item
uri, err := publisher.PublishItem(session, &item)
uri, err := publisher.PublishItem(session, &itemToPublish)
if err != nil {
fmt.Printf("Publish: failed item %d: %v\n", item.ID, err)
// Clear session cache on auth errors