mirror of
https://github.com/zhigang1992/notion-api-worker.git
synced 2026-01-12 22:49:17 +08:00
feat: sanitize page ids for search
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user