mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 03:49:11 +00:00
25 lines
780 B
TypeScript
25 lines
780 B
TypeScript
import { Category, CategorySlug } from '@roleypoly/types';
|
|
import { apiPublicURI, interactionsSharedKey } from './config';
|
|
|
|
export const apiFetch = (url: string, init: RequestInit = {}) =>
|
|
fetch(`${apiPublicURI}${url}`, {
|
|
...init,
|
|
headers: {
|
|
...(init.headers || {}),
|
|
authorization: `Shared ${interactionsSharedKey}`,
|
|
},
|
|
});
|
|
|
|
export const getPickableRoles = async (
|
|
guildID: string
|
|
): Promise<Record<Category['name'], CategorySlug>> => {
|
|
const response = await apiFetch(`/interactions-pickable-roles/${guildID}`);
|
|
|
|
if (response.status !== 200) {
|
|
throw new Error(
|
|
`API request failed to /interactions-pickable-roles, got code: ${response.status}`
|
|
);
|
|
}
|
|
|
|
return (await response.json()) as Record<Category['name'], CategorySlug>;
|
|
};
|