Merge branch 'guild-settings' into guild-joining
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
commit
cf32b62ae7
67 changed files with 2621 additions and 255 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse } from "~/types/interfaces";
|
||||
import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse, StatsResponse, UserResponse } from "~/types/interfaces";
|
||||
|
||||
export const useApi = () => {
|
||||
async function fetchGuilds(): Promise<GuildResponse[] | undefined> {
|
||||
|
@ -24,14 +24,26 @@ export const useApi = () => {
|
|||
async function fetchMember(guildId: string, memberId: string): Promise<GuildMemberResponse | undefined> {
|
||||
return await fetchWithApi(`/guilds/${guildId}/members/${memberId}`);
|
||||
}
|
||||
|
||||
|
||||
async function fetchUsers() {
|
||||
return await fetchWithApi(`/users`);
|
||||
}
|
||||
|
||||
|
||||
async function fetchUser(userId: string) {
|
||||
return await fetchWithApi(`/users/${userId}`);
|
||||
}
|
||||
|
||||
async function fetchFriends(): Promise<UserResponse[] | undefined> {
|
||||
return await fetchWithApi('/me/friends')
|
||||
}
|
||||
|
||||
async function addFriend(username: string): Promise<void> {
|
||||
return await fetchWithApi('/me/friends', { method: "POST", body: { username } });
|
||||
}
|
||||
|
||||
async function removeFriend(userId: string): Promise<void> {
|
||||
return await fetchWithApi(`/me/friends/${userId}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
async function fetchMessages(channelId: string, options?: { amount?: number, offset?: number }): Promise<MessageResponse[] | undefined> {
|
||||
return await fetchWithApi(`/channels/${channelId}/messages`, { query: { amount: options?.amount ?? 100, offset: options?.offset ?? 0 } });
|
||||
|
@ -52,6 +64,15 @@ export const useApi = () => {
|
|||
async function createChannel(guildId: string, name: string, description?: string): Promise<void> {
|
||||
return await fetchWithApi(`/guilds/${guildId}/channels`, { method: "POST", body: { name, description } });
|
||||
}
|
||||
|
||||
async function fetchInstanceStats(apiBase: string): Promise<StatsResponse> {
|
||||
return await $fetch(`${apiBase}/stats`, { method: "GET" });
|
||||
}
|
||||
|
||||
async function sendVerificationEmail(): Promise<void> {
|
||||
const email = useAuth().user.value?.email;
|
||||
await fetchWithApi("/auth/verify-email", { method: "POST", body: { email } });
|
||||
}
|
||||
|
||||
return {
|
||||
fetchGuilds,
|
||||
|
@ -62,10 +83,15 @@ export const useApi = () => {
|
|||
fetchMember,
|
||||
fetchUsers,
|
||||
fetchUser,
|
||||
fetchFriends,
|
||||
addFriend,
|
||||
removeFriend,
|
||||
fetchMessages,
|
||||
fetchMessage,
|
||||
createGuild,
|
||||
joinGuild,
|
||||
createChannel
|
||||
createChannel,
|
||||
fetchInstanceStats,
|
||||
sendVerificationEmail
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue