Skip to content

Commit

Permalink
Update API code for vc-repository
Browse files Browse the repository at this point in the history
  • Loading branch information
waltkb committed Feb 13, 2024
1 parent ab2033b commit 5a0c535
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
22 changes: 1 addition & 21 deletions src/server/api/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,5 @@ import { serverQueryContent } from "#content/server";

export default defineEventHandler(async (event) => {
const contentQuery = await serverQueryContent(event).find();

return contentQuery
.filter(
(page) =>
page.body.children.find((elem) => {
{
return elem.tag === "pre" && elem.props?.language === "json";
}
}) != undefined
)
.map((elem) => elem.title);

//.map()
//.filter((elem) => {return elem.tag === "pre" && elem.props?.language === "json"})

//return //JSON.parse(
/*
.filter((elem) => {return elem.tag === "pre" && elem.props?.language === "json"})
.map((elem) => {return elem?.props?.code})
.filter((elem) => { return elem != null })*/
//)
return contentQuery.filter((page) => page._path?.startsWith("/credentials/") && page.body?.children.find((elem) => elem.tag === "pre" && elem.props?.language === "json") != undefined).map((elem) => elem.title);
});
11 changes: 8 additions & 3 deletions src/server/api/mapping/[name].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineEventHandler(async (event) => {
const contentQuery = await serverQueryContent(event).find();

const matchedContent = contentQuery.find((content) => {
return content.title === name;
return content._path?.startsWith("/credentials/") && content.title === name;
});

if (matchedContent === undefined) {
Expand All @@ -26,12 +26,17 @@ export default defineEventHandler(async (event) => {
return `error: No credential found named: \"${name}\". Available credentials: ${n.join(", ")}`;
}

console.log("MATCHED: ", matchedContent.body.children);
console.log("MATCHED: ", matchedContent.body?.children);

const codeblocksAndTitles = matchedContent.body.children.filter((elem) => {
const codeblocksAndTitles = matchedContent.body?.children.filter((elem) => {
return (elem.tag === "pre" && elem.props?.language === "json") || elem.tag === "h2";
});

if (!codeblocksAndTitles) {
setResponseStatus(event, 400);
return "error: no-credential";
}

let mappingInTitle = false;
for (const codeblockOrTitle of codeblocksAndTitles) {
console.log("ITERATING: ", codeblockOrTitle);
Expand Down
4 changes: 2 additions & 2 deletions src/server/api/vc/[name].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineEventHandler(async (event) => {
const contentQuery = await serverQueryContent(event).find();

const matchedContent = contentQuery.find((content) => {
return content.title === name;
return content._path?.startsWith("/credentials/") && content.title === name;
});

if (matchedContent === undefined) {
Expand All @@ -26,7 +26,7 @@ export default defineEventHandler(async (event) => {
return `error: No credential found named: \"${name}\". Available credentials: ${n.join(", ")}`;
}

const code = matchedContent.body.children.find((elem) => {
const code = matchedContent.body?.children.find((elem) => {
return elem.tag === "pre" && elem.props?.language === "json";
})?.props?.code;

Expand Down

0 comments on commit 5a0c535

Please sign in to comment.