Unlock everything, add a donation link, credit Last.fm, nudge re-linking

- Every feature is free for everyone (the plan system stays for later);
  remaining limits are abuse guards
- Optional website donation link (NEXT_PUBLIC_DONATION_URL). Not shown in
  the mobile apps, where tips to the developer generally need in-app
  purchase
- Last.fm/ListenBrainz-sourced plays link to the user's profile, as
  Last.fm's API terms require
- Connections track when they last saw activity; a scrobbler silent for
  over a week prompts re-linking Spotify (its link expires every 6 months)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
This commit is contained in:
2026-10-04 08:13:54 -04:00
co-authored by Claude Opus 5.5
parent 91a78a8ad4
commit 63d618f0e3
33 changed files with 1277 additions and 38 deletions
+1
View File
@@ -8,6 +8,7 @@ function item(username: string, opts: { pinnedAt?: string; isPlaying?: boolean;
isPlaying: opts.isPlaying ?? false,
source: 'spotify',
sourceApp: null,
sourceUrl: null,
progressMs: null,
updatedAt: opts.updatedAt ?? '2026-01-01T00:00:00.000Z',
pinnedAt: opts.pinnedAt ?? null,
+6
View File
@@ -36,6 +36,8 @@ export interface NowPlayingDTO {
source: NowPlayingProvider;
/** The app it's playing in, when a phone reported it (e.g. "Spotify"). */
sourceApp: string | null;
/** Link to the source for attribution, e.g. the user's Last.fm profile (required by Last.fm's terms). */
sourceUrl: string | null;
progressMs: number | null;
updatedAt: string;
}
@@ -79,6 +81,8 @@ export interface ProfileDTO {
nowPlaying: NowPlayingDTO | null;
/** Most recent first, not including the track playing right now. */
recent: RecentPlayDTO[];
/** Profile links for sources whose data appears here (Last.fm requires attribution). */
attribution: Partial<Record<'lastfm' | 'listenbrainz', string>>;
}
export interface ConnectionDTO {
@@ -88,6 +92,8 @@ export interface ConnectionDTO {
status: 'active' | 'error';
lastError: string | null;
lastPolledAt: string | null;
/** Last time this connection saw something playing. */
lastActivityAt: string | null;
/** Secret URL the user can paste into Plex/Jellyfin for instant updates. */
webhookUrl: string | null;
}
+16 -3
View File
@@ -3,7 +3,11 @@ export type Plan = (typeof PLANS)[number];
/**
* Every feature gate lives here so paid tiers can be reshaped without
* hunting through the codebase. Clients read these to show upsells.
* hunting through the codebase.
*
* Currently everything is unlocked for everyone (the app is donation-supported);
* the limits that remain are abuse guards, not upsells. "plus" is kept so paid
* tiers can return without touching the rest of the code.
*/
export interface Entitlements {
/** How often we refresh now-playing while someone is watching you. */
@@ -16,7 +20,16 @@ export interface Entitlements {
profileThemes: boolean;
}
const EVERYTHING: Entitlements = {
// 10s balances freshness against third-party API budgets (Spotify's quota is shared across all users).
activePollSeconds: 10,
maxConnections: 10,
maxPinnedFriends: 20,
fullHistory: true,
profileThemes: true,
};
export const PLAN_ENTITLEMENTS: Record<Plan, Entitlements> = {
free: { activePollSeconds: 15, maxConnections: 3, maxPinnedFriends: 3, fullHistory: false, profileThemes: false },
plus: { activePollSeconds: 5, maxConnections: 10, maxPinnedFriends: 20, fullHistory: true, profileThemes: true },
free: EVERYTHING,
plus: EVERYTHING,
};
+19 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { STREAMING_SERVICES, openUrl, searchUrl } from './services';
import { STREAMING_SERVICES, isQuietScrobbler, openUrl, searchUrl } from './services';
const track = { title: 'Midnight City', artist: 'M83', links: { spotify: 'https://open.spotify.com/track/abc' } };
@@ -22,3 +22,21 @@ describe('searchUrl', () => {
expect(decodeURIComponent(url.href)).toContain('Ünïcode Café & Co');
});
});
describe('isQuietScrobbler', () => {
const now = new Date('2026-10-04T12:00:00Z').getTime();
const conn = (provider: string, daysAgo: number | null) => ({
provider,
status: 'active',
lastActivityAt: daysAgo === null ? null : new Date(now - daysAgo * 86_400_000).toISOString(),
});
it('flags Last.fm/ListenBrainz that went silent for over a week', () => {
expect(isQuietScrobbler(conn('lastfm', 8), now)).toBe(true);
expect(isQuietScrobbler(conn('listenbrainz', 30), now)).toBe(true);
});
it('ignores recent activity, never-active connections, and other providers', () => {
expect(isQuietScrobbler(conn('lastfm', 2), now)).toBe(false);
expect(isQuietScrobbler(conn('lastfm', null), now)).toBe(false);
expect(isQuietScrobbler(conn('spotify', 30), now)).toBe(false);
});
});
+32
View File
@@ -62,3 +62,35 @@ export function openUrl(
if (direct) return { url: direct, exact: true };
return { url: searchUrl(service, track.title, track.artist), exact: false };
}
/** Public profile page for scrobbling services (attribution links). */
export function sourceProfileUrl(provider: string, username: string): string | null {
const u = encodeURIComponent(username);
if (provider === 'lastfm') return `https://www.last.fm/user/${u}`;
if (provider === 'listenbrainz') return `https://listenbrainz.org/user/${u}/`;
return null;
}
/** Where users re-link Spotify on each scrobbling service. */
export const SPOTIFY_LINK_PAGES = {
lastfm: 'https://www.last.fm/settings/applications',
listenbrainz: 'https://listenbrainz.org/settings/music-services/details/',
} as const;
const QUIET_AFTER_MS = 7 * 86_400_000;
/**
* A scrobbler that used to report plays but has gone silent for a week. Usually
* Spotify's link to it expired (Spotify makes users re-approve every 6 months).
*/
export function isQuietScrobbler(
c: { provider: string; status: string; lastActivityAt: string | null },
now = Date.now(),
): c is { provider: 'lastfm' | 'listenbrainz'; status: string; lastActivityAt: string } {
return (
(c.provider === 'lastfm' || c.provider === 'listenbrainz') &&
c.status === 'active' &&
c.lastActivityAt !== null &&
now - new Date(c.lastActivityAt).getTime() > QUIET_AFTER_MS
);
}