nixamp 0.58.1 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-label.d.ts +6 -0
- package/dist/ai-label.js +1 -0
- package/dist/follow-page.js +1 -1
- package/dist/label-routes.js +3 -1
- package/dist/music-hub.d.ts +97 -0
- package/dist/music-hub.js +215 -0
- package/dist/music-store.d.ts +2 -0
- package/dist/music-store.js +4 -2
- package/dist/server.d.ts +9 -0
- package/dist/server.js +92 -6
- package/dist/store-routes.js +5 -4
- package/package.json +1 -1
- package/src/ai-label.ts +3 -0
- package/src/follow-page.ts +1 -1
- package/src/label-routes.ts +3 -1
- package/src/music-hub.ts +210 -0
- package/src/music-store.ts +6 -2
- package/src/server.ts +85 -6
- package/src/store-routes.ts +5 -4
- package/web/dist/assets/{ar-CBn9fObz.js → ar-BGz59p0i.js} +1 -1
- package/web/dist/assets/chunk-Q2XQMA4B-BaoaSqsD.js +1 -0
- package/web/dist/assets/{cs-BvEScz92.js → cs-DKsmGQfn.js} +1 -1
- package/web/dist/assets/{da-uKElVtgi.js → da-VBBFYTgq.js} +1 -1
- package/web/dist/assets/{de-DXEoI1GG.js → de-DocjfCJV.js} +1 -1
- package/web/dist/assets/{es-Q-QEZFh2.js → es-ScAWdKuT.js} +1 -1
- package/web/dist/assets/{fi-ClJkdfXs.js → fi-BCjOujwG.js} +1 -1
- package/web/dist/assets/{fr-DWmNoP1h.js → fr-EO9zGot_.js} +1 -1
- package/web/dist/assets/{hi-DGQOrveg.js → hi-DOv37S1y.js} +1 -1
- package/web/dist/assets/{hls-OR5FY6YP-CxI-FwpW.js → hls-OR5FY6YP-B-70I17r.js} +1 -1
- package/web/dist/assets/{hu-DGcKM8DB.js → hu-BMxwsXKm.js} +1 -1
- package/web/dist/assets/{id-D18Cz5RW.js → id-DDfdVuoK.js} +1 -1
- package/web/dist/assets/{it-WQxuRjlI.js → it-BbbFjt9-.js} +1 -1
- package/web/dist/assets/{main-cry6C8KD.js → main-BMYkP1N_.js} +2 -2
- package/web/dist/assets/modulepreload-polyfill-P2Xu9kJm.js +1 -0
- package/web/dist/assets/{mpegts-7CN75AI2-D-6xFZI-.js → mpegts-7CN75AI2-D-bdbDNw.js} +1 -1
- package/web/dist/assets/{mpegts-D2ZKeEby.js → mpegts-C_-pZIIG.js} +1 -1
- package/web/dist/assets/music-CmI2KJ1Y.js +1 -0
- package/web/dist/assets/music-jouma3VD.css +1 -0
- package/web/dist/assets/{nl-BvOA9QBr.js → nl-CO-MkYd-.js} +1 -1
- package/web/dist/assets/radio-DmVc3wpH.js +1 -0
- package/web/dist/assets/{ru-Cx4tgP1k.js → ru-C48YQfIR.js} +1 -1
- package/web/dist/assets/{station-BzLUgyQ0.js → station-DtY1LOm5.js} +1 -1
- package/web/dist/assets/{sv-f0zj1AdU.js → sv--HR26-tY.js} +1 -1
- package/web/dist/assets/{uk-DpGYtFFI.js → uk-p55LkwrK.js} +1 -1
- package/web/dist/assets/{vi-Cxf7VqJQ.js → vi-DPS8isVc.js} +1 -1
- package/web/dist/assets/vod-BzQvQVLd.js +1 -0
- package/web/dist/assets/watch-B9LW8D1C.js +1 -0
- package/web/dist/assets/{zh-DyuYbygO.js → zh-Dw9Ji9b2.js} +1 -1
- package/web/dist/index.html +4 -3
- package/web/dist/music.html +43 -0
- package/web/dist/radio.html +3 -2
- package/web/dist/station.html +3 -2
- package/web/dist/sw.js +30 -27
- package/web/dist/vod.html +3 -2
- package/web/dist/watch.html +3 -2
- package/web/dist/assets/chunk-Q2XQMA4B-PTuZPMen.js +0 -1
- package/web/dist/assets/radio-DV3h4YZS.js +0 -1
- package/web/dist/assets/vod-Bbg_gWbl.js +0 -1
- package/web/dist/assets/watch-Bygo4bPY.js +0 -1
package/dist/ai-label.d.ts
CHANGED
|
@@ -209,6 +209,12 @@ export interface AiLabelDeps {
|
|
|
209
209
|
}) => Promise<void>;
|
|
210
210
|
/** A scene's picture for this prompt, or null when nothing can draw one; Workers AI by default. */
|
|
211
211
|
image?: (prompt: string) => Promise<Buffer | null>;
|
|
212
|
+
/** Tells the world an album landed (nixamp.com tells the artist's followers); never awaited. */
|
|
213
|
+
announce?: (release: {
|
|
214
|
+
artist: string;
|
|
215
|
+
title: string;
|
|
216
|
+
kind: "album" | "song";
|
|
217
|
+
}) => void;
|
|
212
218
|
/** The day's pick (artist, genre, new or not); Math.random by default. */
|
|
213
219
|
random?: () => number;
|
|
214
220
|
now?: () => number;
|
package/dist/ai-label.js
CHANGED
|
@@ -1273,6 +1273,7 @@ export class AiLabel {
|
|
|
1273
1273
|
if (album.songs.every((one) => one.file)) {
|
|
1274
1274
|
album.doneAt = this.now();
|
|
1275
1275
|
this.log(`${artist.name} released "${album.title}"`);
|
|
1276
|
+
this.deps.announce?.({ artist: artist.key, title: album.title, kind: "album" });
|
|
1276
1277
|
void this.ensureProfile(artist).catch(() => undefined);
|
|
1277
1278
|
}
|
|
1278
1279
|
this.save();
|
package/dist/follow-page.js
CHANGED
|
@@ -96,7 +96,7 @@ export async function handleFollowPage(request, response, path, url, ctx) {
|
|
|
96
96
|
if (!me) {
|
|
97
97
|
send(response, 200, page(`Follow ${target.name}`, `<h1>Follow ${escape(target.name)}</h1>
|
|
98
98
|
<p class="by">Sign in to nixamp.com to follow the artists you hear on the radio.</p>
|
|
99
|
-
<a class="go" href="/
|
|
99
|
+
<a class="go" href="/music/me">Sign in to nixamp.com</a>
|
|
100
100
|
<small>Signed in, open this page again (or press Follow on the artist's page) to follow.</small>${back}`), method);
|
|
101
101
|
return true;
|
|
102
102
|
}
|
package/dist/label-routes.js
CHANGED
|
@@ -10,6 +10,7 @@ import { createHash } from "node:crypto";
|
|
|
10
10
|
import { createReadStream, statSync } from "node:fs";
|
|
11
11
|
import { ROSTER } from "./ai-label.js";
|
|
12
12
|
import { covers, PRICES } from "./music-store.js";
|
|
13
|
+
import { serverId } from "./music-hub.js";
|
|
13
14
|
import { writeZip, zipSize } from "./zip-stream.js";
|
|
14
15
|
import { StationError } from "./stations.js";
|
|
15
16
|
import { adCsp, withPageAd } from "./station-guide.js";
|
|
@@ -25,7 +26,8 @@ export function isPublicLabelPath(path) {
|
|
|
25
26
|
}
|
|
26
27
|
/** nixamp.com's page that sells this: a song, an album or everything by the artist. */
|
|
27
28
|
export function buyLink(site, server, kind, artist, album = "", n = 0) {
|
|
28
|
-
|
|
29
|
+
// The server goes by its opaque id (music-hub.ts): no link names the machine the music is on.
|
|
30
|
+
const query = new URLSearchParams({ server: /^https:\/\//.test(server) ? serverId(server) : server, kind, artist, ...(kind !== "artist" ? { album } : {}), ...(kind === "song" ? { n: String(n) } : {}) });
|
|
29
31
|
return `${site}/buy?${query.toString()}`;
|
|
30
32
|
}
|
|
31
33
|
async function jsonBody(ctx, request) {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
/** A server's opaque id: the first 10 hex of the SHA-256 of its https origin. Both sides can work it out. */
|
|
3
|
+
export declare function serverId(base: string): string;
|
|
4
|
+
/** The followable id of an artist, as /follow and live.streaming's /radio use it. */
|
|
5
|
+
export declare function artistFollowId(name: string): string;
|
|
6
|
+
interface LabelArtist {
|
|
7
|
+
key: string;
|
|
8
|
+
name: string;
|
|
9
|
+
genre: string;
|
|
10
|
+
bio: string;
|
|
11
|
+
members?: Array<{
|
|
12
|
+
slug: string;
|
|
13
|
+
name: string;
|
|
14
|
+
role: string;
|
|
15
|
+
bio: string;
|
|
16
|
+
}>;
|
|
17
|
+
albums: Array<{
|
|
18
|
+
key: string;
|
|
19
|
+
title: string;
|
|
20
|
+
year: number;
|
|
21
|
+
concept: string;
|
|
22
|
+
cover: boolean;
|
|
23
|
+
complete: boolean;
|
|
24
|
+
songs: Array<{
|
|
25
|
+
n: number;
|
|
26
|
+
title: string;
|
|
27
|
+
seconds: number;
|
|
28
|
+
lyrics?: string;
|
|
29
|
+
}>;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export interface HubStation {
|
|
33
|
+
server: string;
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
state: string;
|
|
37
|
+
listen: string;
|
|
38
|
+
token: string;
|
|
39
|
+
nowPlaying: {
|
|
40
|
+
title: string;
|
|
41
|
+
artist: string;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
export interface HubArtist extends LabelArtist {
|
|
45
|
+
server: string;
|
|
46
|
+
follow: string;
|
|
47
|
+
}
|
|
48
|
+
export interface HubCatalogue {
|
|
49
|
+
holders: string[];
|
|
50
|
+
genres: Array<{
|
|
51
|
+
genre: string;
|
|
52
|
+
stations: HubStation[];
|
|
53
|
+
artists: HubArtist[];
|
|
54
|
+
}>;
|
|
55
|
+
/** Every AI station on the servers, by genre or not (lo-fi, the bands...). */
|
|
56
|
+
stations: HubStation[];
|
|
57
|
+
}
|
|
58
|
+
export interface MusicHubOptions {
|
|
59
|
+
/** The servers whose labels are gathered: the directory and the guide's peers. */
|
|
60
|
+
peers: () => string[];
|
|
61
|
+
fetcher?: typeof fetch;
|
|
62
|
+
now?: () => number;
|
|
63
|
+
}
|
|
64
|
+
export declare class MusicHub {
|
|
65
|
+
private readonly options;
|
|
66
|
+
private cache;
|
|
67
|
+
private bases;
|
|
68
|
+
constructor(options: MusicHubOptions);
|
|
69
|
+
private now;
|
|
70
|
+
/** The https origin behind an opaque id, among the servers known now. */
|
|
71
|
+
resolve(id: string): string;
|
|
72
|
+
/** The catalogue, gathered at most once a minute (a slow or gone server is left out, not waited on). */
|
|
73
|
+
catalogue(): Promise<HubCatalogue>;
|
|
74
|
+
private read;
|
|
75
|
+
private gather;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* live.streaming's /radio/artist/<slug> and /radio/album/<slug> addresses, on
|
|
79
|
+
* nixamp.com: the /music page they name (radio-slug.ts's slugs), or "" when
|
|
80
|
+
* the catalogue has no such artist or album.
|
|
81
|
+
*/
|
|
82
|
+
export declare function musicPageFor(hub: MusicHub, path: string): Promise<string>;
|
|
83
|
+
export declare function isMusicPath(path: string): boolean;
|
|
84
|
+
export interface MusicRoutesContext {
|
|
85
|
+
hub: MusicHub;
|
|
86
|
+
json: (response: ServerResponse, status: number, body: unknown) => void;
|
|
87
|
+
readBody: (request: IncomingMessage) => Promise<string>;
|
|
88
|
+
/** The page shell (web/music.html), or null when the web build is absent. */
|
|
89
|
+
page: () => string | null;
|
|
90
|
+
/** A server says something of its label landed; null when nobody may say so. */
|
|
91
|
+
released?: (request: IncomingMessage, body: Record<string, unknown>) => Promise<{
|
|
92
|
+
status: number;
|
|
93
|
+
body: unknown;
|
|
94
|
+
}>;
|
|
95
|
+
}
|
|
96
|
+
export declare function handleMusicRoutes(request: IncomingMessage, response: ServerResponse, path: string, ctx: MusicRoutesContext): Promise<boolean>;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nixamp.com/music: every AI label's catalogue in one place.
|
|
3
|
+
*
|
|
4
|
+
* The music lives on the servers that make it (server1 and any other nixamp
|
|
5
|
+
* with a label); nixamp.com is where people listen, browse, follow and buy.
|
|
6
|
+
* This gathers each server's /api/v1/label and its public stations, gives
|
|
7
|
+
* every server a short opaque id (so no page or link names the machine), and
|
|
8
|
+
* hands covers, portraits and words through itself.
|
|
9
|
+
*
|
|
10
|
+
* GET /api/v1/music the merged catalogue
|
|
11
|
+
* GET /api/v1/music/file/<server>/<path> a cover, portrait, profile or words, through nixamp.com
|
|
12
|
+
* POST /api/v1/music/released a server says an album or song landed: its followers hear
|
|
13
|
+
*/
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
15
|
+
/** A server's opaque id: the first 10 hex of the SHA-256 of its https origin. Both sides can work it out. */
|
|
16
|
+
export function serverId(base) {
|
|
17
|
+
return createHash("sha256").update(base.replace(/\/+$/, "")).digest("hex").slice(0, 10);
|
|
18
|
+
}
|
|
19
|
+
/** The followable id of an artist, as /follow and live.streaming's /radio use it. */
|
|
20
|
+
export function artistFollowId(name) {
|
|
21
|
+
const slug = name.split(/\s*;\s*/)[0].normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "artist";
|
|
22
|
+
return `artist:${slug}`;
|
|
23
|
+
}
|
|
24
|
+
export class MusicHub {
|
|
25
|
+
options;
|
|
26
|
+
cache = null;
|
|
27
|
+
bases = new Map();
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.options = options;
|
|
30
|
+
}
|
|
31
|
+
now() {
|
|
32
|
+
return this.options.now?.() ?? Date.now();
|
|
33
|
+
}
|
|
34
|
+
/** The https origin behind an opaque id, among the servers known now. */
|
|
35
|
+
resolve(id) {
|
|
36
|
+
if (!/^[a-f0-9]{10}$/.test(id))
|
|
37
|
+
return "";
|
|
38
|
+
if (!this.bases.has(id))
|
|
39
|
+
for (const base of this.options.peers())
|
|
40
|
+
this.bases.set(serverId(base), base);
|
|
41
|
+
return this.bases.get(id) ?? "";
|
|
42
|
+
}
|
|
43
|
+
/** The catalogue, gathered at most once a minute (a slow or gone server is left out, not waited on). */
|
|
44
|
+
catalogue() {
|
|
45
|
+
if (this.cache && this.now() - this.cache.at < 60_000)
|
|
46
|
+
return this.cache.value;
|
|
47
|
+
const value = this.gather().catch((error) => { this.cache = null; throw error; });
|
|
48
|
+
this.cache = { at: this.now(), value };
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
async read(url) {
|
|
52
|
+
try {
|
|
53
|
+
const response = await (this.options.fetcher ?? fetch)(url, { signal: AbortSignal.timeout(6_000), headers: { accept: "application/json" } });
|
|
54
|
+
return response.ok ? await response.json() : null;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async gather() {
|
|
61
|
+
const peers = [...new Set(this.options.peers())];
|
|
62
|
+
const holders = new Set();
|
|
63
|
+
const genres = new Map();
|
|
64
|
+
const stations = [];
|
|
65
|
+
await Promise.all(peers.map(async (base) => {
|
|
66
|
+
const id = serverId(base);
|
|
67
|
+
this.bases.set(id, base);
|
|
68
|
+
const [label, guide] = await Promise.all([
|
|
69
|
+
this.read(`${base}/api/v1/label`),
|
|
70
|
+
this.read(`${base}/api/v1/stations/guide?local=1`),
|
|
71
|
+
]);
|
|
72
|
+
// A station is heard through its own server; the page's token is its listen key.
|
|
73
|
+
const byId = new Map();
|
|
74
|
+
for (const one of guide?.stations ?? []) {
|
|
75
|
+
if (one.group && one.group !== "ai")
|
|
76
|
+
continue;
|
|
77
|
+
let page;
|
|
78
|
+
try {
|
|
79
|
+
page = new URL(one.page);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (page.origin !== base)
|
|
85
|
+
continue;
|
|
86
|
+
const station = { server: id, id: one.id, name: one.name, state: one.state, listen: `${base}/api/v1/stations/${one.id}`, token: page.searchParams.get("t") ?? "", nowPlaying: one.nowPlaying };
|
|
87
|
+
byId.set(one.id, station);
|
|
88
|
+
stations.push(station);
|
|
89
|
+
}
|
|
90
|
+
if (!label)
|
|
91
|
+
return;
|
|
92
|
+
holders.add(label.holder);
|
|
93
|
+
for (const genre of label.genres) {
|
|
94
|
+
const slot = genres.get(genre.genre) ?? { genre: genre.genre, stations: [], artists: [] };
|
|
95
|
+
const station = byId.get(genre.station);
|
|
96
|
+
if (station)
|
|
97
|
+
slot.stations.push(station);
|
|
98
|
+
for (const artist of genre.artists)
|
|
99
|
+
slot.artists.push({ ...artist, server: id, follow: artistFollowId(artist.name) });
|
|
100
|
+
genres.set(genre.genre, slot);
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
return {
|
|
104
|
+
holders: [...holders],
|
|
105
|
+
genres: [...genres.values()].sort((a, b) => a.genre.localeCompare(b.genre)),
|
|
106
|
+
stations: stations.sort((a, b) => a.name.localeCompare(b.name)),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const FILE = /^\/api\/v1\/music\/file\/([a-f0-9]{10})\/([a-f0-9]{10}\/(?:[a-f0-9]{8}\/(?:\d{1,3}\.txt|cover\.jpg)|artist\.md|members\/[a-z0-9-]{1,40}\.(?:md|jpg)))$/;
|
|
111
|
+
const slugOf = (text, max) => text.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, max);
|
|
112
|
+
/**
|
|
113
|
+
* live.streaming's /radio/artist/<slug> and /radio/album/<slug> addresses, on
|
|
114
|
+
* nixamp.com: the /music page they name (radio-slug.ts's slugs), or "" when
|
|
115
|
+
* the catalogue has no such artist or album.
|
|
116
|
+
*/
|
|
117
|
+
export async function musicPageFor(hub, path) {
|
|
118
|
+
const match = /^\/radio\/(artist|album)\/([a-z0-9-]{1,100})\/?$/.exec(path);
|
|
119
|
+
if (!match)
|
|
120
|
+
return "";
|
|
121
|
+
const catalogue = await hub.catalogue();
|
|
122
|
+
const artists = catalogue.genres.flatMap((one) => one.artists);
|
|
123
|
+
if (match[1] === "artist") {
|
|
124
|
+
const artist = artists.find((one) => one.follow === `artist:${match[2]}`);
|
|
125
|
+
return artist ? `/music/artist/${artist.server}/${artist.key}` : "";
|
|
126
|
+
}
|
|
127
|
+
for (const artist of artists) {
|
|
128
|
+
const album = artist.albums.find((one) => slugOf(`${artist.follow.slice(7)} ${one.title}`, 90) === match[2]);
|
|
129
|
+
if (album)
|
|
130
|
+
return `/music/album/${artist.server}/${artist.key}/${album.key}`;
|
|
131
|
+
}
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
export function isMusicPath(path) {
|
|
135
|
+
return path === "/music" || path.startsWith("/music/") || path === "/api/v1/music" || FILE.test(path) || path === "/api/v1/music/released";
|
|
136
|
+
}
|
|
137
|
+
export async function handleMusicRoutes(request, response, path, ctx) {
|
|
138
|
+
if (!isMusicPath(path))
|
|
139
|
+
return false;
|
|
140
|
+
const method = request.method ?? "GET";
|
|
141
|
+
if (path === "/api/v1/music/released") {
|
|
142
|
+
if (method !== "POST" || !ctx.released) {
|
|
143
|
+
ctx.json(response, 405, { error: "not like that" });
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
let body = {};
|
|
147
|
+
try {
|
|
148
|
+
body = JSON.parse(await ctx.readBody(request));
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
ctx.json(response, 400, { error: "the body is not JSON" });
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
const answer = await ctx.released(request, body);
|
|
155
|
+
ctx.json(response, answer.status, answer.body);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
159
|
+
ctx.json(response, 405, { error: "not like that" });
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
if (path === "/api/v1/music") {
|
|
163
|
+
ctx.json(response, 200, await ctx.hub.catalogue());
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
const file = FILE.exec(path);
|
|
167
|
+
if (file) {
|
|
168
|
+
const base = ctx.hub.resolve(file[1]);
|
|
169
|
+
if (!base) {
|
|
170
|
+
ctx.json(response, 404, { error: "no such server" });
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const upstream = await fetch(`${base}/api/v1/label/${file[2]}`, { signal: AbortSignal.timeout(15_000) });
|
|
175
|
+
if (!upstream.ok || !upstream.body) {
|
|
176
|
+
ctx.json(response, upstream.status === 404 ? 404 : 502, { error: "not there" });
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
response.writeHead(200, {
|
|
180
|
+
"content-type": upstream.headers.get("content-type") ?? "application/octet-stream",
|
|
181
|
+
"cache-control": "public, max-age=3600",
|
|
182
|
+
...(upstream.headers.get("content-length") ? { "content-length": upstream.headers.get("content-length") } : {}),
|
|
183
|
+
});
|
|
184
|
+
if (method === "HEAD") {
|
|
185
|
+
response.end();
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
const reader = upstream.body.getReader();
|
|
189
|
+
for (;;) {
|
|
190
|
+
const { done, value } = await reader.read();
|
|
191
|
+
if (done)
|
|
192
|
+
break;
|
|
193
|
+
if (!response.write(value))
|
|
194
|
+
await new Promise((resolve) => response.once("drain", resolve));
|
|
195
|
+
}
|
|
196
|
+
response.end();
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
if (!response.headersSent)
|
|
200
|
+
ctx.json(response, 502, { error: "the server holding it did not answer" });
|
|
201
|
+
else
|
|
202
|
+
response.destroy();
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
// /music and everything under it is the app; it reads /api/v1/music.
|
|
207
|
+
const page = ctx.page();
|
|
208
|
+
if (!page) {
|
|
209
|
+
ctx.json(response, 404, { error: "the music app is not built here" });
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
response.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-cache" });
|
|
213
|
+
response.end(method === "HEAD" ? undefined : page);
|
|
214
|
+
return true;
|
|
215
|
+
}
|
package/dist/music-store.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ export interface MusicStoreOptions {
|
|
|
63
63
|
secret: string;
|
|
64
64
|
/** The servers whose catalogues may be sold here (the directory and the guide's peers). */
|
|
65
65
|
servers: () => string[];
|
|
66
|
+
/** The https origin behind an opaque server id, when nixamp.com keeps a hub. */
|
|
67
|
+
resolveServer?: (id: string) => string;
|
|
66
68
|
fetcher?: typeof fetch;
|
|
67
69
|
now?: () => number;
|
|
68
70
|
log?: (line: string) => void;
|
package/dist/music-store.js
CHANGED
|
@@ -151,7 +151,9 @@ export class MusicStore {
|
|
|
151
151
|
}
|
|
152
152
|
/** What is for sale at this address, with its name and price; refused when there is no such thing. */
|
|
153
153
|
async describe(input) {
|
|
154
|
-
|
|
154
|
+
// An opaque server id (music-hub.ts), or an https origin.
|
|
155
|
+
const asked = String(input["server"] ?? "");
|
|
156
|
+
const server = /^[a-f0-9]{10}$/.test(asked) ? (this.options.resolveServer?.(asked) ?? "") : serverBase(asked);
|
|
155
157
|
// A server in the directory or the guide's peers, or one named under nixamp.com (whose names
|
|
156
158
|
// and certificates nixamp.com issues): the directory empties on every restart of nixamp.com.
|
|
157
159
|
const named = server ? new URL(server).hostname.endsWith(".nixamp.com") : false;
|
|
@@ -240,7 +242,7 @@ export class MusicStore {
|
|
|
240
242
|
await this.mail(purchase.email, `Your music: ${purchase.title}`, [
|
|
241
243
|
`Thank you. "${purchase.title}" by ${purchase.artistName} is yours: MP3s with the cover art and the lyrics, in one zip.`,
|
|
242
244
|
`Download it, now or any time: ${this.link(purchase.id, purchase.token)}`,
|
|
243
|
-
`Sign in to nixamp.com with ${purchase.email} and everything you have bought is under My music on ${this.options.site}/
|
|
245
|
+
`Sign in to nixamp.com with ${purchase.email} and everything you have bought is under My music on ${this.options.site}/music/me, to play or download again.`,
|
|
244
246
|
]);
|
|
245
247
|
return purchase;
|
|
246
248
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { ListenerStore } from "./library-user.ts";
|
|
|
26
26
|
import { Importer } from "./handoff.ts";
|
|
27
27
|
import { AiLabel } from "./ai-label.ts";
|
|
28
28
|
import { MusicStore } from "./music-store.ts";
|
|
29
|
+
import { MusicHub } from "./music-hub.ts";
|
|
29
30
|
import { AiRadio } from "./ai-radio.ts";
|
|
30
31
|
import { ListenerShares } from "./listener-shares.ts";
|
|
31
32
|
import { Support, SupportSubscriptions } from "./support.ts";
|
|
@@ -833,6 +834,14 @@ export interface HandlerOptions {
|
|
|
833
834
|
coinpayWebhookSecret?: string;
|
|
834
835
|
/** The AI label's songs for sale, nixamp.com only (music-store.ts). */
|
|
835
836
|
musicStore?: MusicStore;
|
|
837
|
+
/** nixamp.com/music: every server's label in one app (music-hub.ts). */
|
|
838
|
+
music?: {
|
|
839
|
+
hub: MusicHub;
|
|
840
|
+
released: (request: IncomingMessage, body: Record<string, unknown>) => Promise<{
|
|
841
|
+
status: number;
|
|
842
|
+
body: unknown;
|
|
843
|
+
}>;
|
|
844
|
+
};
|
|
836
845
|
sharedTranslations?: SharedTranslations;
|
|
837
846
|
/** Translation: texts in another language, by a model here. The same optional library. */
|
|
838
847
|
translator?: Translator;
|
package/dist/server.js
CHANGED
|
@@ -64,6 +64,7 @@ import { handleAiRoutes, isPublicSharePath } from "./ai-routes.js";
|
|
|
64
64
|
import { AiLabel } from "./ai-label.js";
|
|
65
65
|
import { buyLink, handleLabelRoutes, isPublicLabelPath } from "./label-routes.js";
|
|
66
66
|
import { GrantVerifier, MusicStore, PRICES } from "./music-store.js";
|
|
67
|
+
import { handleMusicRoutes, isMusicPath, MusicHub, musicPageFor, serverId } from "./music-hub.js";
|
|
67
68
|
import { handleStoreRoutes, isStorePath } from "./store-routes.js";
|
|
68
69
|
import { AiRadio } from "./ai-radio.js";
|
|
69
70
|
import { ListenerShares } from "./listener-shares.js";
|
|
@@ -1591,7 +1592,7 @@ export function createHandler(engine, options) {
|
|
|
1591
1592
|
query.set("t", station.listenToken);
|
|
1592
1593
|
request.url = `/api/v1/stations/${station.id}/${sub[2]}?${query.toString()}`;
|
|
1593
1594
|
const here = options.stations.publicBase?.() ?? "";
|
|
1594
|
-
rewriteResponse(response, radioRewriter(station, sub[1], /^https:\/\//.test(here) ? `${storeSite}/buy?server=${
|
|
1595
|
+
rewriteResponse(response, radioRewriter(station, sub[1], /^https:\/\//.test(here) ? `${storeSite}/buy?server=${serverId(here)}&` : ""));
|
|
1595
1596
|
return handle(request, response);
|
|
1596
1597
|
}
|
|
1597
1598
|
}
|
|
@@ -2309,6 +2310,9 @@ export function createHandler(engine, options) {
|
|
|
2309
2310
|
!(isPublicLabelPath(path) && Boolean(options.stations?.label)) &&
|
|
2310
2311
|
// The music store: its pages, checkout, receipts and grants (nixamp.com).
|
|
2311
2312
|
!(isStorePath(path) && Boolean(options.musicStore)) &&
|
|
2313
|
+
// nixamp.com/music: the app and its catalogue, for anybody.
|
|
2314
|
+
!(isMusicPath(path) && Boolean(options.music)) &&
|
|
2315
|
+
!(/^\/radio\/(artist|album)\//.test(path) && Boolean(options.music)) &&
|
|
2312
2316
|
// What is on, as MCP, for anybody.
|
|
2313
2317
|
path !== "/mcp/public" &&
|
|
2314
2318
|
// Supporting a copyright holder is for anybody listening.
|
|
@@ -2643,6 +2647,15 @@ export function createHandler(engine, options) {
|
|
|
2643
2647
|
// /radio: public, listed stations under readable names, and the artists and
|
|
2644
2648
|
// albums they play (radio-pages.ts). A station's own paths under its name
|
|
2645
2649
|
// were answered at the top of this handler.
|
|
2650
|
+
// On nixamp.com, live.streaming's artist and album addresses open the same page of the music app.
|
|
2651
|
+
if (options.music && /^\/radio\/(artist|album)\//.test(path) && (request.method === "GET" || request.method === "HEAD")) {
|
|
2652
|
+
const target = await musicPageFor(options.music.hub, path).catch(() => "");
|
|
2653
|
+
if (target) {
|
|
2654
|
+
response.writeHead(302, { location: target });
|
|
2655
|
+
response.end();
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2646
2659
|
if (options.stations && isRadioPath(path) && (request.method === "GET" || request.method === "HEAD")) {
|
|
2647
2660
|
const stations = options.stations;
|
|
2648
2661
|
const named = radioStations(stations.store.list());
|
|
@@ -2844,6 +2857,23 @@ export function createHandler(engine, options) {
|
|
|
2844
2857
|
});
|
|
2845
2858
|
return;
|
|
2846
2859
|
}
|
|
2860
|
+
if (options.music && isMusicPath(path)) {
|
|
2861
|
+
const music = options.music;
|
|
2862
|
+
const shell = web ? join(web, "music.html") : "";
|
|
2863
|
+
if (await handleMusicRoutes(request, response, path, {
|
|
2864
|
+
hub: music.hub,
|
|
2865
|
+
json,
|
|
2866
|
+
readBody,
|
|
2867
|
+
page: () => { try {
|
|
2868
|
+
return shell ? readFileSync(shell, "utf8") : null;
|
|
2869
|
+
}
|
|
2870
|
+
catch {
|
|
2871
|
+
return null;
|
|
2872
|
+
} },
|
|
2873
|
+
released: music.released,
|
|
2874
|
+
}))
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2847
2877
|
if (options.musicStore && options.support && isStorePath(path)) {
|
|
2848
2878
|
const support = options.support;
|
|
2849
2879
|
const accounts = options.accounts;
|
|
@@ -7147,6 +7177,19 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7147
7177
|
root: process.env["NIXAMP_LABEL_ROOT"] || (labelHome ? join(labelHome.root, "ai") : join(stateDir(), "ai-label")),
|
|
7148
7178
|
owner: options.owner || "",
|
|
7149
7179
|
mayStart: mayStartStation,
|
|
7180
|
+
// A release is told to nixamp.com as this server's owner; nixamp.com tells the artist's followers.
|
|
7181
|
+
announce: (release) => {
|
|
7182
|
+
const session = readSession();
|
|
7183
|
+
const here = stations.publicBase?.() ?? "";
|
|
7184
|
+
if (!session?.token || !/^https:\/\//.test(here))
|
|
7185
|
+
return;
|
|
7186
|
+
void fetch(`${session.site.replace(/\/+$/, "")}/api/v1/music/released`, {
|
|
7187
|
+
method: "POST",
|
|
7188
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${session.token}` },
|
|
7189
|
+
body: JSON.stringify({ ...release, server: here }),
|
|
7190
|
+
signal: AbortSignal.timeout(15_000),
|
|
7191
|
+
}).then((answer) => console.log(` ai label: nixamp.com was told of "${release.title}" (${answer.status})`)).catch(() => undefined);
|
|
7192
|
+
},
|
|
7150
7193
|
log: (line) => console.log(line),
|
|
7151
7194
|
});
|
|
7152
7195
|
aiRadio.startSchedule();
|
|
@@ -7397,18 +7440,54 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7397
7440
|
supportMonthly?.startSchedule();
|
|
7398
7441
|
// The AI label's songs for sale: purchases kept here, the music zipped by the server that holds it.
|
|
7399
7442
|
const jwtSecret = process.env["NIXAMP_JWT_SECRET"] ?? "";
|
|
7443
|
+
// The servers whose music nixamp.com sells and plays: the directory and the guide's peers.
|
|
7444
|
+
const musicServers = () => {
|
|
7445
|
+
const listed = directory ? directory.list().map((one) => peerBase(one.url)).filter(Boolean) : [];
|
|
7446
|
+
return [...new Set([...guidePeers(), ...listed])];
|
|
7447
|
+
};
|
|
7448
|
+
// nixamp.com/music: every server's label in one catalogue (music-hub.ts).
|
|
7449
|
+
const musicHub = options.directory ? new MusicHub({ peers: musicServers }) : undefined;
|
|
7400
7450
|
const musicStore = supportPayments && supportPayments.enabled && pool && jwtSecret ? new MusicStore({
|
|
7401
7451
|
db: pool,
|
|
7402
7452
|
support: supportPayments,
|
|
7403
7453
|
mail: process.env["RESEND_API_KEY"] ? { apiKey: process.env["RESEND_API_KEY"], from: process.env["NIXAMP_MAIL_FROM"] ?? "nixamp <notifications@nixamp.com>" } : null,
|
|
7404
7454
|
site: nixampSite,
|
|
7405
7455
|
secret: sha("sha256").update(`music-grant:${jwtSecret}`).digest("hex"),
|
|
7406
|
-
servers:
|
|
7407
|
-
|
|
7408
|
-
return [...new Set([...guidePeers(), ...listed])];
|
|
7409
|
-
},
|
|
7456
|
+
servers: musicServers,
|
|
7457
|
+
...(musicHub ? { resolveServer: (id) => musicHub.resolve(id) } : {}),
|
|
7410
7458
|
log: (line) => console.log(line),
|
|
7411
7459
|
}) : undefined;
|
|
7460
|
+
/**
|
|
7461
|
+
* A server says an album (or song) of its label landed: its artist's
|
|
7462
|
+
* followers are told. Only the account that owns a listed server may say
|
|
7463
|
+
* so, only for an artist that server's catalogue has, once per release.
|
|
7464
|
+
*/
|
|
7465
|
+
const announced = new Set();
|
|
7466
|
+
const musicReleased = async (request, body) => {
|
|
7467
|
+
const me = accounts ? await accounts.whoIs(tokenFrom(request.headers)).catch(() => null) : null;
|
|
7468
|
+
if (!me)
|
|
7469
|
+
return { status: 401, body: { error: "sign in as the server's owner" } };
|
|
7470
|
+
const base = peerBase(String(body["server"] ?? ""));
|
|
7471
|
+
const owns = directory?.list().some((one) => one.ownerId === me.id && peerBase(one.url) === base) ?? false;
|
|
7472
|
+
if (!base || !owns || !musicHub)
|
|
7473
|
+
return { status: 403, body: { error: "that server is not yours, or not listed" } };
|
|
7474
|
+
const catalogue = await musicHub.catalogue();
|
|
7475
|
+
const id = serverId(base);
|
|
7476
|
+
const artist = catalogue.genres.flatMap((one) => one.artists).find((one) => one.server === id && one.key === body["artist"]);
|
|
7477
|
+
const what = String(body["title"] ?? "").replace(/[\r\n]/g, " ").slice(0, 120);
|
|
7478
|
+
if (!artist || !what)
|
|
7479
|
+
return { status: 404, body: { error: "no such artist on that server" } };
|
|
7480
|
+
const key = `${id}:${artist.key}:${what}`;
|
|
7481
|
+
if (announced.has(key))
|
|
7482
|
+
return { status: 200, body: { told: false, why: "already" } };
|
|
7483
|
+
announced.add(key);
|
|
7484
|
+
tellAudienceOf(artist.follow, {
|
|
7485
|
+
title: `New from ${artist.name}`,
|
|
7486
|
+
body: body["kind"] === "song" ? `"${what}" is out. Listen free on nixamp.` : `The album "${what}" is out. Listen free on nixamp.`,
|
|
7487
|
+
url: `${nixampSite}/music/artist/${id}/${artist.key}`,
|
|
7488
|
+
});
|
|
7489
|
+
return { status: 202, body: { told: true, follow: artist.follow } };
|
|
7490
|
+
};
|
|
7412
7491
|
if (translationPasses)
|
|
7413
7492
|
void translationPasses.access().catch(() => console.error("nixamp: translation checkout could not warm; it will retry on demand"));
|
|
7414
7493
|
const liveVoice = accounts && process.env["NIXAMP_DUBBING"] !== "off" ? new LiveVoice({
|
|
@@ -7556,8 +7635,14 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7556
7635
|
body: `${what} Listen at ${DEFAULT_DIRECTORY}/directory, or call ${CALL_IN_NUMBER} and key ${listing.code}.`.trim(),
|
|
7557
7636
|
url: listing.url,
|
|
7558
7637
|
};
|
|
7638
|
+
tellAudienceOf(listing.ownerId, note);
|
|
7639
|
+
};
|
|
7640
|
+
/** Everyone following `followed` (an account, or `artist:<slug>`), by every way they asked to be told. */
|
|
7641
|
+
const tellAudienceOf = (followed, note) => {
|
|
7642
|
+
if (follows === undefined)
|
|
7643
|
+
return;
|
|
7559
7644
|
void follows
|
|
7560
|
-
.audience(
|
|
7645
|
+
.audience(followed)
|
|
7561
7646
|
.then((audience) => notifyAll(audience, note, {
|
|
7562
7647
|
...(process.env["RESEND_API_KEY"]
|
|
7563
7648
|
? {
|
|
@@ -7960,6 +8045,7 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7960
8045
|
...(supportPayments ? { support: supportPayments } : {}),
|
|
7961
8046
|
...(supportMonthly ? { supportSubscriptions: supportMonthly } : {}),
|
|
7962
8047
|
...(musicStore ? { musicStore } : {}),
|
|
8048
|
+
...(musicHub ? { music: { hub: musicHub, released: musicReleased } } : {}),
|
|
7963
8049
|
...(process.env["COINPAY_WEBHOOK_SECRET"] ? { coinpayWebhookSecret: process.env["COINPAY_WEBHOOK_SECRET"] } : {}),
|
|
7964
8050
|
...(sharedTranslations ? { sharedTranslations } : {}),
|
|
7965
8051
|
...(translator ? { translator } : {}),
|
package/dist/store-routes.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { PRICES } from "./music-store.js";
|
|
14
|
+
import { serverId } from "./music-hub.js";
|
|
14
15
|
import { SupportError } from "./support.js";
|
|
15
16
|
const PURCHASE = /^\/purchases\/([0-9a-f-]{36})$/;
|
|
16
17
|
const ONE = /^\/api\/v1\/store\/purchases\/([0-9a-f-]{36})$/;
|
|
@@ -100,7 +101,7 @@ export async function handleStoreRoutes(request, response, path, url, ctx) {
|
|
|
100
101
|
}
|
|
101
102
|
const me = await ctx.account().catch(() => null);
|
|
102
103
|
const what = item.kind === "song" ? "One song" : item.kind === "album" ? `The album, ${item.songs} songs` : `Everything by ${escape(item.artistName)}, ${item.songs} songs so far`;
|
|
103
|
-
const cover = item.kind === "artist" ? "" : `<img src="${escape(
|
|
104
|
+
const cover = item.kind === "artist" ? "" : `<img src="${escape(`/api/v1/music/file/${serverId(item.server)}/${item.artist}/${item.album}/cover.jpg`)}" alt="" width="160" height="160" style="border-radius:10px;float:right;margin:0 0 8px 12px;max-width:40%;height:auto">`;
|
|
104
105
|
html(response, 200, page(`Download ${item.title}`, `<div class="card">${cover}
|
|
105
106
|
<h1>${escape(item.title)}</h1><p class="by">${escape(item.artistName)}</p>
|
|
106
107
|
<div class="price">${price(item.amountCents)}</div>
|
|
@@ -113,8 +114,8 @@ export async function handleStoreRoutes(request, response, path, url, ctx) {
|
|
|
113
114
|
<button id="pay" type="submit">Pay ${price(item.amountCents)} with crypto</button>
|
|
114
115
|
</form>
|
|
115
116
|
<p id="status" role="status" aria-live="polite"></p>
|
|
116
|
-
<small>Payments go through <a href="https://coinpayportal.com">CoinPay</a> to nixamp.com. For small amounts pick a coin with low fees (USDC on Polygon or Solana, SOL, LTC). Listening on the live stations is always free.${me ? "" : ` <a href="/
|
|
117
|
-
</div>`, JSON.stringify({ server: item.server, kind: item.kind, artist: item.artist, album: item.album, n: item.n })), method);
|
|
117
|
+
<small>Payments go through <a href="https://coinpayportal.com">CoinPay</a> to nixamp.com. For small amounts pick a coin with low fees (USDC on Polygon or Solana, SOL, LTC). Listening on the live stations is always free.${me ? "" : ` <a href="/?redirect=${encodeURIComponent("/music/me")}#account-panel">Sign in</a> with the same email to keep everything under My music.`}</small>
|
|
118
|
+
</div>`, JSON.stringify({ server: serverId(item.server), kind: item.kind, artist: item.artist, album: item.album, n: item.n })), method);
|
|
118
119
|
return true;
|
|
119
120
|
}
|
|
120
121
|
const receipt = PURCHASE.exec(path);
|
|
@@ -127,7 +128,7 @@ export async function handleStoreRoutes(request, response, path, url, ctx) {
|
|
|
127
128
|
const body = purchase.status === "paid"
|
|
128
129
|
? `<div class="card"><h1>${escape(purchase.title)}</h1><p class="by">${escape(purchase.artistName)} · paid ${price(purchase.amountCents)}</p>
|
|
129
130
|
<a class="go" href="${escape(store.zipUrl(purchase))}" download>Download the zip</a>
|
|
130
|
-
<small>MP3s with the cover art and lyrics, plus each song's .lyrics.txt, cover.jpg and album.json. Keep this page's address (it is in your email too) to download again. Signed in to nixamp.com as ${escape(purchase.email)}, everything you bought is under <a href="/
|
|
131
|
+
<small>MP3s with the cover art and lyrics, plus each song's .lyrics.txt, cover.jpg and album.json. Keep this page's address (it is in your email too) to download again. Signed in to nixamp.com as ${escape(purchase.email)}, everything you bought is under <a href="/music/me">My music</a>, to play or download.</small></div>`
|
|
131
132
|
: `<div class="card"><h1>${escape(purchase.title)}</h1><p class="by">${escape(purchase.artistName)} · ${price(purchase.amountCents)} in ${escape(purchase.coin)}</p>
|
|
132
133
|
<p>Waiting for your payment. Once CoinPay confirms it, your download is here and in your email (${escape(purchase.email)}). This page checks again when you reload it.</p>
|
|
133
134
|
<a class="go" href="https://coinpayportal.com/pay/${escape(purchase.paymentId)}">Open the payment</a></div>`;
|
package/package.json
CHANGED
package/src/ai-label.ts
CHANGED
|
@@ -738,6 +738,8 @@ export interface AiLabelDeps {
|
|
|
738
738
|
storyVideo?: (input: { audio: string; images: string[]; seconds: number; artist: string; title: string; out: string }) => Promise<void>;
|
|
739
739
|
/** A scene's picture for this prompt, or null when nothing can draw one; Workers AI by default. */
|
|
740
740
|
image?: (prompt: string) => Promise<Buffer | null>;
|
|
741
|
+
/** Tells the world an album landed (nixamp.com tells the artist's followers); never awaited. */
|
|
742
|
+
announce?: (release: { artist: string; title: string; kind: "album" | "song" }) => void;
|
|
741
743
|
/** The day's pick (artist, genre, new or not); Math.random by default. */
|
|
742
744
|
random?: () => number;
|
|
743
745
|
now?: () => number;
|
|
@@ -1383,6 +1385,7 @@ export class AiLabel {
|
|
|
1383
1385
|
if (album.songs.every((one) => one.file)) {
|
|
1384
1386
|
album.doneAt = this.now();
|
|
1385
1387
|
this.log(`${artist.name} released "${album.title}"`);
|
|
1388
|
+
this.deps.announce?.({ artist: artist.key, title: album.title, kind: "album" });
|
|
1386
1389
|
void this.ensureProfile(artist).catch(() => undefined);
|
|
1387
1390
|
}
|
|
1388
1391
|
this.save();
|