Add say form submit & popup entry

This commit is contained in:
2024-04-24 14:17:42 +08:00
parent 46d7d4b26f
commit 6632c839e4
5 changed files with 118 additions and 4 deletions
+26
View File
@@ -0,0 +1,26 @@
import type { PlasmoMessaging } from "@plasmohq/messaging";
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
if (req.body.action === "addSay") {
const { values } = req.body;
const formData = new FormData();
Object.keys(values).forEach((item) => {
formData.append(item, String(values[item]));
});
const addReq = await fetch(`${siteUrl}/api/say/add`, {
method: "POST",
body: formData,
headers: {
"paul-token-code": token,
},
}).then((res) => res.json());
res.send(addReq);
}
}
export default handler;