Skip to content

Commit dd7de08

Browse files
committed
Expose public content
1 parent 2a9684f commit dd7de08

3 files changed

Lines changed: 35 additions & 29 deletions

File tree

apps/website/app/api/content/[space_id]/[resource_id]/route.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
createApiResponse,
77
} from "~/utils/supabase/apiUtils";
88
import { asJsonLD } from "~/utils/conversion/jsonld";
9-
import { Tables } from "@repo/database/dbTypes";
9+
import { Tables, Enums } from "@repo/database/dbTypes";
1010
import { convert, MIMETYPES, type DocType } from "~/utils/conversion/convert";
1111

1212
type Concept = Tables<"Concept">;
1313
type Content = Tables<"Content">;
14-
type Space = Tables<"Space">;
1514
type PlatformAccount = Tables<"PlatformAccount">;
15+
type Platform = Enums<"Platform">;
1616

1717
export type SegmentDataType = { params: Promise<Record<string, string>> };
1818

@@ -59,15 +59,18 @@ export const GET = async (
5959
if (spaceResponse.error) {
6060
return createApiResponse(request, spaceResponse);
6161
}
62-
if (!spaceResponse.data) {
62+
let platform: Platform = "Obsidian";
63+
if (spaceResponse.data) {
64+
platform = spaceResponse.data.platform;
65+
} else {
6366
// consideration: We may not see it because we don't have access,
64-
// so it would be worth re-fetching as superuser to see if I should redirect to login.
65-
return createApiResponse(
66-
request,
67-
asPostgrestFailure("Space not found", "401", 401),
68-
);
67+
// We should find a way to check its platform otherwise.
68+
// Let's just keep the Obsidian guess for MIRA demo.
69+
// return createApiResponse(
70+
// request,
71+
// asPostgrestFailure("Space not found", "401", 401),
72+
// );
6973
}
70-
const space: Space = spaceResponse.data;
7174
const conceptResponse = await supabase
7275
.from("Concept")
7376
.select()
@@ -112,9 +115,9 @@ export const GET = async (
112115

113116
// await initRT(rootUrl);
114117
const source: DocType | undefined =
115-
space.platform === "Obsidian"
118+
platform === "Obsidian"
116119
? "obsidian"
117-
: space.platform === "Roam"
120+
: platform === "Roam"
118121
? "roam"
119122
: undefined;
120123
let text =
@@ -154,7 +157,7 @@ export const GET = async (
154157
}
155158

156159
const jsonLdData = asJsonLD({
157-
space,
160+
platform,
158161
concept,
159162
baseUrl,
160163
title,

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {
66
createApiResponse,
77
} from "~/utils/supabase/apiUtils";
88
import { asJsonLD, wrapJsonLd } from "~/utils/conversion/jsonld";
9-
import { Tables } from "@repo/database/dbTypes";
9+
import type { Tables, Enums } from "@repo/database/dbTypes";
1010
import { PostgrestMaybeSingleResponse } from "@supabase/supabase-js";
1111
import { MIMETYPES, type DocType } from "~/utils/conversion/convert";
1212

1313
type Concept = Tables<"Concept">;
1414
type Content = Tables<"Content">;
15-
type Space = Tables<"Space">;
1615
type PlatformAccount = Tables<"PlatformAccount">;
16+
type Platform = Enums<"Platform">;
1717

1818
export type SegmentDataType = { params: Promise<Record<string, string>> };
1919

@@ -53,15 +53,18 @@ export const GET = async (
5353
if (spaceResponse.error) {
5454
return createApiResponse(request, spaceResponse);
5555
}
56-
if (!spaceResponse.data) {
56+
let platform: Platform = "Obsidian";
57+
if (spaceResponse.data) {
58+
platform = spaceResponse.data.platform;
59+
} else {
5760
// consideration: We may not see it because we don't have access,
58-
// so it would be worth re-fetching as superuser to see if I should redirect to login.
59-
return createApiResponse(
60-
request,
61-
asPostgrestFailure("Space not found", "401", 401),
62-
);
61+
// We should find a way to check its platform otherwise.
62+
// Let's just keep the Obsidian guess for MIRA demo.
63+
// return createApiResponse(
64+
// request,
65+
// asPostgrestFailure("Space not found", "401", 401),
66+
// );
6367
}
64-
const space: Space = spaceResponse.data;
6568
const conceptResponse = await supabase
6669
.from("Concept")
6770
.select()
@@ -161,7 +164,7 @@ export const GET = async (
161164
const relationsJLD = withContext
162165
? relations.map((c) =>
163166
asJsonLD({
164-
space,
167+
platform,
165168
concept: c,
166169
baseUrl,
167170
schema: c.schema_id ? schemas[c.schema_id] : undefined,
@@ -172,7 +175,7 @@ export const GET = async (
172175
const schemasJLD = withSchema
173176
? Object.values(schemas).map((c) =>
174177
asJsonLD({
175-
space,
178+
platform,
176179
concept: c,
177180
baseUrl,
178181
author: c.author_id ? authors[c.author_id] : undefined,
@@ -181,7 +184,7 @@ export const GET = async (
181184
: [];
182185

183186
const baseJLDData = asJsonLD({
184-
space,
187+
platform,
185188
concept,
186189
baseUrl,
187190
title,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Tables, Json } from "@repo/database/dbTypes";
1+
import type { Tables, Enums, Json } from "@repo/database/dbTypes";
22
import { convert, MIMETYPES, type DocType } from "~/utils/conversion/convert";
33

44
type Concept = Tables<"Concept">;
55
type Content = Tables<"Content">;
6-
type Space = Tables<"Space">;
76
type PlatformAccount = Tables<"PlatformAccount">;
7+
type Platform = Enums<"Platform">;
88

99
// This is a temporary hack
1010
export const KnownClassEntities: Record<string, string[]> = {
@@ -69,7 +69,7 @@ export const KnownSchemaCuries = Object.values(KnownSchemaEntities).flat();
6969
export const KnownSchemaIris = new Set(KnownSchemaCuries.map(curieToIri));
7070

7171
export const asJsonLD = ({
72-
space,
72+
platform,
7373
concept,
7474
baseUrl,
7575
title,
@@ -79,7 +79,7 @@ export const asJsonLD = ({
7979
targetFormat,
8080
wrap,
8181
}: {
82-
space: Space;
82+
platform: Platform;
8383
concept: Concept;
8484
baseUrl: string;
8585
title?: Content;
@@ -160,7 +160,7 @@ export const asJsonLD = ({
160160
const rootUrl = baseUrl.split("/").slice(0, 3).join("/");
161161
pageUrl = `${rootUrl}/api/content/${baseUrl.split("/")[5]}/${concept.id}#`;
162162
const source: DocType | undefined =
163-
space.platform === "Obsidian" ? "obsidian" : "markdown";
163+
platform === "Obsidian" ? "obsidian" : "markdown";
164164
// punt roam-json
165165
const contentText = source && convert(content.text, source, targetFormat);
166166
extraData["description"] = {

0 commit comments

Comments
 (0)