feat(telegram): split oversized videos into playable parts (#229)

* feat(telegram): split oversized videos losslessly

* fix(telegram): respect Premium upload limits

* fix(telegram): keep split videos in one album
This commit is contained in:
Haopeng Huo
2026-08-05 16:57:46 +08:00
committed by GitHub
parent 1d794a7b9c
commit e4144e73e6
11 changed files with 839 additions and 24 deletions

View File

@@ -0,0 +1,19 @@
package storagetypes
import "context"
type sourceCaptionContextKey struct{}
// WithSourceCaption records the source Telegram message caption for storage
// backends that can preserve it. Calling this function with an empty caption
// intentionally suppresses a backend-generated fallback caption.
func WithSourceCaption(ctx context.Context, caption string) context.Context {
return context.WithValue(ctx, sourceCaptionContextKey{}, caption)
}
// SourceCaptionFromContext returns the source caption and whether the caller
// explicitly supplied one.
func SourceCaptionFromContext(ctx context.Context) (string, bool) {
caption, ok := ctx.Value(sourceCaptionContextKey{}).(string)
return caption, ok
}

View File

@@ -0,0 +1,24 @@
package storagetypes
import (
"context"
"testing"
)
func TestSourceCaptionContext(t *testing.T) {
if _, ok := SourceCaptionFromContext(context.Background()); ok {
t.Fatal("caption unexpectedly present on empty context")
}
tests := []string{"original caption", ""}
for _, want := range tests {
ctx := WithSourceCaption(context.Background(), want)
got, ok := SourceCaptionFromContext(ctx)
if !ok {
t.Fatalf("caption %q was not marked as present", want)
}
if got != want {
t.Fatalf("caption = %q, want %q", got, want)
}
}
}