File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
app/beanconqueror/api/decode Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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" ,
You can’t perform that action at this time.
0 commit comments