Skip to content

Commit

Permalink
minor: add caching to getVideoInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
okdargy committed Jan 25, 2024
1 parent 38a0bfb commit 23a8d14
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/services/tiktok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ export async function grabAwemeId(videoId: string): Promise<String | Error> {

export async function getVideoInfo(awemeId: String): Promise<AwemeList | Error> {
// https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/feed/7311925846594342175
const res: Response = await fetch('https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/feed/?aweme_id=' + awemeId)
const res: Response = await fetch('https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/feed/?aweme_id=' + awemeId, {
cf: {
cacheEverything: true,
cacheTtlByStatus: { "200-299": 86400, 404: 1, "500-599": 0 },
},
})
const json: TikTokAPIResponse = await res.json()
const videoInfo: AwemeList | undefined = json.aweme_list.find((aweme) => aweme.aweme_id === awemeId)
if(videoInfo) {

if (videoInfo) {
return videoInfo
} else {
return new Error('Could not find video info')
Expand Down

0 comments on commit 23a8d14

Please sign in to comment.