mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 03:49:11 +00:00
refactor(api): Abstract discord API base url to config.ts
Signed-off-by: Katalina Okano <git@kat.cafe>
This commit is contained in:
parent
31ea2e2183
commit
824fee0703
4 changed files with 14 additions and 6 deletions
|
@ -17,7 +17,13 @@ import {
|
||||||
userAgent,
|
userAgent,
|
||||||
} from '../utils/api-tools';
|
} from '../utils/api-tools';
|
||||||
import { Bounce } from '../utils/bounce';
|
import { Bounce } from '../utils/bounce';
|
||||||
import { apiPublicURI, botClientID, botClientSecret, uiPublicURI } from '../utils/config';
|
import {
|
||||||
|
apiPublicURI,
|
||||||
|
botClientID,
|
||||||
|
botClientSecret,
|
||||||
|
discordAPIBase,
|
||||||
|
uiPublicURI,
|
||||||
|
} from '../utils/config';
|
||||||
import { Sessions } from '../utils/kv';
|
import { Sessions } from '../utils/kv';
|
||||||
|
|
||||||
const AuthErrorResponse = (extra?: string) =>
|
const AuthErrorResponse = (extra?: string) =>
|
||||||
|
@ -72,7 +78,7 @@ export const LoginCallback = resolveFailures(
|
||||||
code,
|
code,
|
||||||
};
|
};
|
||||||
|
|
||||||
const tokenFetch = await fetch('https://discord.com/api/v8/oauth2/token', {
|
const tokenFetch = await fetch(discordAPIBase + '/oauth2/token', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/x-www-form-urlencoded',
|
'content-type': 'application/x-www-form-urlencoded',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { SessionData } from '@roleypoly/types';
|
import { SessionData } from '@roleypoly/types';
|
||||||
import { formData, respond, userAgent, withSession } from '../utils/api-tools';
|
import { formData, respond, userAgent, withSession } from '../utils/api-tools';
|
||||||
import { botClientID, botClientSecret } from '../utils/config';
|
import { botClientID, botClientSecret, discordAPIBase } from '../utils/config';
|
||||||
import { Sessions } from '../utils/kv';
|
import { Sessions } from '../utils/kv';
|
||||||
|
|
||||||
export const RevokeSession = withSession(
|
export const RevokeSession = withSession(
|
||||||
|
@ -11,7 +11,7 @@ export const RevokeSession = withSession(
|
||||||
client_secret: botClientSecret,
|
client_secret: botClientSecret,
|
||||||
};
|
};
|
||||||
|
|
||||||
await fetch('https://discord.com/api/v8/oauth2/token/revoke', {
|
await fetch(discordAPIBase + '/oauth2/token/revoke', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/x-www-form-urlencoded',
|
'content-type': 'application/x-www-form-urlencoded',
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
import { SessionData, UserGuildPermissions } from '@roleypoly/types';
|
import { SessionData, UserGuildPermissions } from '@roleypoly/types';
|
||||||
import KSUID from 'ksuid';
|
import KSUID from 'ksuid';
|
||||||
import { Handler } from '../router';
|
import { Handler } from '../router';
|
||||||
import { allowedCallbackHosts, apiPublicURI, rootUsers } from './config';
|
import { allowedCallbackHosts, apiPublicURI, discordAPIBase, rootUsers } from './config';
|
||||||
import { Sessions, WrappedKVNamespace } from './kv';
|
import { Sessions, WrappedKVNamespace } from './kv';
|
||||||
|
|
||||||
export const formData = (obj: Record<string, any>): string => {
|
export const formData = (obj: Record<string, any>): string => {
|
||||||
|
@ -84,7 +84,7 @@ export const discordFetch = async <T>(
|
||||||
authType: AuthType = AuthType.Bearer,
|
authType: AuthType = AuthType.Bearer,
|
||||||
init?: RequestInit
|
init?: RequestInit
|
||||||
): Promise<T | null> => {
|
): Promise<T | null> => {
|
||||||
const response = await fetch('https://discord.com/api/v8' + url, {
|
const response = await fetch(discordAPIBase + url, {
|
||||||
...(init || {}),
|
...(init || {}),
|
||||||
headers: {
|
headers: {
|
||||||
...(init?.headers || {}),
|
...(init?.headers || {}),
|
||||||
|
|
|
@ -13,3 +13,5 @@ export const apiPublicURI = safeURI(env('API_PUBLIC_URI'));
|
||||||
export const rootUsers = list(env('ROOT_USERS'));
|
export const rootUsers = list(env('ROOT_USERS'));
|
||||||
export const allowedCallbackHosts = list(env('ALLOWED_CALLBACK_HOSTS'));
|
export const allowedCallbackHosts = list(env('ALLOWED_CALLBACK_HOSTS'));
|
||||||
export const importSharedKey = env('BOT_IMPORT_TOKEN');
|
export const importSharedKey = env('BOT_IMPORT_TOKEN');
|
||||||
|
|
||||||
|
export const discordAPIBase = 'https://discordapp.com/api/v9';
|
||||||
|
|
Loading…
Add table
Reference in a new issue