mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 07:37:55 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
84
apps/web-react/app/features/core/streams/streams.server.ts
Normal file
84
apps/web-react/app/features/core/streams/streams.server.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import type { TournamentTierNumber } from "~/features/tournament/core/tiering";
|
||||
import { RunningTournaments } from "~/features/tournament-bracket/core/RunningTournaments.server";
|
||||
import type { Tournament } from "~/features/tournament-bracket/core/Tournament";
|
||||
import { cache } from "~/utils/cache.server";
|
||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import { tournamentStreamsPage } from "~/utils/urls";
|
||||
|
||||
export const COMBINED_STREAMS_KEY = "combined-streams";
|
||||
|
||||
export function clearCombinedStreamsCache() {
|
||||
cache.delete(COMBINED_STREAMS_KEY);
|
||||
}
|
||||
|
||||
export type SidebarStream = {
|
||||
id: string;
|
||||
name: string;
|
||||
imageUrl: string;
|
||||
overlayIconUrl?: string;
|
||||
url: string;
|
||||
subtitle: string;
|
||||
startsAt: number;
|
||||
tier: TournamentTierNumber | null;
|
||||
membersPerTeam?: number;
|
||||
tentativeTier?: number;
|
||||
peakXp?: number;
|
||||
twitchUsername?: string;
|
||||
};
|
||||
|
||||
export function getLiveTournamentStreams(): SidebarStream[] {
|
||||
const streams: SidebarStream[] = [];
|
||||
|
||||
for (const tournament of RunningTournaments.all) {
|
||||
if (tournament.isLeagueDivision) continue;
|
||||
if (tournament.streams.length === 0) continue;
|
||||
|
||||
streams.push({
|
||||
id: `tournament-${tournament.ctx.id}`,
|
||||
name: tournament.ctx.name,
|
||||
imageUrl: tournament.ctx.logoUrl,
|
||||
url: tournamentStreamsPage(tournament.ctx.id),
|
||||
subtitle: deriveCurrentRound(tournament),
|
||||
startsAt: dateToDatabaseTimestamp(tournament.ctx.startsAt),
|
||||
tier: tournament.ctx.tier,
|
||||
membersPerTeam: tournament.minMembersPerTeam,
|
||||
});
|
||||
}
|
||||
|
||||
return streams;
|
||||
}
|
||||
|
||||
/** Lowercased Twitch usernames of all members and casters streaming a currently live tournament. */
|
||||
export function getLiveTournamentStreamerTwitchNames(): string[] {
|
||||
const names: string[] = [];
|
||||
|
||||
for (const tournament of RunningTournaments.all) {
|
||||
if (tournament.isLeagueDivision) continue;
|
||||
|
||||
for (const stream of tournament.streams) {
|
||||
names.push(stream.twitchUserName.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
function deriveCurrentRound(tournament: Tournament): string {
|
||||
for (const bracket of tournament.brackets.toReversed()) {
|
||||
if (bracket.preview) continue;
|
||||
if (bracket.isUnderground) continue;
|
||||
|
||||
for (const match of bracket.data.match) {
|
||||
if (bracket.matchStatus(match.id) !== "STARTED") continue;
|
||||
|
||||
const context = tournament.matchContextNamesById(match.id);
|
||||
if (context?.roundNameWithoutMatchIdentifier) {
|
||||
return context.roundNameWithoutMatchIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
return bracket.name;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
Reference in New Issue
Block a user