feat: sanitize page ids for search

This commit is contained in:
Travis Fischer
2020-06-22 11:23:35 -04:00
parent dae5184dae
commit 2001b1ceb7
2 changed files with 7 additions and 4 deletions

View File

@@ -7,8 +7,10 @@ export const idToUuid = (path: string) =>
)}-${path.substr(16, 4)}-${path.substr(20)}`;
export const parsePageId = (id: string) => {
const rawId = id.replace(/\-/g, "").slice(-32);
return idToUuid(rawId);
if (id) {
const rawId = id.replace(/\-/g, "").slice(-32);
return idToUuid(rawId);
}
};
export const getNotionValue = (
@@ -20,7 +22,7 @@ export const getNotionValue = (
return getTextContent(val);
case "person":
return (
val.filter(v => v.length > 1).map(v => v[1]![0][1] as string) || []
val.filter((v) => v.length > 1).map((v) => v[1]![0][1] as string) || []
);
case "checkbox":
return val[0][0] === "Yes";

View File

@@ -1,9 +1,10 @@
import { fetchNotionSearch } from "../api/notion";
import { createResponse } from "../response";
import { HandlerRequest } from "../api/types";
import { parsePageId } from "../api/utils";
export async function searchRoute(req: HandlerRequest) {
const ancestorId = req.searchParams.get("ancestorId");
const ancestorId = parsePageId(req.searchParams.get("ancestorId"));
const query = req.searchParams.get("query") || "";
const limit = req.searchParams.get("limit") || 20;