Skip to content

Commit

Permalink
support intl tenor links (#2438)
Browse files Browse the repository at this point in the history
* support intl tenor links

* update test cases
  • Loading branch information
haileyok authored Jan 8, 2024
1 parent 9eeff2c commit 928a626
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions __tests__/lib/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ describe('parseEmbedPlayerFromUrl', () => {
'https://tenor.com/notView/gifId',
'https://tenor.com/view',
'https://tenor.com/view/gifId.gif',
'https://tenor.com/intl/view/gifId.gif',
]

const outputs = [
Expand Down Expand Up @@ -742,6 +743,13 @@ describe('parseEmbedPlayerFromUrl', () => {
hideDetails: true,
playerUri: 'https://tenor.com/view/gifId.gif',
},
{
type: 'tenor_gif',
source: 'tenor',
isGif: true,
hideDetails: true,
playerUri: 'https://tenor.com/intl/view/gifId.gif',
},
]

it('correctly grabs the correct id from uri', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/strings/embed-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,12 @@ export function parseEmbedPlayerFromUrl(
}

if (urlp.hostname === 'tenor.com' || urlp.hostname === 'www.tenor.com') {
const [_, path, filename] = urlp.pathname.split('/')
const [_, pathOrIntl, pathOrFilename, intlFilename] =
urlp.pathname.split('/')
const isIntl = pathOrFilename === 'view'
const filename = isIntl ? intlFilename : pathOrFilename

if (path === 'view' && filename) {
if ((pathOrIntl === 'view' || pathOrFilename === 'view') && filename) {
const includesExt = filename.split('.').pop() === 'gif'

return {
Expand Down

0 comments on commit 928a626

Please sign in to comment.