All checks were successful
Reply to a message containing a link with !gallerydl (or send it with a link inline) to download the media via the gallery-dl CLI and have the files posted back as a reply. Restricted to an allowed_users allowlist (comma-separated, per-channel/global config); no one is allowed by default. - Add media support to the platform layer: model.Message.Files, ActionSendMedia, and Platform.SendMedia. Telegram uploads via multipart (sendPhoto/sendVideo/sendDocument, 50MB cap); Slack returns unsupported for now. - Add internal/shell (os/exec wrapper) and internal/urlutil (URL extraction) helpers with tests. - Dispatch ActionSendMedia in app and clean up the temp download dir. - Admin config UI for allowed_users / gallery_dl_path; docs entry. - Containerfile: base on alpine and install gallery-dl + ffmpeg (was scratch); release workflow sets up QEMU + Buildx for cross-arch image builds.
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package urlutil
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestExtractURLs(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
text string
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "no URLs",
|
|
text: "just some plain text with no links",
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "single URL in text",
|
|
text: "check this out https://example.com/photo it is cool",
|
|
expected: []string{"https://example.com/photo"},
|
|
},
|
|
{
|
|
name: "URL with trailing punctuation",
|
|
text: "look at https://example.com/photo.",
|
|
expected: []string{"https://example.com/photo"},
|
|
},
|
|
{
|
|
name: "URL wrapped in parentheses",
|
|
text: "see (https://example.com/a) for details",
|
|
expected: []string{"https://example.com/a"},
|
|
},
|
|
{
|
|
name: "multiple URLs",
|
|
text: "https://a.com/1 and http://b.com/2",
|
|
expected: []string{"https://a.com/1", "http://b.com/2"},
|
|
},
|
|
{
|
|
name: "duplicate URLs are de-duplicated",
|
|
text: "https://a.com/1 https://a.com/1",
|
|
expected: []string{"https://a.com/1"},
|
|
},
|
|
{
|
|
name: "command prefix stripped by extraction",
|
|
text: "!gallerydl https://example.com/gallery/123",
|
|
expected: []string{"https://example.com/gallery/123"},
|
|
},
|
|
{
|
|
name: "non-http scheme ignored",
|
|
text: "ftp://example.com/file and https://ok.com/x",
|
|
expected: []string{"https://ok.com/x"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := ExtractURLs(tt.text)
|
|
if !reflect.DeepEqual(got, tt.expected) {
|
|
t.Errorf("ExtractURLs(%q) = %v, want %v", tt.text, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|