Skip to content

Commit

Permalink
post
Browse files Browse the repository at this point in the history
  • Loading branch information
curly210102 committed Nov 5, 2021
1 parent cf113d5 commit e9484b8
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions pages/api/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,30 @@ export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data | Error>
) {
const { slugs } = req.query;
if (req.method === "POST") {
const { slugs } = req.body;

const data: Data = {
deleted: [],
updated: [],
};
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, "index.md"),
"utf8"
);
if (!emailTemplate) {
data.deleted.push(slug);
} else {
data.updated.push(emailTemplate);
}
});
return res.status(200).json(data);
(typeof slugs === "string" ? [slugs] : slugs).forEach((slug: string) => {
const templateDirectory = resolve(process.cwd(), "extensions");
const emailTemplate = readFileSync(
join(templateDirectory, slug, "index.md"),
"utf8"
);
if (!emailTemplate) {
data.deleted.push(slug);
} else {
data.updated.push(emailTemplate);
}
});
return res.status(200).json(data);
} else {
return res.status(404).json({
error: "Not Support Method",
});
}
}

0 comments on commit e9484b8

Please sign in to comment.