mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
reduce blocking domain to 1 hour
This commit is contained in:
parent
e6ebac5e13
commit
4674321531
3 changed files with 26 additions and 18 deletions
|
|
@ -165,8 +165,8 @@ const incrementContentFetchFailure = async (
|
|||
const key = failureRedisKey(domain)
|
||||
try {
|
||||
const result = await redisClient.incr(key)
|
||||
// expire the key in 1 day
|
||||
await redisClient.expire(key, 24 * 60 * 60)
|
||||
// expire the key in 1 hour
|
||||
await redisClient.expire(key, 60 * 60)
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export const getYoutubePlaylistId = (url: string) => {
|
|||
return u.searchParams.get('list')
|
||||
}
|
||||
|
||||
const getEmbedData = (url: string) => {
|
||||
export const getEmbedData = (url: string) => {
|
||||
const BaseUrl = 'https://www.youtube.com'
|
||||
const embedBaseUrl = 'https://www.youtube.com/embed'
|
||||
|
||||
|
|
@ -25,17 +25,17 @@ const getEmbedData = (url: string) => {
|
|||
throw new Error(`Invalid youtube url: ${url}`)
|
||||
}
|
||||
|
||||
const type = match[4]
|
||||
const id = match[5]
|
||||
|
||||
if (type === '/playlist?list=') {
|
||||
const playlistId = getYoutubePlaylistId(url) || id
|
||||
|
||||
const playlistId = getYoutubePlaylistId(url)
|
||||
if (playlistId) {
|
||||
return {
|
||||
src: `${embedBaseUrl}/videoseries?list=${playlistId}`,
|
||||
url: `${BaseUrl}/playlist?list=${playlistId}`,
|
||||
}
|
||||
} else if (type === '/shorts/') {
|
||||
}
|
||||
|
||||
const type = match[4]
|
||||
const id = match[5]
|
||||
if (type === '/shorts/') {
|
||||
return {
|
||||
src: `${embedBaseUrl}/${id}`,
|
||||
url: `${BaseUrl}/shorts/${id}`,
|
||||
|
|
@ -43,7 +43,6 @@ const getEmbedData = (url: string) => {
|
|||
}
|
||||
|
||||
const videoId = getYoutubeVideoId(url) || id
|
||||
|
||||
return {
|
||||
src: `${embedBaseUrl}/${videoId}`,
|
||||
url: `${BaseUrl}/watch?v=${videoId}`,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,21 @@
|
|||
import { expect } from "chai";
|
||||
import "mocha";
|
||||
import { escapeTitle, getYoutubePlaylistId, getYoutubeVideoId } from "../src/websites/youtube-handler";
|
||||
import {
|
||||
escapeTitle,
|
||||
getEmbedData,
|
||||
getYoutubePlaylistId,
|
||||
getYoutubeVideoId,
|
||||
} from '../src/websites/youtube-handler'
|
||||
|
||||
describe('getEmbedData', () => {
|
||||
expect('https://www.youtube.com/embed/vFD2gu007dc').to.eq(
|
||||
getEmbedData('https://youtu.be/vFD2gu007dc').src
|
||||
)
|
||||
|
||||
expect('https://www.youtube.com/embed/cg9b4RC87LI').to.eq(
|
||||
getEmbedData('https://youtu.be/cg9b4RC87LI?t=116').src
|
||||
)
|
||||
})
|
||||
|
||||
describe('getYoutubeVideoId', () => {
|
||||
it('should parse video id out of a URL', async () => {
|
||||
|
|
@ -12,15 +27,9 @@ describe('getYoutubeVideoId', () => {
|
|||
'https://www.youtube.com/watch?v=vFD2gu007dc&list=RDvFD2gu007dc&start_radio=1'
|
||||
)
|
||||
)
|
||||
expect('vFD2gu007dc').to.eq(
|
||||
getYoutubeVideoId('https://youtu.be/vFD2gu007dc')
|
||||
)
|
||||
expect('BMFVCnbRaV4').to.eq(
|
||||
getYoutubeVideoId('https://youtube.com/watch?v=BMFVCnbRaV4&feature=share')
|
||||
)
|
||||
expect('cg9b4RC87LI').to.eq(
|
||||
getYoutubeVideoId('https://youtu.be/cg9b4RC87LI?t=116')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue