Skip to content

Commit

Permalink
simplify demo
Browse files Browse the repository at this point in the history
  • Loading branch information
curly210102 committed Nov 6, 2021
1 parent a1eb921 commit 31e7499
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions pages/api/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { resolve, join } from "path";
import { readFileSync } from "fs";

type Data = {
updated: string[];
deleted: string[];
content: string;
};

type Error = {
Expand All @@ -18,25 +17,16 @@ export default function handler(
) {
if (req.method === "GET") {
const { slugs } = req.query;
const slug = typeof slugs === "string" ? slugs : slugs[0];

const data: Data = {
deleted: [],
updated: [],
};

(typeof slugs === "string" ? [slugs] : slugs).forEach((slug: string) => {
const templateDirectory = resolve(process.cwd(), "extensions");
const emailTemplate = readFileSync(
join(templateDirectory, slug, "README.md"),
"utf8"
);
if (!emailTemplate) {
data.deleted.push(slug);
} else {
data.updated.push(emailTemplate);
}
const templateDirectory = resolve(process.cwd(), "extensions");
const emailTemplate = readFileSync(
join(templateDirectory, slug, "README.md"),
"utf8"
);
return res.status(200).json({
content: emailTemplate,
});
return res.status(200).json(data);
} else {
return res.status(404).json({
error: "Not Support Method",
Expand Down

0 comments on commit 31e7499

Please sign in to comment.