mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 02:45:39 -04:00
- Overhaul `lib/auth/server.ts` and `lib/auth/session.ts`; update all API routes and server actions to use the revised session pattern - Refactor server actions (settings, titles, watchlist, setup) for consistency with new auth layer - Extract `SetupForm` into its own client component with `useActionState`, animated steps, and copyable env snippets - Move landing page redirect logic into `app/page.tsx`; slim down `LandingPage` component - Add `proxy.ts` for local dev proxying - Minor cleanup to `NavBar`, `MobileTabBar`, and `TitleCard`
86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
"use server";
|
|
|
|
import { eq } from "drizzle-orm";
|
|
import { z } from "zod";
|
|
import { requireSession } from "@/lib/auth/session";
|
|
import { db } from "@/lib/db/client";
|
|
import { episodes } from "@/lib/db/schema";
|
|
import {
|
|
logEpisodeWatch,
|
|
logEpisodeWatchBatch,
|
|
logMovieWatch,
|
|
markAllEpisodesWatched,
|
|
rateTitleStars,
|
|
removeTitleStatus,
|
|
setTitleStatus,
|
|
unwatchEpisode,
|
|
unwatchSeason,
|
|
} from "@/lib/services/tracking";
|
|
|
|
async function getSessionUserId() {
|
|
const session = await requireSession();
|
|
return session.user.id;
|
|
}
|
|
|
|
export async function updateTitleStatus(
|
|
titleId: string,
|
|
status: "in_progress" | null,
|
|
) {
|
|
const userId = await getSessionUserId();
|
|
if (status === null) {
|
|
removeTitleStatus(userId, titleId);
|
|
} else {
|
|
setTitleStatus(userId, titleId, status);
|
|
}
|
|
}
|
|
|
|
export async function markAllWatchedAction(titleId: string) {
|
|
const userId = await getSessionUserId();
|
|
markAllEpisodesWatched(userId, titleId);
|
|
}
|
|
|
|
const ratingSchema = z.number().int().min(0).max(5);
|
|
|
|
export async function updateTitleRating(titleId: string, ratingStars: number) {
|
|
const userId = await getSessionUserId();
|
|
rateTitleStars(userId, titleId, ratingSchema.parse(ratingStars));
|
|
}
|
|
|
|
export async function watchMovie(titleId: string) {
|
|
const userId = await getSessionUserId();
|
|
logMovieWatch(userId, titleId);
|
|
}
|
|
|
|
export async function watchEpisode(episodeId: string) {
|
|
const userId = await getSessionUserId();
|
|
logEpisodeWatch(userId, episodeId);
|
|
}
|
|
|
|
export async function unwatchEpisodeAction(episodeId: string) {
|
|
const userId = await getSessionUserId();
|
|
unwatchEpisode(userId, episodeId);
|
|
}
|
|
|
|
export async function watchSeason(seasonId: string) {
|
|
const userId = await getSessionUserId();
|
|
const seasonEps = db
|
|
.select()
|
|
.from(episodes)
|
|
.where(eq(episodes.seasonId, seasonId))
|
|
.all();
|
|
logEpisodeWatchBatch(
|
|
userId,
|
|
seasonEps.map((ep) => ep.id),
|
|
);
|
|
}
|
|
|
|
export async function unwatchSeasonAction(seasonId: string) {
|
|
const userId = await getSessionUserId();
|
|
unwatchSeason(userId, seasonId);
|
|
}
|
|
|
|
export async function batchWatchEpisodes(episodeIds: string[]) {
|
|
const userId = await getSessionUserId();
|
|
logEpisodeWatchBatch(userId, episodeIds);
|
|
}
|