Skip to content

Commit 499f337

Browse files
committed
First version of post (untested)
1 parent bbd6c9f commit 499f337

9 files changed

Lines changed: 548 additions & 157 deletions

File tree

apps/website/app/api/data/[space_id]/route.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
createApiResponse,
77
} from "~/utils/supabase/apiUtils";
88
import { Tables } from "@repo/database/dbTypes";
9+
import { populate } from "~/utils/conversion/fromJsonLd";
10+
import { JsonLdDocument } from "jsonld";
911

1012
type Space = Tables<"Space">;
1113

@@ -133,3 +135,29 @@ export const GET = async (
133135
};
134136

135137
export const OPTIONS = defaultOptionsHandler;
138+
139+
export const POST = async (
140+
request: NextRequest,
141+
segmentData: SegmentDataType,
142+
): Promise<NextResponse> => {
143+
const { space_id } = await segmentData.params;
144+
const spaceIdN = Number.parseInt(space_id || "NaN");
145+
if (isNaN(spaceIdN)) {
146+
return createApiResponse(
147+
request,
148+
asPostgrestFailure(`space_id is not a number`, "type"),
149+
);
150+
}
151+
const supabase = await createClient();
152+
const input: JsonLdDocument = await request.json();
153+
try {
154+
const output = await populate(supabase, input, spaceIdN, request.url);
155+
return NextResponse.json(output, {
156+
status: 200,
157+
});
158+
} catch (error) {
159+
return NextResponse.json((error as Error).message || "Error", {
160+
status: 500,
161+
});
162+
}
163+
};

apps/website/app/utils/conversion/convert.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export const MIMETYPES: Record<DocType, string> = {
99
html: "text/html",
1010
};
1111

12+
export const DOCTYPES: Record<string, DocType> = Object.fromEntries(
13+
Object.entries(MIMETYPES).map(([a, b]) => [b, a as DocType]),
14+
);
15+
1216
const markdownTypes: Set<DocType> = new Set(["obsidian", "markdown"]);
1317

1418
let converter: showdown.Converter | undefined;

0 commit comments

Comments
 (0)