Skip to content

Commit 2f46ee6

Browse files
feat: add api route for decoding share urls
1 parent 0e0b0f7 commit 2f46ee6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {decodeMessage} from "@/lib/beanconqueror/proto";
2+
import {type NextRequest, type NextResponse} from "next/server";
3+
4+
type Body = {
5+
url: string
6+
}
7+
8+
interface RequestWithBody extends NextRequest {
9+
json: () => Promise<Body>;
10+
}
11+
12+
/**
13+
* Endpoint for decoding a Beanconqueror share url into a JSON object.
14+
* This endpoint expects a json body with an url property.
15+
* @param req
16+
* @constructor
17+
*/
18+
export async function POST(req: RequestWithBody) {
19+
const body = await req.json();
20+
const url = body.url;
21+
22+
if (url === null) {
23+
return NextResponse.json({"error": "missing url in body"}, {status: 400});
24+
}
25+
26+
const bean = decodeMessage(url);
27+
28+
return NextResponse.json(bean);
29+
}

src/middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default authMiddleware({
55
"/",
66
"/api/users/webhook",
77
"/beanconqueror",
8+
"/beanconqueror/api/decode",
89
"/beanconqueror/create",
910
"/beanconqueror/stats",
1011
"/beanconqueror/shorten",

0 commit comments

Comments
 (0)