add redis storage for pornhub

This commit is contained in:
La macchina desiderante 2024-05-21 23:29:56 +02:00
parent 2c1d71e483
commit 81b3bb8660
1 changed files with 3 additions and 16 deletions

View File

@ -17,8 +17,6 @@ export const fetchPornHubVideoData = async (videoId: string, params?: FetchParam
srcSet: []
}
let related: GalleryData[] = [];
let mediaUrl, sessionCookie, convertedData: VideoSourceItem[]
let reqHeaders = getHeaders(PORNHUB_BASE_URL)
@ -26,10 +24,9 @@ export const fetchPornHubVideoData = async (videoId: string, params?: FetchParam
const queryUrl = `${PORNHUB_BASE_URL_VIDEO}${videoId.replace(/\//g, '')}`
const cachedVideoData = await getDataFromRedis(queryUrl)
const cachedRelatedData = await getDataFromRedis(queryUrl + DEFAULT_RELATED_VIDEO_KEY_PATH)
if (cachedVideoData) {
return [cachedVideoData as VideoData, cachedRelatedData as GalleryData[] ?? []]
return [cachedVideoData as VideoData, []]
}
await axios.get(queryUrl, reqHeaders)
@ -51,14 +48,6 @@ export const fetchPornHubVideoData = async (videoId: string, params?: FetchParam
mediaUrl = getMediaUrl
}
// // populate related gallery
// scriptTags.map((idx, elem) => {
// // magic goes here
// })
// await storeDataIntoRedis(queryUrl + DEFAULT_RELATED_VIDEO_KEY_PATH, related, DEFAULT_PORNHUB_VIDEO_EXPIRY);
})
}).catch((error: AxiosError) => {
@ -67,12 +56,10 @@ export const fetchPornHubVideoData = async (videoId: string, params?: FetchParam
if (sessionCookie && mediaUrl) {
convertedData = await getPornHubMediaUrlList(mediaUrl, sessionCookie)
await storeDataIntoRedis(queryUrl, convertedData, DEFAULT_PORNHUB_VIDEO_EXPIRY);
data.srcSet = convertedData.reverse()
await storeDataIntoRedis(queryUrl, data, DEFAULT_PORNHUB_VIDEO_EXPIRY);
}
return [ data, []]
// return [ { lowResUrl: 'https://www.w3schools.com/html/mov_bbb.mp4' } ,[]]
}