All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m15s
features/files/filesHost.ts: the index and file response types, parseIndex (refuses a malformed index and any entry name that is a path), joinPath, an OpenID token source, and createFilesHost (bearer token, one retry on 401, Range, host error codes passed through uninterpreted). preview-demo/filesHost.ts: sample zones answered in-page under /_files, with the rules the real host must keep (bearer, ranges, no dotfiles, handoff-private never served), and the pretend homeserver's openid/request_token. No UI; config key filesDesk is declared, nothing reads it. Roots, ticket auth and error codes stay placeholders until Eureka answers Q-E1..7 on PR #142. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import { createContext, useContext } from 'react';
|
|
import type { DingsConfig } from '../features/dings/dings';
|
|
import type { BackgroundSceneConfig } from '../features/scene/tier';
|
|
import type { PushConfig } from '../features/push/config';
|
|
|
|
export type HashRouterConfig = {
|
|
enabled?: boolean;
|
|
basename?: string;
|
|
};
|
|
|
|
export type RegistrationConfig = {
|
|
enabled?: boolean;
|
|
url?: string;
|
|
};
|
|
|
|
export type ClientConfig = {
|
|
defaultHomeserver?: number;
|
|
homeserverList?: string[];
|
|
allowCustomHomeservers?: boolean;
|
|
|
|
featuredCommunities?: {
|
|
openAsDefault?: boolean;
|
|
spaces?: string[];
|
|
rooms?: string[];
|
|
servers?: string[];
|
|
};
|
|
|
|
hashRouter?: HashRouterConfig;
|
|
|
|
backgroundScene?: BackgroundSceneConfig;
|
|
|
|
// Per-Mind notification earcons (src/app/features/dings). Off unless `enabled: true`.
|
|
dings?: DingsConfig;
|
|
|
|
// Rooms (ids or aliases) shown as the album view; a room whose create type is org.gamecult.file_zone needs no entry.
|
|
fileZoneRooms?: string[];
|
|
|
|
// Sharing a set of files into a file-zone room as one album. Off unless `enabled` is true.
|
|
fileZoneShare?: { enabled?: boolean };
|
|
|
|
// The Files desk (docs/commons-files-desk.md): a served-directory file zone beside the Matrix one. Off unless
|
|
// `enabled` is true; `host` is the file host's base URL (a value Eureka names, never a path this client invents).
|
|
filesDesk?: { enabled?: boolean; host?: string };
|
|
|
|
// The sign-up entry on the sign-in page. Off unless `enabled` is true; `url` is the account
|
|
// service's own registration page (a value, never a route this client invents).
|
|
registration?: RegistrationConfig;
|
|
|
|
// Web Push to the installed app (src/app/features/push). Off unless all three keys are filled; ships empty.
|
|
push?: PushConfig;
|
|
|
|
// Dev preview only: the build answers a pretend homeserver in-page (src/preview-demo).
|
|
previewDemo?: boolean;
|
|
};
|
|
|
|
const ClientConfigContext = createContext<ClientConfig | null>(null);
|
|
|
|
export const ClientConfigProvider = ClientConfigContext.Provider;
|
|
|
|
export function useClientConfig(): ClientConfig {
|
|
const config = useContext(ClientConfigContext);
|
|
if (!config) throw new Error('Client config are not provided!');
|
|
return config;
|
|
}
|
|
|
|
export const clientDefaultServer = (clientConfig: ClientConfig): string =>
|
|
clientConfig.homeserverList?.[clientConfig.defaultHomeserver ?? 0] ?? 'chat.gamecult.org';
|
|
|
|
export const clientAllowedServer = (clientConfig: ClientConfig, server: string): boolean => {
|
|
const { homeserverList, allowCustomHomeservers } = clientConfig;
|
|
|
|
if (allowCustomHomeservers) return true;
|
|
|
|
return homeserverList?.includes(server) === true;
|
|
};
|