MM-60351 Use oEmbed for YouTube links (#28312)
* Split up handling of permalinks and other links in getLinkMetadata * MM-60351 Use oEmbed for YouTube links * Explicitly request json from the oEmbed provider * Fix linter * Fix type of CacheAge field * Address feedback
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d53a2ef4df
Коммит
76021c76a0
63
server/channels/app/oembed/endpoint_test.go
Обычный файл
63
server/channels/app/oembed/endpoint_test.go
Обычный файл
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package oembed
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFindEndpointForURL(t *testing.T) {
|
||||
youtubeProvider := providers[slices.IndexFunc(providers, func(provider *ProviderEndpoint) bool {
|
||||
return provider.URL == "https://www.youtube.com/oembed"
|
||||
})]
|
||||
|
||||
for _, testCase := range []struct {
|
||||
Name string
|
||||
Input string
|
||||
Expected *ProviderEndpoint
|
||||
}{
|
||||
{
|
||||
Name: "random URL",
|
||||
Input: "https://example.com/some/random.url",
|
||||
Expected: nil,
|
||||
},
|
||||
{
|
||||
Name: "YouTube home page",
|
||||
Input: "https://www.youtube.com",
|
||||
Expected: nil,
|
||||
},
|
||||
{
|
||||
Name: "YouTube video",
|
||||
Input: "https://www.youtube.com/watch?v=szfZfQFUSnU",
|
||||
Expected: youtubeProvider,
|
||||
},
|
||||
{
|
||||
Name: "YouTube video with short link and tracking information",
|
||||
Input: "https://youtu.be/Qq3zukqBFqQ?si=iK_TPT20H30mH90G",
|
||||
Expected: youtubeProvider,
|
||||
},
|
||||
{
|
||||
Name: "YouTube video with playlist",
|
||||
Input: "https://www.youtube.com/watch?v=Qq3zukqBFqQ&list=PL-jqvaPsjQpMqnRgFEw_3fuGQbcVDTpaM",
|
||||
Expected: youtubeProvider,
|
||||
},
|
||||
{
|
||||
Name: "YouTube playlist",
|
||||
Input: "https://www.youtube.com/playlist?list=PL-jqvaPsjQpMqnRgFEw_3fuGQbcVDTpaM",
|
||||
Expected: youtubeProvider,
|
||||
},
|
||||
{
|
||||
Name: "YouTube channel",
|
||||
Input: "https://www.youtube.com/@MattermostHQ",
|
||||
Expected: nil,
|
||||
},
|
||||
} {
|
||||
t.Run(testCase.Name, func(t *testing.T) {
|
||||
assert.Equal(t, testCase.Expected, FindEndpointForURL(testCase.Input))
|
||||
})
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user