summaryrefslogtreecommitdiff
path: root/ui/lib/apiServer.js
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-11-03 21:47:30 -0500
committerOwen Jacobson <owen@grimoire.ca>2024-11-03 21:47:30 -0500
commit65381f49cc9abce98c1c63c399fdcfc8ce76c3f5 (patch)
treee0b1eea57aa8b431aa83e2efc4577c12d3cc2b29 /ui/lib/apiServer.js
parent30fa0c4c1faece6b054105fe3cce5107f24a2fa2 (diff)
parentf38881f3253b3a128154ffd95655859e3dc629dc (diff)
Merge remote-tracking branch 'origin/wip/actually-configure-prettier'
Diffstat (limited to 'ui/lib/apiServer.js')
-rw-r--r--ui/lib/apiServer.js148
1 files changed, 74 insertions, 74 deletions
diff --git a/ui/lib/apiServer.js b/ui/lib/apiServer.js
index e537abc..a6fdaa6 100644
--- a/ui/lib/apiServer.js
+++ b/ui/lib/apiServer.js
@@ -2,120 +2,120 @@ import axios from 'axios';
import { channelsList, logins, messages } from '$lib/store';
export const apiServer = axios.create({
- baseURL: '/api/',
- validateStatus: () => true
+ baseURL: '/api/',
+ validateStatus: () => true
});
export async function boot() {
- return apiServer.get('/boot');
+ return apiServer.get('/boot');
}
export async function setup(name, password) {
- return apiServer.post('/setup', { name, password });
+ return apiServer.post('/setup', { name, password });
}
export async function logIn(name, password) {
- return apiServer.post('/auth/login', { name, password });
+ return apiServer.post('/auth/login', { name, password });
}
export async function logOut() {
- return apiServer.post('/auth/logout', {});
+ return apiServer.post('/auth/logout', {});
}
export async function changePassword(password, to) {
- return apiServer.post('/password', { password, to });
+ return apiServer.post('/password', { password, to });
}
export async function createChannel(name) {
- return apiServer.post('/channels', { name });
+ return apiServer.post('/channels', { name });
}
export async function postToChannel(channelId, body) {
- return apiServer.post(`/channels/${channelId}`, { body });
+ return apiServer.post(`/channels/${channelId}`, { body });
}
export async function createInvite() {
- return apiServer.post(`/invite`, {});
+ return apiServer.post(`/invite`, {});
}
export async function getInvite(inviteId) {
- return apiServer.get(`/invite/${inviteId}`);
+ return apiServer.get(`/invite/${inviteId}`);
}
export async function acceptInvite(inviteId, username, password) {
- const data = {
- name: username,
- password
- };
- return apiServer.post(`/invite/${inviteId}`, data);
+ const data = {
+ name: username,
+ password
+ };
+ return apiServer.post(`/invite/${inviteId}`, data);
}
export function subscribeToEvents(resume_point) {
- const eventsUrl = new URL('/api/events', window.location);
- eventsUrl.searchParams.append('resume_point', resume_point);
- const evtSource = new EventSource(eventsUrl.toString());
- // TODO: this should process all incoming events and store them.
- // TODO: eventually we'll need to handle expiring old info, so as not to use
- // infinite browser memory.
- /*
- * Known message types as of now:
- * - created: a channel is created.
- * - action: ignore.
- * - message: a message is created.
- * - action: display message in channel.
- * - message_deleted: a message is deleted.
- * - action: replace message with <...>.
- * - deleted: a channel is deleted.
- * - action: remove channel from sidebar.
- */
- evtSource.onmessage = (evt) => {
- const data = JSON.parse(evt.data);
-
- switch (data.type) {
- case 'login':
- onLoginEvent(data);
- break;
- case 'channel':
- onChannelEvent(data);
- break;
- case 'message':
- onMessageEvent(data);
- break;
- }
- };
-
- return evtSource;
+ const eventsUrl = new URL('/api/events', window.location);
+ eventsUrl.searchParams.append('resume_point', resume_point);
+ const evtSource = new EventSource(eventsUrl.toString());
+ // TODO: this should process all incoming events and store them.
+ // TODO: eventually we'll need to handle expiring old info, so as not to use
+ // infinite browser memory.
+ /*
+ * Known message types as of now:
+ * - created: a channel is created.
+ * - action: ignore.
+ * - message: a message is created.
+ * - action: display message in channel.
+ * - message_deleted: a message is deleted.
+ * - action: replace message with <...>.
+ * - deleted: a channel is deleted.
+ * - action: remove channel from sidebar.
+ */
+ evtSource.onmessage = (evt) => {
+ const data = JSON.parse(evt.data);
+
+ switch (data.type) {
+ case 'login':
+ onLoginEvent(data);
+ break;
+ case 'channel':
+ onChannelEvent(data);
+ break;
+ case 'message':
+ onMessageEvent(data);
+ break;
+ }
+ };
+
+ return evtSource;
}
function onLoginEvent(data) {
- switch (data.event) {
- case 'created':
- logins.update((value) => value.addLogin(data.id, data.name));
- break;
- }
+ switch (data.event) {
+ case 'created':
+ logins.update((value) => value.addLogin(data.id, data.name));
+ break;
+ }
}
function onChannelEvent(data) {
- switch (data.event) {
- case 'created':
- channelsList.update((value) => value.addChannel(data.id, data.name));
- break;
- case 'deleted':
- channelsList.update((value) => value.deleteChannel(data.id));
- messages.update((value) => value.deleteChannel(data.id));
- break;
- }
+ switch (data.event) {
+ case 'created':
+ channelsList.update((value) => value.addChannel(data.id, data.name));
+ break;
+ case 'deleted':
+ channelsList.update((value) => value.deleteChannel(data.id));
+ messages.update((value) => value.deleteChannel(data.id));
+ break;
+ }
}
function onMessageEvent(data) {
- switch (data.event) {
- case 'sent':
- messages.update((value) =>
- value.addMessage(data.channel, data.id, data.at, data.sender, data.body)
- );
- break;
- case 'deleted':
- messages.update((value) => value.deleteMessage(data.id));
- break;
- }
+ switch (data.event) {
+ case 'sent':
+ messages.update((value) =>
+ value.addMessage(data.channel, data.id, data.at, data.sender, data.body)
+ );
+ break;
+ case 'deleted':
+ messages.update((value) => value.deleteMessage(data.id));
+ break;
+ }
}