Skip to content
Open
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Every Spot+ update. The app shows the newest ones in its “What’s new” screen.

## 2.2.7 — Base tier daily limit, unlocked by support
_2026-11-25_

- Daily limit: on the base tier, Skip, Insta Play, and Insta Choose share 300 uses a day. The count is kept per device and per network address, and either one running out is enough.
- After the limit is reached, the song already playing can finish and the queue can still advance. Skip, Insta Play, Insta Choose, seeking, new downloads, repeat, Canvas, and early loading of the next song stay off until the next day.
- Unlock: star coye2/spot-plus on GitHub and verify the star, join the Discord and verify membership, or refer a friend who installs Spot+ and enters your code. Another browser, phone, or VPN on the same device does not count as that friend.
- Your own devices are excluded from the limit, including devices linked with the same library sync key. They do not spend the allowance.
- Star verification reads GitHub’s public stars page, so a busy API limit no longer stops the check.

## 2.2.6 — Vehicle integration architecture: Spot+ Drive bridge, OpenSubsonic gateway PoC & Native Microbridge
_2026-11-25_

Expand Down
610 changes: 610 additions & 0 deletions canvas-bridge/access.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions canvas-bridge/installs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Live counters for Spot+: total installs (one per device, stored for good) and people listening
// right now (players check in while music plays; kept in memory, counted over the last ~3 minutes).
import { handleAccess } from './access.js';
const LIVE_WINDOW = 540_000; // listeners check in every 4 minutes
export class InstallCounter {
constructor(state) { this.state = state; this.live = new Map(); this.ipDay = new Map(); }
liveCount(now = Date.now()) { for (const [id, at] of this.live) if (now - at > LIVE_WINDOW) this.live.delete(id); return this.live.size; }
async fetch(request) {
const url = new URL(request.url), now = Date.now();
if (url.pathname === '/access' || url.pathname.startsWith('/access/')) {
return handleAccess(request, { storage: this.state.storage, fetcher: this.fetcher || fetch, now: this.now || now });
}
const installs = async () => (await this.state.storage.get('installs')) || 0;
if (request.method === 'POST') {
const body = await request.json().catch(() => ({}));
Expand Down
156 changes: 156 additions & 0 deletions canvas-bridge/referral.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Friend-install unlock. The code is created by one device and redeemed by a
// later, different install. The 60s hold is a real open app, not a single request.
import { DISCORD } from '../js/access-policy.js';
import { isOwnerProof } from '../js/maintenance.js';
import {
CODE_ALPHABET, HOLD_MS, browserKey, hardwareKey, isGuildMember, judgeReferral, normalizeCode, platformFamily, screenBucket,
} from '../js/referral.js';

const HEADERS = {
'Content-Type': 'application/json; charset=utf-8',
'Cache-Control': 'no-store',
'X-Content-Type-Options': 'nosniff',
};
const json = (data, status = 200) => new Response(JSON.stringify(data), { status, headers: HEADERS });

function validDevice(id) {
return /^[a-f0-9]{32}$/.test(String(id || ''));
}

function newCode() {
const bytes = new Uint8Array(8);
crypto.getRandomValues(bytes);
return [...bytes].map((b) => CODE_ALPHABET[b % CODE_ALPHABET.length]).join('');
}

function hexId(size = 8) {
const bytes = new Uint8Array(size);
crypto.getRandomValues(bytes);
return [...bytes].map((b) => b.toString(16).padStart(2, '0')).join('');
}

function readSignals(body) {
const signals = body?.signals && typeof body.signals === 'object' ? body.signals : {};
return {
ua: String(signals.ua || '').slice(0, 180),
platform: String(signals.platform || '').slice(0, 40),
timezone: String(signals.timezone || '').slice(0, 64),
language: String(signals.language || '').slice(0, 20),
cores: Number(signals.cores) || 0,
memory: Number(signals.memory) || 0,
touch: Number(signals.touch) || 0,
width: Number(signals.width) || 0,
height: Number(signals.height) || 0,
dpr: Number(signals.dpr) || 1,
color: Number(signals.color) || 0,
};
}

async function profileOf(body, ipHash, hash) {
const signals = readSignals(body);
const mark = String(body?.mark || '');
return {
device: String(body?.device || ''),
mark: /^[a-f0-9]{32}$/.test(mark) ? await hash(mark) : '',
hardware: await hash(hardwareKey(signals)),
browser: await hash(browserKey(signals)),
family: platformFamily(signals.ua, signals.platform),
screen: screenBucket(signals.width, signals.height, signals.dpr),
ip: ipHash || '',
};
}

export async function handleReferral(request, ctx) {
if (request.method !== 'POST') return json({ error: 'Use POST' }, 405);
const body = await request.json().catch(() => ({}));
const device = String(body.device || '');
if (!validDevice(device)) return json({ ok: false, reason: 'invalid' }, 400);
const url = new URL(request.url);
if (url.pathname === '/access/refer/code') return createCode(body, device, ctx);
if (url.pathname === '/access/refer/redeem') return redeemCode(body, device, ctx);
return json({ error: 'Not found' }, 404);
}

async function createCode(body, device, { storage, now, ipHash, hash }) {
const day = new Date(now).toISOString().slice(0, 10);
const tallyKey = `refday:${day}:${device}`;
const tally = Number(await storage.get(tallyKey)) || 0;
if (tally >= 5) return json({ ok: false, reason: 'rate-limited' }, 429);
const profile = await profileOf(body, ipHash, hash);
let code = '';
for (let i = 0; i < 5 && !code; i++) {
const next = newCode();
if (!(await storage.get('ref:' + next))) code = next;
}
if (!code) return json({ ok: false, reason: 'unavailable' }, 503);
const previous = await storage.get('refby:' + device);
const record = { ...profile, created: now, expires: now + 14 * 86400000, used: false };
const put = { ['ref:' + code]: record, ['refby:' + device]: code, [tallyKey]: tally + 1 };
if (typeof previous === 'string' && previous !== code) put['ref:' + previous] = { used: true, device: '', expires: 0 };
await storage.put(put);
return json({ ok: true, code, expires: record.expires });
}

async function redeemCode(body, device, ctx) {
const { storage, now, ipHash, hash, unlock } = ctx;
const house = /^[a-f0-9]{32}$/.test(ctx.household || '') ? ctx.household : '';
if (await storage.get('own:' + device) || (house && await storage.get('house:' + house)) || isOwnerProof(ctx.ownerProof, { origin: ctx.origin, now })) {
return json({ ok: false, reason: 'excluded' }, 200);
}
const code = normalizeCode(body.code);
if (!code) return json({ ok: false, reason: 'invalid' }, 400);
const record = await storage.get('ref:' + code);
if (!record?.device || record.used) return json({ ok: false, reason: record?.used ? 'taken' : 'invalid' }, 200);
if (record.expires && now > record.expires) return json({ ok: false, reason: 'expired' }, 200);
if (await storage.get('friend:' + device)) return json({ ok: false, reason: 'used' }, 200);
const friend = await profileOf(body, ipHash, hash);
const seenKey = 'seen:' + device;
const firstSeen = Number(await storage.get(seenKey)) || 0;
const verdict = judgeReferral({
referrer: record,
friend,
codeCreatedAt: record.created,
friendFirstSeen: firstSeen,
standalone: body.standalone === true || body.signals?.standalone === true,
});
if (!verdict.ok) return json({ ok: false, reason: verdict.reason });
if (!firstSeen) await storage.put({ [seenKey]: now });

const holdKey = 'hold:' + device;
const hold = await storage.get(holdKey);
const challenge = String(body.challenge || '');
if (!hold || hold.code !== code || hold.hardware !== friend.hardware) {
const challengeId = hexId(8);
await storage.put({ [holdKey]: { code, challenge: challengeId, at: now, hardware: friend.hardware } });
return json({ ok: false, reason: 'hold', waitMs: HOLD_MS, challenge: challengeId });
}
const waitMs = HOLD_MS - (now - hold.at);
if (challenge !== hold.challenge || waitMs > 0) {
return json({ ok: false, reason: 'hold', waitMs: Math.max(0, waitMs), challenge: hold.challenge });
}

const saved = await unlock(record.device, 'friend:' + device, 'a friend');
if (!saved?.ok) return json({ ok: false, reason: saved?.reason || 'unavailable' });
await storage.put({
['ref:' + code]: { ...record, used: true, friend: device, redeemed: now },
['friend:' + device]: code,
});
return json({ ok: true, reason: 'ok', thanked: true });
}

export async function discordGuildId(storage, fetcher, envGuild, signal) {
if (/^\d{5,25}$/.test(String(envGuild || ''))) return String(envGuild);
const cached = await storage.get('discord:guild');
if (/^\d{5,25}$/.test(String(cached || ''))) return String(cached);
const response = await fetcher(`https://discord.com/api/v10/invites/${DISCORD.code}`, {
headers: { Accept: 'application/json', 'User-Agent': 'SpotPlus (https://coye2.github.io/spot-plus/)' },
signal,
});
if (!response.ok) return '';
const data = await response.json();
const id = String(data?.guild?.id || '');
if (/^\d{5,25}$/.test(id)) await storage.put({ 'discord:guild': id });
return id;
}

export { isGuildMember };
4 changes: 3 additions & 1 deletion canvas-bridge/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {youtubeStream} from './youtube-stream.js';
// A narrow public-metadata adapter, never an arbitrary URL or credential proxy.
import {spotifyStats} from './spotify-stats.js';
import {spotifyPublic} from './spotify-public.js';
import {routeAccess} from './access.js';
const SOURCE = 'https://canvas.auramusic.site/api/canvas';
const CORS = {'Access-Control-Allow-Origin':'*','Access-Control-Allow-Methods':'GET, POST, OPTIONS','Content-Type':'application/json; charset=utf-8','X-Content-Type-Options':'nosniff'};
// Lyrics search: Genius's public lyric search, reduced to title, artist and the matching line.
Expand Down Expand Up @@ -85,6 +86,7 @@ const json = (data,status=200,maxAge=0,swr=0) => new Response(JSON.stringify(dat
export async function handle(request, {fetcher=fetch,cache,waitUntil=()=>{},env} = {}) {
if (request.method === 'OPTIONS') return new Response(null,{status:204,headers:CORS});
const url = new URL(request.url);
if (url.pathname === '/access' || url.pathname.startsWith('/access/')) return routeAccess(request, env);
if (['/stats','/installs','/listening','/rate'].includes(url.pathname) && (request.method === 'GET' ? url.pathname === '/stats' : request.method === 'POST' && url.pathname !== '/stats'))
return liveStats(request, env, async text => [...new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode('spotplus:' + text)))].slice(0, 8).map(b => b.toString(16).padStart(2, '0')).join(''));
if (request.method !== 'GET' && !(['/yta','/mono'].includes(url.pathname) && request.method === 'HEAD')) return json({error:'Use GET'},405);
Expand All @@ -99,7 +101,7 @@ export async function handle(request, {fetcher=fetch,cache,waitUntil=()=>{},env}
if (url.pathname === '/mono') return monochromeAudio(request,{fetcher});
if (url.pathname === '/stream') return youtubeStream(request,{fetcher,cache,waitUntil});
if (url.pathname === '/spotify-public') return spotifyPublic(request,{fetcher,cache,waitUntil});
if (url.pathname === '/health') return json({service:'Spot+ Canvas bridge',status:'ok',lyrics:true,spotifyPublic:true,match:true,wallpapers:true,sc:!!(env?.SC_CLIENT_ID&&env?.SC_CLIENT_SECRET),relay:true,relayIntegrity:'v3',mono:true,images:true,stream:true,stats:true,dev:true,podcasts:true}, 200, 30, 60);
if (url.pathname === '/health') return json({service:'Spot+ Canvas bridge',status:'ok',lyrics:true,spotifyPublic:true,match:true,wallpapers:true,sc:!!(env?.SC_CLIENT_ID&&env?.SC_CLIENT_SECRET),relay:true,relayIntegrity:'v3',mono:true,images:true,stream:true,stats:true,dev:true,podcasts:true,access:true}, 200, 30, 60);
if (url.pathname === '/lyrics-search') return lyricsSearch(url,{fetcher,cache,waitUntil});
if (url.pathname !== '/canvas') return json({error:'Not found'},404);
const query = queryFor(url.searchParams);
Expand Down
21 changes: 21 additions & 0 deletions css/polish.css
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,24 @@ html[data-maintenance="1"] .maint-screen{display:flex!important}
.maint-error{margin:8px 0 0;font-size:12px;color:#ff8a8a}
@media (prefers-reduced-motion:reduce){.maint-eq i{animation:none}}

.access-banner{position:fixed;z-index:35;left:12px;right:12px;bottom:calc(var(--nav-h, 64px) + var(--bar-h, 64px) + var(--sb, 0px) + 10px);display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 12px;border-radius:14px;background:var(--bg2);color:var(--text);border:1px solid var(--line);box-shadow:0 10px 30px rgba(0,0,0,.35)}
.access-banner[hidden]{display:none}
.access-banner p{margin:0;font-size:13px;font-weight:650}
.access-dlg{width:min(440px,calc(100vw - 28px));max-height:min(92dvh,760px);overflow:auto}
.access-way{margin:0 0 14px;padding-top:4px}
.access-way h4{margin:0 0 8px;font-size:15px}
.access-way .btn{margin:0 8px 8px 0}
.access-code{margin:0 0 10px;font-size:28px;font-weight:800;letter-spacing:.18em}
.access-hold{margin:0 0 8px;font-size:13px;line-height:1.4}
.access-kicker{margin:0 0 6px;font-size:11px;font-weight:750;letter-spacing:.12em;text-transform:uppercase;color:var(--accent,#1ed760)}
.access-dlg h3{margin:0 0 8px;font-size:22px;letter-spacing:-.03em}
.access-copy,.access-help,.access-fine{margin:0 0 12px;font-size:14px;line-height:1.45;color:var(--muted)}
.access-fine{font-size:12px;margin:12px 0 0}
.access-star{display:flex;justify-content:center;margin:4px 0 12px}
.access-login{display:block;font-size:13px;font-weight:650;margin:0 0 8px}
.access-login input{display:block;width:100%;margin-top:6px;font-weight:500}
.access-error{margin:0 0 8px;font-size:13px;line-height:1.4;color:#ff8a8a}
.access-oauth{width:100%;margin-top:8px}
html[data-access="limited"] [data-act="next"],html[data-access="limited"] [data-act="prev"]{opacity:.45}
@media (min-width:900px){.access-banner{left:50%;right:auto;transform:translateX(-50%);width:min(560px,calc(100vw - 48px));bottom:calc(var(--bar-h, 84px) + 16px)}}

80 changes: 80 additions & 0 deletions js/access-policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Base-tier allowance shared by skips, Insta Play, and Insta Choose.
// The cap is enforced twice: once for the device and once for the network address.
// Full access (a verified GitHub star) is not capped.

export const DAILY_LIMIT = 300;
export const ACTIONS = Object.freeze(['skip', 'insta-play', 'insta-choose']);
export const RESTRICTED_FEATURES = Object.freeze([
'skip', 'insta-play', 'insta-choose', 'seek', 'download', 'repeat', 'canvas', 'preload',
]);
export const REPO = Object.freeze({
owner: 'coye2',
name: 'spot-plus',
full: 'coye2/spot-plus',
url: 'https://github.com/coye2/spot-plus',
});
export const DISCORD = Object.freeze({
code: 'DbhTQD7jW',
invite: 'https://discord.gg/DbhTQD7jW',
});
export const MAX_DEVICES_PER_LOGIN = 3;
export const ACTION_LABELS = Object.freeze({
skip: 'Skip',
'insta-play': 'Insta Play',
'insta-choose': 'Insta Choose',
seek: 'Seeking',
download: 'Downloads',
repeat: 'Repeat',
canvas: 'Canvas',
preload: 'Early loading of the next song',
});

export function utcDay(now = Date.now()) {
return new Date(now).toISOString().slice(0, 10);
}

/** GitHub usernames: 1–39 chars, alphanumeric or hyphen, no leading or trailing hyphen. */
export function normalizeLogin(input) {
const login = String(input || '').trim().replace(/^@+/, '');
if (!/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/.test(login)) return '';
return login;
}

export function quotaView({ deviceUsed = 0, ipUsed = 0, unlocked = false, limit = DAILY_LIMIT } = {}) {
const device = clampCount(deviceUsed, limit);
const ip = clampCount(ipUsed, limit);
const used = Math.max(device, ip);
if (unlocked) {
return { tier: 'full', limited: false, remaining: null, allowed: true, deviceUsed: device, ipUsed: ip, limit, used };
}
const remaining = Math.max(0, limit - used);
const limited = used >= limit;
return { tier: 'base', limited, remaining, allowed: !limited, deviceUsed: device, ipUsed: ip, limit, used };
}

function clampCount(value, limit) {
const n = Math.floor(Number(value) || 0);
if (n < 0) return 0;
return Math.min(limit, n);
}

/**
* Add `n` combined actions to both buckets.
* A request is refused once either bucket is already at the limit, so clearing
* site data (new device id, same network) or switching networks (same device)
* does not mint a fresh allowance.
*/
export function addUsage({ deviceUsed = 0, ipUsed = 0, unlocked = false, limit = DAILY_LIMIT, trackIp = true } = {}, n = 1) {
const before = quotaView({ deviceUsed, ipUsed, unlocked, limit });
const add = Math.floor(Number(n) || 0);
if (unlocked || !before.allowed || add <= 0) return { ...before, charged: 0 };
const amount = Math.min(add, limit);
const nextDevice = Math.min(limit, before.deviceUsed + amount);
const nextIp = trackIp ? Math.min(limit, before.ipUsed + amount) : before.ipUsed;
const changed = nextDevice !== before.deviceUsed || nextIp !== before.ipUsed;
return { ...quotaView({ deviceUsed: nextDevice, ipUsed: nextIp, unlocked: false, limit }), charged: changed ? amount : 0 };
}

export function isKnownAction(action) {
return ACTIONS.includes(action);
}
Loading