A message containing a YouTube link now carries a preview card. Discord and X build their own card from the URL in the text, so the work is on the bluesky side: the new preview.go asks YouTube's oEmbed endpoint for the title, channel and thumbnail and posts them as an app.bsky.embed.external. Links are found by pulling candidates out of the text and parsing them with net/url rather than by matching a URL shaped regexp, so a host like youtube.com.example.invalid is not mistaken for the real thing. Bluesky allows one embed per post, so a message with both attachments and a link keeps the attachments. A failed oEmbed lookup only costs the card, not the post. Downloading the thumbnail wants the attachment download path, so it is split into fetch and downloadImage, and both now go through a client with a timeout: the event loop is single threaded and a hung request would stall every later message. The Dockerfile built main.go by name, which stops working now that package main spans two files; it builds the package instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
36 lines
729 B
Go
36 lines
729 B
Go
package output
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type stdoutput struct {
|
|
}
|
|
|
|
func StdOutput() *stdoutput {
|
|
return &stdoutput{}
|
|
}
|
|
|
|
func (so *stdoutput) Write(post Post) (Ref, error) {
|
|
if post.ReplyTo != nil {
|
|
fmt.Printf("[reply to: %s]\n", post.ReplyTo.ID)
|
|
}
|
|
fmt.Println(post.Text)
|
|
for _, img := range post.Images {
|
|
fmt.Printf("[image: %s (%s, %d bytes)]\n", img.Filename, img.ContentType, len(img.Data))
|
|
}
|
|
if post.Preview != nil {
|
|
fmt.Printf("[preview: %s - %s (%s)]\n", post.Preview.Title, post.Preview.Description, post.Preview.URL)
|
|
}
|
|
return Ref{ID: post.Text}, nil
|
|
}
|
|
|
|
func (so *stdoutput) Delete(ref Ref) error {
|
|
fmt.Printf("[deleted: %s]\n", ref.ID)
|
|
return nil
|
|
}
|
|
|
|
func (so *stdoutput) GetName() string {
|
|
return "stdout"
|
|
}
|