Skip to content

Commit

Permalink
chore: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
okdargy committed Jun 8, 2024
1 parent c516af8 commit e3c5f9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
44 changes: 22 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,30 @@ async function handleVideo(c: any): Promise<Response> {

// If the user agent is a bot, redirect to the TikTok page
if (!BOT_REGEX.test(c.req.header('User-Agent') || '')) {
const url = new URL(c.req.url)

// Remove tracking parameters
url.search = ''

return new Response('', {
status: 302,
headers: {
Location: 'https://www.tiktok.com' + url.pathname
}
})
}
const url = new URL(c.req.url)

if(!awemeIdPattern.test(id)) {
const url = await grabAwemeId(id)
const match = url.pathname.match(awemeLinkPattern)
// Remove tracking parameters
url.search = ''

if (match) {
id = match[3]
} else {
const responseContent = await ErrorResponse('Invalid video ID')
return returnHTMLResponse(responseContent, 400)
return new Response('', {
status: 302,
headers: {
Location: 'https://www.tiktok.com' + url.pathname
}
})
}

if (!awemeIdPattern.test(id)) {
const url = await grabAwemeId(id)
const match = url.pathname.match(awemeLinkPattern)

if (match) {
id = match[3]
} else {
const responseContent = await ErrorResponse('Invalid video ID')
return returnHTMLResponse(responseContent, 400)
}
}

try {
const videoInfo = await scrapeVideoData(id)
Expand Down Expand Up @@ -150,7 +150,7 @@ async function handleVideo(c: any): Promise<Response> {
}
async function handleLive(c: any): Promise<Response> {
const { author, videoId } = c.req.param()
let authorName = author;
let authorName = author

// If the user agent is a bot, redirect to the TikTok page
if (!BOT_REGEX.test(c.req.header('User-Agent') || '')) {
Expand All @@ -167,7 +167,7 @@ async function handleLive(c: any): Promise<Response> {
})
}

if(!author && !awemeIdPattern.test(videoId)) {
if (!author && !awemeIdPattern.test(videoId)) {
const url = await grabAwemeId(videoId)
const match = url.pathname.match(awemeLinkPattern)

Expand Down
8 changes: 3 additions & 5 deletions src/services/tiktok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ export async function scrapeLiveData(author: string): Promise<LiveRoom | Error>
const html = await res.text()

try {
const resJson = html
.split('<script id="SIGI_STATE" type="application/json">')[1]
.split('</script>')[0]
const resJson = html.split('<script id="SIGI_STATE" type="application/json">')[1].split('</script>')[0]
const json: LiveWebJSONResponse = JSON.parse(resJson)

if (!json['LiveRoom']) throw new Error('Could not find live data')

return json['LiveRoom']
} catch (err) {
throw new Error('Could not parse live data')
}
}
}
2 changes: 1 addition & 1 deletion src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './pages/VideoResponse'
export * from './pages/Error'
export * from './pages/LiveResponse'
export * from './pages/LiveResponse'

0 comments on commit e3c5f9d

Please sign in to comment.