mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 09:39:09 +00:00
fix a bunch of build issues
This commit is contained in:
parent
e35b17e685
commit
558207872d
19 changed files with 283 additions and 69 deletions
|
@ -1,4 +1,5 @@
|
|||
import { Bounce } from '../utils/bounce';
|
||||
import { botClientID } from '../utils/config';
|
||||
|
||||
const validGuildID = /^[0-9]+$/;
|
||||
|
||||
|
@ -27,7 +28,7 @@ export const BotJoin = (request: Request): Response => {
|
|||
|
||||
return Bounce(
|
||||
buildURL({
|
||||
clientID: BOT_CLIENT_ID,
|
||||
clientID: botClientID,
|
||||
permissions: 268435456,
|
||||
guildID,
|
||||
})
|
||||
|
|
|
@ -16,7 +16,7 @@ export const respond = (obj: Record<string, any>, init?: ResponseInit) =>
|
|||
export const resolveFailures = (
|
||||
handleWith: Response,
|
||||
handler: (request: Request) => Promise<Response> | Response
|
||||
) => async (request: Request): Promise<Response> | Response => {
|
||||
) => async (request: Request): Promise<Response> => {
|
||||
try {
|
||||
return handler(request);
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
const self = (global as any) as Record<string, string>;
|
||||
|
||||
const env = (key: string) => self[key] ?? process?.env[key] ?? '';
|
||||
|
||||
const safeURI = (x: string) => x.replace(/\/$/, '');
|
||||
const list = (x: string) => x.split(',');
|
||||
|
||||
export const botClientID = self.BOT_CLIENT_ID;
|
||||
export const botClientSecret = self.BOT_CLIENT_SECRET;
|
||||
export const uiPublicURI = safeURI(self.UI_PUBLIC_URI);
|
||||
export const apiPublicURI = safeURI(self.API_PUBLIC_URI);
|
||||
export const rootUsers = list(self.ROOT_USERS);
|
||||
export const kvPrefix = self.KV_PREFIX;
|
||||
export const botClientID = env('BOT_CLIENT_ID');
|
||||
export const botClientSecret = env('BOT_CLIENT_SECRET');
|
||||
export const uiPublicURI = safeURI(env('UI_PUBLIC_URI'));
|
||||
export const apiPublicURI = safeURI(env('API_PUBLIC_URI'));
|
||||
export const rootUsers = list(env('ROOT_USERS'));
|
||||
export const kvPrefix = env('KV_PREFIX');
|
||||
|
|
|
@ -21,6 +21,70 @@ class WrappedKVNamespace {
|
|||
delete = this.kvNamespace.delete;
|
||||
}
|
||||
|
||||
export const Sessions = new WrappedKVNamespace(KV_SESSIONS);
|
||||
export const GuildData = new WrappedKVNamespace(KV_GUILD_DATA);
|
||||
export const Guilds = new WrappedKVNamespace(KV_GUILDS);
|
||||
class EmulatedKV implements KVNamespace {
|
||||
constructor() {
|
||||
console.warn('EmulatedKV used. Data will be lost.');
|
||||
}
|
||||
|
||||
private data: Map<string, any> = new Map();
|
||||
|
||||
async get<T>(key: string): Promise<T | null> {
|
||||
if (!this.data.has(key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.data.get(key);
|
||||
}
|
||||
|
||||
async getWithMetadata<T, Metadata = unknown>(
|
||||
key: string
|
||||
): KVValueWithMetadata<T, Metadata> {
|
||||
return {
|
||||
value: await this.get<T>(key),
|
||||
metadata: {} as Metadata,
|
||||
};
|
||||
}
|
||||
|
||||
async put(key: string, value: string | ReadableStream<any> | ArrayBuffer | FormData) {
|
||||
this.data.set(key, value);
|
||||
}
|
||||
|
||||
async delete(key: string) {
|
||||
this.data.delete(key);
|
||||
}
|
||||
|
||||
async list(options?: {
|
||||
prefix?: string;
|
||||
limit?: number;
|
||||
cursor?: string;
|
||||
}): Promise<{
|
||||
keys: { name: string; expiration?: number; metadata?: unknown }[];
|
||||
list_complete: boolean;
|
||||
cursor: string;
|
||||
}> {
|
||||
let keys: { name: string }[] = [];
|
||||
|
||||
for (let key of this.data.keys()) {
|
||||
if (options?.prefix && !key.startsWith(options.prefix)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
keys.push({ name: key });
|
||||
}
|
||||
|
||||
return {
|
||||
keys,
|
||||
cursor: '0',
|
||||
list_complete: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const kvOrLocal = (namespace: KVNamespace | null): KVNamespace =>
|
||||
namespace || new EmulatedKV();
|
||||
|
||||
const self = (global as any) as Record<string, any>;
|
||||
|
||||
export const Sessions = new WrappedKVNamespace(kvOrLocal(self.KV_SESSIONS ?? null));
|
||||
export const GuildData = new WrappedKVNamespace(kvOrLocal(self.KV_GUILD_DATA ?? null));
|
||||
export const Guilds = new WrappedKVNamespace(kvOrLocal(self.KV_GUILDS ?? null));
|
||||
|
|
|
@ -98,6 +98,8 @@ export const EditorCategory = (props: Props) => {
|
|||
<Space />
|
||||
<Text>Roles</Text>
|
||||
<Popover
|
||||
position={'top left'}
|
||||
headContent={null}
|
||||
active={roleSearchPopoverActive}
|
||||
onExit={() => setRoleSearchPopoverActive(false)}
|
||||
>
|
||||
|
|
|
@ -9,7 +9,7 @@ type Props = {
|
|||
};
|
||||
|
||||
export const EditorShell = (props: Props) => (
|
||||
<TabView selected={0}>
|
||||
<TabView initialTab={0}>
|
||||
<Tab title="Roles">{() => <RolesTab {...props} />}</Tab>
|
||||
<Tab title="Server Details">{() => <div>hi2!</div>}</Tab>
|
||||
</TabView>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as React from 'react';
|
||||
import { DiscordUser } from 'roleypoly/common/types';
|
||||
import { DotOverlay } from 'roleypoly/design-system/atoms/dot-overlay';
|
||||
import { Hero } from 'roleypoly/design-system/atoms/hero';
|
||||
import {
|
||||
|
@ -6,20 +7,19 @@ import {
|
|||
ErrorMessage,
|
||||
} from 'roleypoly/design-system/molecules/error-banner';
|
||||
import { AppShell } from 'roleypoly/design-system/organisms/app-shell';
|
||||
import { RoleypolyUser } from 'roleypoly/common/types';
|
||||
import { getMessageFromCode } from './errorStrings';
|
||||
|
||||
export type ErrorProps = {
|
||||
code: string | number;
|
||||
messageOverride?: ErrorMessage;
|
||||
user?: RoleypolyUser | null;
|
||||
user?: DiscordUser | null;
|
||||
};
|
||||
|
||||
export const Error = (props: ErrorProps) => {
|
||||
const messageFromCode = getMessageFromCode(props.code);
|
||||
|
||||
return (
|
||||
<AppShell user={props.user || null}>
|
||||
<AppShell user={props.user || undefined}>
|
||||
<DotOverlay />
|
||||
<Hero topSpacing={100} bottomSpacing={25}>
|
||||
<ErrorBanner message={messageFromCode} />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue