Files
musicshare/packages/shared/src/dto.ts
T
chrisandClaude Opus 5.5 ece9c4fd64 Add recently played to profiles
A play is recorded when a new track starts (pausing and resuming doesn't
count; returning after 10+ minutes does). Profiles show the last 10,
excluding the track playing now; 50 are kept per user. Recent plays are
free on every plan; the paid flag is renamed to fullHistory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
2026-10-03 16:02:38 -04:00

102 lines
2.6 KiB
TypeScript

import type { Entitlements, Plan } from './plans';
import type { NowPlayingProvider, StreamingService } from './services';
export interface TrackDTO {
id: string;
title: string;
artist: string;
album: string | null;
artworkUrl: string | null;
durationMs: number | null;
isrc: string | null;
links: Partial<Record<StreamingService, string>>;
}
export interface UserSummaryDTO {
id: string;
username: string;
displayName: string | null;
avatarUrl: string | null;
}
export interface MeDTO extends UserSummaryDTO {
email: string;
bio: string | null;
preferredService: StreamingService | null;
plan: Plan;
entitlements: Entitlements;
}
export interface NowPlayingDTO {
user: UserSummaryDTO;
track: TrackDTO;
isPlaying: boolean;
source: NowPlayingProvider;
progressMs: number | null;
updatedAt: string;
}
/** A feed entry. pinnedAt is set when the viewer pinned this friend. */
export interface FeedItemDTO extends NowPlayingDTO {
pinnedAt: string | null;
}
/** Pinned first (oldest pin on top, so order is stable), then live listeners, then most recent. */
export function sortFeed<T extends FeedItemDTO>(items: T[]): T[] {
return [...items].sort(
(a, b) =>
Number(Boolean(b.pinnedAt)) - Number(Boolean(a.pinnedAt)) ||
(a.pinnedAt && b.pinnedAt ? a.pinnedAt.localeCompare(b.pinnedAt) : 0) ||
Number(b.isPlaying) - Number(a.isPlaying) ||
b.updatedAt.localeCompare(a.updatedAt),
);
}
export interface FeaturedSongDTO {
track: TrackDTO;
comment: string | null;
updatedAt: string;
}
export interface RecentPlayDTO {
track: TrackDTO;
source: NowPlayingProvider;
playedAt: string;
}
export interface ProfileDTO {
user: UserSummaryDTO & { bio: string | null };
followerCount: number;
followingCount: number;
isFollowing: boolean;
isPinned: boolean;
isSelf: boolean;
featured: FeaturedSongDTO | null;
nowPlaying: NowPlayingDTO | null;
/** Most recent first, not including the track playing right now. */
recent: RecentPlayDTO[];
}
export interface ConnectionDTO {
provider: NowPlayingProvider;
externalUserId: string;
displayName: string | null;
status: 'active' | 'error';
lastError: string | null;
lastPolledAt: string | null;
/** Secret URL the user can paste into Plex/Jellyfin for instant updates. */
webhookUrl: string | null;
}
export interface TrackSearchResultDTO {
deezerId: string;
title: string;
artist: string;
album: string | null;
artworkUrl: string | null;
durationMs: number | null;
}
/** Messages pushed over the realtime websocket. */
export type RealtimeMessage = { type: 'now_playing'; data: NowPlayingDTO };