Skip to content

Commit 8d7e7cb

Browse files
committed
feat: Suggest source for transcription
enables the related button and onSubmit calls the intenal `/suggestSource` endpoint which then calls the newly introduced `/suggestSource` endpoint in the Review app which is then responsible for all the related logic.
1 parent 41d80e3 commit 8d7e7cb

File tree

6 files changed

+260
-31
lines changed

6 files changed

+260
-31
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NEXT_PUBLIC_VERCEL_ENV = "" # development | staging | production
2+
REVIEW_APP_URL = ""

package-lock.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@bitcoin-dev-project/bdp-ui": "^1.3.0",
15+
"axios": "^1.7.7",
1516
"contentlayer2": "^0.4.6",
1617
"next": "14.2.4",
1718
"next-contentlayer2": "^0.4.6",

src/app/api/suggestSource/route.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { NextResponse } from "next/server";
2+
import axios from "axios";
3+
4+
const REVIEW_APP_URL = process.env.REVIEW_APP_URL;
5+
6+
export async function POST(request: Request) {
7+
try {
8+
const { title, media, targetRepository } = await request.json();
9+
10+
const response = await axios.post(
11+
`${REVIEW_APP_URL}/api/github/suggestSource`,
12+
{
13+
title,
14+
media,
15+
targetRepository,
16+
},
17+
{
18+
headers: {
19+
"Content-Type": "application/json",
20+
},
21+
}
22+
);
23+
24+
return NextResponse.json(response.data);
25+
} catch (error) {
26+
console.error("Error suggesting source:", error);
27+
if (axios.isAxiosError(error)) {
28+
const errorMessage = error.response?.data?.message || error.message;
29+
return NextResponse.json(
30+
{ message: errorMessage },
31+
{ status: error.response?.status || 500 }
32+
);
33+
} else {
34+
return NextResponse.json(
35+
{
36+
message: "An unexpected error occurred while suggesting the source",
37+
},
38+
{ status: 500 }
39+
);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)