Update background message name
This commit is contained in:
parent
8bf22edbda
commit
46d7d4b26f
|
|
@ -0,0 +1,22 @@
|
||||||
|
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 === "updateBangumiProgress") {
|
||||||
|
const { values } = req.body;
|
||||||
|
|
||||||
|
const updateRequest = await fetch(`${siteUrl}/api/bangumi/update`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
headers: {
|
||||||
|
"paul-token-code": token,
|
||||||
|
},
|
||||||
|
}).then((res) => res.json());
|
||||||
|
|
||||||
|
res.send(updateRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default handler;
|
||||||
|
|
@ -3,7 +3,7 @@ import type { PlasmoMessaging } from "@plasmohq/messaging";
|
||||||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||||
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
||||||
|
|
||||||
if (req.body.action === "submitAddForm") {
|
if (req.body.action === "addRead") {
|
||||||
const { values } = req.body;
|
const { values } = req.body;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||||
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
const { token, siteUrl } = await chrome.storage.local.get(["token", "siteUrl"]);
|
||||||
|
|
||||||
// 添加手办
|
// 添加手办
|
||||||
if (req.body.action === "submitAddForm") {
|
if (req.body.action === "addToy") {
|
||||||
const { values } = req.body;
|
const { values } = req.body;
|
||||||
|
|
||||||
let imageBlob: Blob | undefined;
|
let imageBlob: Blob | undefined;
|
||||||
|
|
@ -33,21 +33,6 @@ const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||||
|
|
||||||
res.send(addReq);
|
res.send(addReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新追番进度
|
|
||||||
if (req.body.action === "updateBangumiProgress") {
|
|
||||||
const { values } = req.body;
|
|
||||||
|
|
||||||
const updateRequest = await fetch(`${siteUrl}/api/bangumi/update`, {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(values),
|
|
||||||
headers: {
|
|
||||||
"paul-token-code": token,
|
|
||||||
},
|
|
||||||
}).then((res) => res.json());
|
|
||||||
|
|
||||||
res.send(updateRequest);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default handler;
|
export default handler;
|
||||||
|
|
@ -28,20 +28,13 @@ const submitForm = (body: FormValue) => {
|
||||||
sendToBackground({
|
sendToBackground({
|
||||||
name: "read",
|
name: "read",
|
||||||
body: {
|
body: {
|
||||||
action: "submitAddForm",
|
action: "addRead",
|
||||||
values: body,
|
values: body,
|
||||||
},
|
},
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res.status === "Success") {
|
add({
|
||||||
add({
|
content: res.msg,
|
||||||
content: "提交成功",
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
add({
|
|
||||||
content: res.msg,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
add({
|
add({
|
||||||
|
|
|
||||||
|
|
@ -42,23 +42,22 @@ function Toy() {
|
||||||
|
|
||||||
const submitForm = (body: FormValue) => {
|
const submitForm = (body: FormValue) => {
|
||||||
sendToBackground({
|
sendToBackground({
|
||||||
name: "bili",
|
name: "toy",
|
||||||
body: {
|
body: {
|
||||||
action: "submitAddForm",
|
action: "addToy",
|
||||||
values: {
|
values: {
|
||||||
...body,
|
...body,
|
||||||
imageUrl: imgs[0],
|
imageUrl: imgs[0],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res.status === "Success") {
|
add({
|
||||||
|
content: res.msg,
|
||||||
|
});
|
||||||
|
}).catch((e) => {
|
||||||
|
if (e instanceof Error) {
|
||||||
add({
|
add({
|
||||||
content: "提交成功",
|
content: e.message,
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
add({
|
|
||||||
content: res.msg,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ const SyncButton = () => {
|
||||||
console.log("Toolbox: 获得追番信息", res.value);
|
console.log("Toolbox: 获得追番信息", res.value);
|
||||||
|
|
||||||
sendToBackground({
|
sendToBackground({
|
||||||
name: "bili",
|
name: "bangumi",
|
||||||
body: {
|
body: {
|
||||||
action: "updateBangumiProgress",
|
action: "updateBangumiProgress",
|
||||||
values: res.value,
|
values: res.value,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue