Add /api/get-message-answer API

This commit is contained in:
Yang Luo
2023-05-01 23:15:51 +08:00
parent eea2e1d271
commit 2cd6f9df8e
7 changed files with 159 additions and 2 deletions

View File

@ -44,6 +44,16 @@ export function getMessage(owner, name) {
}).then(res => res.json());
}
export function getMessageAnswer(owner, name, onMessage, onError) {
const source = new EventSource(`${Setting.ServerUrl}/api/get-message-answer?id=${owner}/${encodeURIComponent(name)}`);
source.onmessage = function(event) {
onMessage(event.data);
};
source.onerror = function(error) {
onError(error);
};
}
export function updateMessage(owner, name, message) {
const newMessage = Setting.deepCopy(message);
return fetch(`${Setting.ServerUrl}/api/update-message?id=${owner}/${encodeURIComponent(name)}`, {