Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import {SessionGuard} from "../../auth/guards/session.guard"
import {GuildAdminGuard} from "../../auth/guards/guild-admin.guard"
import type {GuildRequest} from "../../auth/models/authenticated-request"
import {BadRequestException, Body, Controller, UseGuards, Get, Header, Param, Post, Req, Res} from "@nestjs/common"
import {
BadRequestException,
Body,
Controller,
Delete,
Get,
Header,
Param,
Post,
Req,
Res,
UseGuards
} from "@nestjs/common"
import type {Response} from "express"
import {frontendUrl} from "@streamcat/core"
import {SpotifyConfigRepository, TwitchAuthRepository} from "@streamcat/db"
import type {DashboardConnections} from "@streamcat/interfaces"
import {OAuthFlowService, type AuthFlowOptions} from "../../../features/account-linking/services/oauth-flow.service"
import {SpotifyConnectionService} from "../../../features/account-linking/providers/spotify-connection.service"
import {TwitchConnectionService} from "../../../features/account-linking/providers/twitch-connection.service"
import {SpotifyService} from "../../../integrations/spotify/spotify.service"

@Controller("dashboard/guilds/:guildId/connections")
@UseGuards(SessionGuard, GuildAdminGuard)
Expand All @@ -17,6 +30,7 @@ export class GuildConnectionsController {
private readonly flow: OAuthFlowService,
private readonly spotifyAuth: SpotifyConnectionService,
private readonly twitchAuth: TwitchConnectionService,
private readonly spotify: SpotifyService,
private readonly spotifyRepo: SpotifyConfigRepository,
private readonly twitchRepo: TwitchAuthRepository
) {}
Expand Down Expand Up @@ -50,6 +64,21 @@ export class GuildConnectionsController {
response.redirect(url)
}

@Delete(":provider")
@Header("Cache-Control", "private, no-store")
async disconnect(
@Param("guildId") guildId: string,
@Param("provider") provider: string
): Promise<{success: boolean}> {
if (provider !== "spotify" && provider !== "twitch") throw new BadRequestException("Unbekannter Anbieter.")
if (provider === "spotify") {
await this.spotify.disconnectGuild(guildId)
} else {
await this.twitchAuth.removeGuildAuth(guildId)
}
return {success: true}
}

@Post(":provider")
@Header("Cache-Control", "private, no-store")
async connect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {SessionGuard} from "../../auth/guards/session.guard"
import {GuildAdminGuard} from "../../auth/guards/guild-admin.guard"
import {Body, Controller, UseGuards, Get, Header, Param, Post} from "@nestjs/common"
import {Body, Controller, Delete, UseGuards, Get, Header, Param, Post} from "@nestjs/common"
import {OverlayService} from "../../../features/overlays/services/overlay.service"
import {OverlayPlaybackService} from "../../../features/overlays/services/overlay-playback.service"

Expand Down Expand Up @@ -48,6 +48,13 @@ export class OverlayController {
return this.overlays.renameScene(guildId, overlayId, body)
}

@Delete("scenes/:overlayId")
@Header("Cache-Control", "private, no-store")
async deleteScene(@Param("guildId") guildId: string, @Param("overlayId") overlayId: string) {
await this.overlays.deleteScene(guildId, overlayId)
return {success: true}
}

