cea-core
Version:
basic cea api
35 lines (34 loc) • 1.22 kB
JavaScript
import sstore from "@beetcb/sstore";
import fetch from "node-fetch";
const pushEndpoints = ["http://pushplus.hxtrip.com/send"];
const notifications = [];
const saveNotifications = (args) => {
var _a, _b;
const message = args[0];
const [log, at] = [(_a = message == null ? void 0 : message.message) != null ? _a : message, (_b = message == null ? void 0 : message.suffix) != null ? _b : ""];
notifications.push(`${log} ${at != null ? at : ""}`);
};
const notify = async function(addtionalMessage) {
const notifyConf = sstore.get("notifier");
if (!(notifyConf == null ? void 0 : notifyConf.length)) {
return;
}
const [pushPlatform, pushToken] = notifyConf;
const content = `${notifications.join(`<br>`)}<br>${addtionalMessage.replace(/\n/g, "<br>").replace(/\s/g, " ")}`;
const url = pushEndpoints[Number(pushPlatform)];
if (pushToken && url) {
await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
content,
token: pushToken,
title: "Cea.js \u6D88\u606F\u63A8\u9001\u670D\u52A1"
})
});
}
};
export { notify, saveNotifications };
//# sourceMappingURL=notifier.js.map