-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
161 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,50 @@ | ||
export const DONATE_URL = 'https://www.donationalerts.com/r/hmbanan666' | ||
export const DISCORD_SERVER_INVITE_URL = 'https://discord.gg/B6etUajrGZ' | ||
export const TWITCH_URL = 'https://www.twitch.tv/hmbanan666' | ||
export const GITHUB_REPO_URL = 'https://github.com/hmbanan666/chat-game' | ||
|
||
export const TWITCH_CHANNEL_REWARDS = { | ||
add150ViewerPointsId: 'd8237822-c943-434f-9d7e-87a9f549f4c4', | ||
villainStealFuelId: 'd5956de4-54ff-49e4-afbe-ee4e62718eee', | ||
addNewIdea: '289457e8-18c2-4b68-8564-fc61dd60b2a2', | ||
} | ||
|
||
export const ADMIN_PLAYER_ID = 'svhjz9p5467wne9ybasf1bwy' | ||
import { z } from 'zod' | ||
import { env as publicEnv } from '$env/dynamic/public' | ||
|
||
/** | ||
* Здесь объявляется схема конфигурации приложения. | ||
* Содержит только публичные переменные окружения. | ||
* | ||
* Приватные переменные окружения хранятся в '$env/dynamic/private' | ||
* По политике безопасности они не должны быть доступны на клиенте. | ||
* И каждое использование приватной переменной окружения должно в ручном режиме. | ||
*/ | ||
|
||
const allEnv = z.object({ | ||
PUBLIC_COOKIE_KEY: z.string().default(''), | ||
PUBLIC_SIGNIN_REDIRECT_URL: z.string().default(''), | ||
PUBLIC_WEBSOCKET_URL: z.string().default(''), | ||
PUBLIC_DONATE_URL: z.string().default('https://www.donationalerts.com/r/hmbanan666'), | ||
PUBLIC_GITHUB_REPO_URL: z.string().default('https://github.com/hmbanan666/chat-game'), | ||
PUBLIC_DISCORD_SERVER_INVITE_URL: z.string().default('https://discord.gg/B6etUajrGZ'), | ||
PUBLIC_GAME_ADMIN_PLAYER_ID: z.string().default('svhjz9p5467wne9ybasf1bwy'), | ||
PUBLIC_TWITCH_CLIENT_ID: z.string().default(''), | ||
PUBLIC_TWITCH_URL: z.string().default('https://www.twitch.tv/hmbanan666'), | ||
PUBLIC_TWITCH_CHANNEL_REWARDS: z.string().default(JSON.stringify({ | ||
add150ViewerPointsId: 'd8237822-c943-434f-9d7e-87a9f549f4c4', | ||
villainStealFuelId: 'd5956de4-54ff-49e4-afbe-ee4e62718eee', | ||
addNewIdea: '289457e8-18c2-4b68-8564-fc61dd60b2a2', | ||
})), | ||
}) | ||
|
||
const ConfigSchema = allEnv.transform((value) => { | ||
return { | ||
cookieKey: value.PUBLIC_COOKIE_KEY, | ||
signInRedirectUrl: value.PUBLIC_SIGNIN_REDIRECT_URL, | ||
websocketUrl: value.PUBLIC_WEBSOCKET_URL, | ||
donateUrl: value.PUBLIC_DONATE_URL, | ||
githubRepoUrl: value.PUBLIC_GITHUB_REPO_URL, | ||
discordServerInviteUrl: value.PUBLIC_DISCORD_SERVER_INVITE_URL, | ||
game: { | ||
adminPlayerId: value.PUBLIC_GAME_ADMIN_PLAYER_ID, | ||
}, | ||
twitch: { | ||
clientId: value.PUBLIC_TWITCH_CLIENT_ID, | ||
url: value.PUBLIC_TWITCH_URL, | ||
rewards: JSON.parse(value.PUBLIC_TWITCH_CHANNEL_REWARDS), | ||
}, | ||
} | ||
}) | ||
|
||
export type Config = z.infer<typeof ConfigSchema> | ||
export const config: Config = ConfigSchema.parse(publicEnv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Broker, Registry, Subscriber } from './interface' | ||
|
||
export class BrokerService implements Broker { | ||
private subscribers: Subscriber | ||
private static nextId = 0 | ||
|
||
constructor() { | ||
this.subscribers = {} | ||
} | ||
|
||
public dispatch<T>(event: string, arg?: T): void { | ||
const subscriber = this.subscribers[event] | ||
|
||
if (subscriber === undefined) { | ||
return | ||
} | ||
|
||
Object.keys(subscriber).forEach((key) => subscriber[key](arg)) | ||
} | ||
|
||
public register(event: string, callback: Function): Registry { | ||
const id = this.getNextId() | ||
if (!this.subscribers[event]) { | ||
this.subscribers[event] = {} | ||
} | ||
|
||
this.subscribers[event][id] = callback | ||
|
||
return { | ||
unregister: () => { | ||
delete this.subscribers[event][id] | ||
if (Object.keys(this.subscribers[event]).length === 0) { | ||
delete this.subscribers[event] | ||
} | ||
}, | ||
} | ||
} | ||
|
||
private getNextId(): number { | ||
return BrokerService.nextId++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export interface Registry { | ||
unregister: () => void | ||
} | ||
|
||
export interface Callable { | ||
[key: string]: Function | ||
} | ||
|
||
export interface Subscriber { | ||
[key: string]: Callable | ||
} | ||
|
||
export interface Broker { | ||
dispatch: <T>(event: string, arg?: T) => void | ||
register: (event: string, callback: Function) => Registry | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { ChatGameAPI } from '@hmbanan666/chat-game-api' | ||
import { env } from '$env/dynamic/private' | ||
import { env as privateEnv } from '$env/dynamic/private' | ||
|
||
export const api = new ChatGameAPI(env.PRIVATE_WEBSITE_BEARER ?? '') | ||
export const api = new ChatGameAPI(privateEnv.PRIVATE_WEBSITE_BEARER ?? '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { env } from '$env/dynamic/public' | ||
import { config } from '$lib/config' | ||
|
||
export async function load({ cookies }) { | ||
const cookieKey = env.PUBLIC_COOKIE_KEY ?? '' | ||
|
||
return { | ||
gameProfileJWT: cookies.get(cookieKey), | ||
gameProfileJWT: cookies.get(config.cookieKey), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.