mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-08-15 09:23:58 +08:00
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:
19
pkg/storagetypes/context.go
Normal file
19
pkg/storagetypes/context.go
Normal 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
|
||||
}
|
||||
24
pkg/storagetypes/context_test.go
Normal file
24
pkg/storagetypes/context_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user