Files
plumber/internal/events/event.go
T
codegirl007 f96df3222d
CI / test (pull_request) Successful in 6m29s
Add video picker and Discord video attachments.
The picker accepts one MP4 or WebM, the thread lightbox zooms photos, and Discord gets the video as a file on a follow-up message so photo embeds still render.
2026-08-31 02:00:56 -07:00

70 lines
1.6 KiB
Go

package events
import (
"io"
"net/url"
"strings"
)
// Image is a public photo or video already attached to a site post.
type Image struct {
URL string
Description string
Kind string
}
// Media is a local upload still held from the create request so Discord can
// attach the bytes. Photos carry re-encoded Bytes; videos carry an open Body.
type Media struct {
Name string
ContentType string
Kind string
Size int64
Body io.ReadCloser
Bytes []byte
}
// PostEvent is a Discord-free snapshot of a site post after a successful write.
type PostEvent struct {
PostID string
RootID string
ParentID string
Title string
Body string
City string
AuthorID string
AuthorName string
AuthorRole string
Images []Image
Permalink string
}
// PostCreated is emitted after a successful site create.
type PostCreated struct {
PostEvent
Media []Media `json:"-"`
Release func() `json:"-"`
}
// PostUpdated is emitted after a successful site edit.
type PostUpdated struct {
PostEvent
}
// PostedToDiscord is emitted after the Discord subscriber finishes with a
// PostCreated (sent, skipped, or failed). Release deletes held upload files.
type PostedToDiscord struct {
PostID string
Release func() `json:"-"`
}
// Permalink builds /questions/{root}#post-{id}, prefixed by baseURL when set.
func Permalink(baseURL, rootID, postID string) string {
path := "/questions/" + url.PathEscape(rootID) + "#post-" + url.PathEscape(postID)
base := strings.TrimRight(strings.TrimSpace(baseURL), "/")
if base == "" {
return path
}
return base + path
}