27 lines
679 B
TypeScript
27 lines
679 B
TypeScript
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;
|