Skip to content

Commit

Permalink
minor: add 201 if error, fix videoId being username
Browse files Browse the repository at this point in the history
  • Loading branch information
okdargy committed Jan 4, 2024
1 parent 33c6d55 commit 23f1afc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"version": "1.0.0",
"scripts": {
"dev": "wrangler dev src/index.ts",
"deploy": "wrangler deploy --minify src/index.ts",
"release": "pnpm run build && changeset publish"
"build": "wrangler build src/index.ts",
"deploy": "wrangler deploy --minify src/index.ts"
},
"dependencies": {
"hono": "^3.11.7"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230914.0",
"@types/react": "^18.2.46",
"wrangler": "^3.21.0"
},
"homepage": "https://tnktok.com"
}
}
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ app.get('/', (c) => {
})
})

const returnHTMLResponse = (content: string): HandlerResponse<Response> => {
const returnHTMLResponse = (content: string, status?: number): HandlerResponse<Response> => {
return new Response(content, {
status: 200,
status: status || 200,
headers: {
'Content-Type': 'text/html; charset=utf-8',
'Cache-Control': 'public, max-age=3600'
Expand Down Expand Up @@ -67,7 +67,7 @@ async function handleVideo(c: any): Promise<Response> {
id = awemeId
} catch(e) {
const responseContent = await ErrorResponse((e as Error).message);
return returnHTMLResponse(responseContent) as Response;
return returnHTMLResponse(responseContent, 201) as Response;
}
}

Expand All @@ -76,14 +76,14 @@ async function handleVideo(c: any): Promise<Response> {

if (videoInfo instanceof Error) {
const responseContent = await ErrorResponse((videoInfo as Error).message);
return returnHTMLResponse(responseContent) as Response;
return returnHTMLResponse(responseContent, 201) as Response;
}

const responseContent = await VideoResponse(videoInfo);
return returnHTMLResponse(responseContent) as Response;
} catch(e) {
const responseContent = await ErrorResponse((e as Error).message);
return returnHTMLResponse(responseContent) as Response;
return returnHTMLResponse(responseContent, 201) as Response;
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ const routes = [
handler: handleVideo
},
{
path: '/:username/video/:videoId',
path: '/*/video/:videoId',
handler: handleVideo
},
{
Expand Down

0 comments on commit 23f1afc

Please sign in to comment.