@Get("preview")
@Header("Cache-Control", "private, no-store")
async preview(@Param("guildId") guildId: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class TwitchConnectionService {
this.events.unsubscribeFromRedemptions(guildId)
const auth = await this.authRepo.findByGuildId(guildId)
await this.authRepo.delete(guildId)
await this.requests.clear(guildId)
if (auth) {
this.logger.info(`Removed guild auth for ${guildId} (user ${auth.userId})`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export class OverlayService {
return this.toDashboard(renamed)
}

async deleteScene(guildId: string, overlayId: string): Promise<void> {
await this.requireScene(guildId, overlayId)
await this.repository.deleteScene(guildId, overlayId)
this.logger.info(`Overlay scene deleted guild=${guildId} overlay=${overlayId}`)
}

async chat(guildId: string): Promise<OverlayChat> {
const auth = await this.twitchAuth.findIdentityByGuildId(guildId)
if (!auth) return {channel: null, url: null}
Expand Down
18 changes: 17 additions & 1 deletion apps/backend/src/features/overlays/settings/overlay-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ function designColors(value: unknown): Record<`--${string}`, string> | undefined
return Object.keys(colors).length ? (colors as Record<`--${string}`, string>) : undefined
}

function themeColors(value: unknown): OverlayLayout["themeColors"] {
if (value === undefined) return undefined
const data = object(value)
const keys = ["primary", "secondary", "surface", "window", "text"] as const
const colors: NonNullable<OverlayLayout["themeColors"]> = {}
for (const key of keys) {
if (data[key] === undefined) continue
colors[key] = color(data[key])
}
return Object.keys(colors).length ? colors : undefined
}

function widgetDesign(value: unknown, fallback: WidgetDesignId): WidgetDesignId {
if (value === undefined) return fallback
if (isWidgetDesignId(value)) return value
Expand Down Expand Up @@ -176,7 +188,10 @@ export function validateOverlayLayout(input: unknown): OverlayLayout {
(typeof params.audioDeviceName !== "string" || params.audioDeviceName.length > 200)
)
throw new BadRequestException("Ungültiger Audioeingang.")
const geometry = {id: widget.id, x, y, width, height, zIndex}
const label =
typeof widget.label === "string" && widget.label.trim() ? widget.label.trim().slice(0, 80) : undefined
const hidden = widget.hidden === true ? true : undefined
const geometry = {id: widget.id, x, y, width, height, zIndex, label, hidden}
const colors = designColors(params.designColors)
const appearance = {
design: widgetDesign(params.design, theme),
Expand Down Expand Up @@ -248,6 +263,7 @@ export function validateOverlayLayout(input: unknown): OverlayLayout {
width: OVERLAY_WIDTH,
height: OVERLAY_HEIGHT,
theme,
themeColors: themeColors(data.themeColors),
scene: scene as OverlayScene,
font: font as OverlayFont,
socials,
Expand Down
7 changes: 7 additions & 0 deletions apps/backend/src/integrations/spotify/spotify.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ export class SpotifyService implements ISpotifyService, OnModuleDestroy {
this.instances.delete(guildId)
}


async disconnectGuild(guildId: string): Promise<void> {
this.removeGuildInstance(guildId)
await this.spotifyConfigRepo.delete(guildId)
this.logger.info(`Spotify connection removed guild=${guildId}`)
}

async onModuleDestroy(): Promise<void> {
this.destroyed = true
for (const [guildId] of this.instances) {
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/tests/connections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {DiscordLoginService} from "../src/api/auth/discord-login.service"
import {OAuthFlowService, type AuthFlowOptions} from "../src/features/account-linking/services/oauth-flow.service"
import {SpotifyConnectionService} from "../src/features/account-linking/providers/spotify-connection.service"
import {TwitchConnectionService} from "../src/features/account-linking/providers/twitch-connection.service"
import {SpotifyService} from "../src/integrations/spotify/spotify.service"

const session = {id: "session-a", userId: "99"}
let captured: AuthFlowOptions | undefined
Expand Down Expand Up @@ -75,6 +76,7 @@ const twitch = {
{provide: DiscordLoginService, useValue: login},
{provide: OAuthFlowService, useValue: flow},
{provide: SpotifyConnectionService, useValue: spotify},
{provide: SpotifyService, useValue: {disconnectGuild: async () => {}}},
{provide: TwitchConnectionService, useValue: twitch},
{
provide: SpotifyConfigRepository,
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/tests/settings-reset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test("removing guild auth still reconciles chat after a guild cascade deleted th
{} as never,
{findByGuildId: async () => null, delete: deleteAuth} as never,
{} as never,
{} as never,
{clear: async () => {}} as never,
{reconcile} as never,
{forModule: () => ({info: mock(() => {})})} as never,
{unsubscribeFromRedemptions} as never,
Expand Down
1 change: 1 addition & 0 deletions apps/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.verify/
36 changes: 30 additions & 6 deletions apps/web/app/(site)/dashboard/[guildId]/overlay/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import {headers} from "next/headers"
import {SiteHeader} from "@/components/layout/site-header"
import {OverlayEditorClient} from "@/components/overlay/editor-client"
import {backendUrl} from "../../../../../lib/backend"

async function guildName(guildId: string): Promise<string | null> {
const cookie = (await headers()).get("cookie")
if (!cookie) return null
try {
const response = await fetch(`${backendUrl}/dashboard/guilds/${encodeURIComponent(guildId)}`, {
headers: {cookie},
cache: "no-store",
signal: AbortSignal.timeout(5000)
})
if (!response.ok) return null
const guild = (await response.json()) as {name?: string}
return guild.name || null
} catch {
return null
}
}

export default async function OverlayPage({params}: {params: Promise<{guildId: string}>}) {
const {guildId} = await params
const name = await guildName(guildId)
return (
<OverlayEditorClient
key={guildId}
basePath={`/dashboard/guilds/${encodeURIComponent(guildId)}/overlay`}
backHref={`/dashboard/${encodeURIComponent(guildId)}`}
loginHref="/api/backend/dashboard/auth/login"
/>
<>
<SiteHeader context={{path: "overlay-editor", label: name ? `Meine Server / ${name}` : "Meine Server"}} />
<OverlayEditorClient
key={guildId}
basePath={`/dashboard/guilds/${encodeURIComponent(guildId)}/overlay`}
backHref={`/dashboard/${encodeURIComponent(guildId)}`}
loginHref="/api/backend/dashboard/auth/login"
/>
</>
)
}
30 changes: 28 additions & 2 deletions apps/web/app/(site)/dashboard/[guildId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
import {Dashboard} from "@/components/dashboard/dashboard"
import {headers} from "next/headers"
import {SiteHeader} from "@/components/layout/site-header"
import {Guild} from "@/components/dashboard/guild"
import {backendUrl} from "../../../../lib/backend"

async function guildName(guildId: string): Promise<string | null> {
const cookie = (await headers()).get("cookie")
if (!cookie) return null
try {
const response = await fetch(`${backendUrl}/dashboard/guilds/${encodeURIComponent(guildId)}`, {
headers: {cookie},
cache: "no-store",
signal: AbortSignal.timeout(5000)
})
if (!response.ok) return null
const guild = (await response.json()) as {name?: string}
return guild.name || null
} catch {
return null
}
}

export default async function GuildPage({params}: {params: Promise<{guildId: string}>}) {
const {guildId} = await params
return <Dashboard key={guildId} guildId={guildId} />
const name = await guildName(guildId)
return (
<>
<SiteHeader context={{path: "dashboard", label: name ? `Meine Server / ${name}` : "Meine Server"}} />
<Guild key={guildId} guildId={guildId} />
</>
)
}
10 changes: 8 additions & 2 deletions apps/web/app/(site)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {Dashboard} from "@/components/dashboard/dashboard"
import {SiteHeader} from "@/components/layout/site-header"
import {Servers} from "@/components/dashboard/servers"

export default function DashboardPage() {
return <Dashboard />
return (
<>
<SiteHeader context={{path: "servers", label: "Meine Server"}} />
<Servers />
</>
)
}
111 changes: 111 additions & 0 deletions apps/web/app/(site)/home.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
.home {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: var(--space-16);
width: 100%;
max-width: 1440px;
margin-inline: auto;
padding: var(--space-12) var(--gutter);
}

.hero {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--space-5);
text-align: center;
}
.hero-logo {
display: flex;
flex-direction: column;
margin: 0;
color: var(--color-ink);
font-size: var(--text-hero);
font-weight: 400;
line-height: 1;
letter-spacing: -0.04em;
}
.hero-logo-cat {
color: var(--color-muted);
}
.hero-tagline {
max-width: 700px;
margin: 0;
color: var(--color-muted);
font-size: var(--text-lg);
line-height: 1.6;
}
.hero-actions {
display: flex;
align-items: center;
gap: var(--space-3);
}
.home-alert {
margin: 0;
max-width: 700px;
color: var(--color-danger);
font-size: var(--text-sm);
line-height: 1.7;
}

.feature-index {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: var(--space-5);
width: 100%;
}
.feature-index-title {
margin: 0;
color: var(--color-ink);
font-size: var(--text-stat);
font-weight: 400;
line-height: 1.2;
}
.feature-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: var(--space-6);
width: 100%;
margin: 0;
padding: 0;
list-style: none;
}
.feature-card {
padding: var(--space-4);
background: var(--color-paper);
border-top: 1px solid var(--color-rule);
}
.feature-card h3 {
margin: 0 0 var(--space-2);
color: var(--color-ink);
font-size: var(--text-title);
font-weight: 400;
line-height: 1.2;
}
.feature-card p {
margin: 0;
color: var(--color-muted);
font-size: var(--text-sm);
line-height: 1.7;
}

@media (max-width: 1100px) {
.feature-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 760px) {
.home {
gap: var(--space-12);
}
.hero-logo {
font-size: var(--text-hero-mobile);
}
.feature-grid {
grid-template-columns: 1fr;
}
}
Loading
Loading