nixamp 0.58.1 → 0.59.1
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 +109 -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 +95 -6
- package/src/store-routes.ts +5 -4
- package/web/dist/assets/{ar-CBn9fObz.js → ar-BUzfqyls.js} +1 -1
- package/web/dist/assets/chunk-Q2XQMA4B-BaoaSqsD.js +1 -0
- package/web/dist/assets/{cs-BvEScz92.js → cs-Cg4JJr06.js} +1 -1
- package/web/dist/assets/{da-uKElVtgi.js → da-Dw-Resfu.js} +1 -1
- package/web/dist/assets/{de-DXEoI1GG.js → de-CZ5dYZwQ.js} +1 -1
- package/web/dist/assets/{es-Q-QEZFh2.js → es-D-dOpAe8.js} +1 -1
- package/web/dist/assets/{fi-ClJkdfXs.js → fi-k22PyB0Z.js} +1 -1
- package/web/dist/assets/{fr-DWmNoP1h.js → fr-DYab0grY.js} +1 -1
- package/web/dist/assets/{hi-DGQOrveg.js → hi-BvC83nQm.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-vUE9gd3q.js} +1 -1
- package/web/dist/assets/{id-D18Cz5RW.js → id-CZk93O-W.js} +1 -1
- package/web/dist/assets/{it-WQxuRjlI.js → it-RH7JO2dG.js} +1 -1
- package/web/dist/assets/{main-cry6C8KD.js → main-DtTNC2wE.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-CuG3UJ3J.js} +1 -1
- package/web/dist/assets/radio-DmVc3wpH.js +1 -0
- package/web/dist/assets/{ru-Cx4tgP1k.js → ru-B2Iki93q.js} +1 -1
- package/web/dist/assets/{station-BzLUgyQ0.js → station-DtY1LOm5.js} +1 -1
- package/web/dist/assets/{sv-f0zj1AdU.js → sv-ChF-PxpS.js} +1 -1
- package/web/dist/assets/{uk-DpGYtFFI.js → uk-kLEkvaMX.js} +1 -1
- package/web/dist/assets/{vi-Cxf7VqJQ.js → vi-CjnMlYos.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-Uq6eryT3.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());
|
|
@@ -2691,12 +2704,27 @@ export function createHandler(engine, options) {
|
|
|
2691
2704
|
], base, nav));
|
|
2692
2705
|
return;
|
|
2693
2706
|
}
|
|
2707
|
+
// Our label's artists and albums live on nixamp.com/music, where Follow,
|
|
2708
|
+
// Buy and the player are; live.streaming is the public mirror and sends
|
|
2709
|
+
// them there. Anybody else's keep their page here.
|
|
2710
|
+
const onSite = (() => { try {
|
|
2711
|
+
return new URL(storeSite).host === requestHost;
|
|
2712
|
+
}
|
|
2713
|
+
catch {
|
|
2714
|
+
return true;
|
|
2715
|
+
} })();
|
|
2716
|
+
const toMusic = (kind, slug) => {
|
|
2717
|
+
response.writeHead(302, { location: `${storeSite}/radio/${kind}/${encodeURIComponent(slug)}`, "cache-control": "public, max-age=300" });
|
|
2718
|
+
response.end();
|
|
2719
|
+
};
|
|
2694
2720
|
const artistPath = RADIO_ARTIST.exec(path);
|
|
2695
2721
|
if (artistPath) {
|
|
2696
2722
|
const catalogue = radioCatalogue();
|
|
2697
2723
|
const artist = catalogue.artists.get(artistPath[1]);
|
|
2698
2724
|
if (!artist)
|
|
2699
2725
|
return send(404, renderMissing("artist", base, nav));
|
|
2726
|
+
if (artist.label && !onSite)
|
|
2727
|
+
return toMusic("artist", artistPath[1]);
|
|
2700
2728
|
return send(200, renderArtist(catalogue, artist, { base, nav, shop, site: storeSite, stationNames }));
|
|
2701
2729
|
}
|
|
2702
2730
|
const albumPath = RADIO_ALBUM.exec(path);
|
|
@@ -2715,6 +2743,8 @@ export function createHandler(engine, options) {
|
|
|
2715
2743
|
}
|
|
2716
2744
|
if (!album)
|
|
2717
2745
|
return send(404, renderMissing("album", base, nav));
|
|
2746
|
+
if (album.label && !onSite)
|
|
2747
|
+
return toMusic("album", albumPath[1]);
|
|
2718
2748
|
return send(200, renderAlbum(catalogue, album, { base, nav, shop, site: storeSite, stationNames }));
|
|
2719
2749
|
}
|
|
2720
2750
|
const stationPath = RADIO_STATION.exec(path);
|
|
@@ -2844,6 +2874,23 @@ export function createHandler(engine, options) {
|
|
|
2844
2874
|
});
|
|
2845
2875
|
return;
|
|
2846
2876
|
}
|
|
2877
|
+
if (options.music && isMusicPath(path)) {
|
|
2878
|
+
const music = options.music;
|
|
2879
|
+
const shell = web ? join(web, "music.html") : "";
|
|
2880
|
+
if (await handleMusicRoutes(request, response, path, {
|
|
2881
|
+
hub: music.hub,
|
|
2882
|
+
json,
|
|
2883
|
+
readBody,
|
|
2884
|
+
page: () => { try {
|
|
2885
|
+
return shell ? readFileSync(shell, "utf8") : null;
|
|
2886
|
+
}
|
|
2887
|
+
catch {
|
|
2888
|
+
return null;
|
|
2889
|
+
} },
|
|
2890
|
+
released: music.released,
|
|
2891
|
+
}))
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2847
2894
|
if (options.musicStore && options.support && isStorePath(path)) {
|
|
2848
2895
|
const support = options.support;
|
|
2849
2896
|
const accounts = options.accounts;
|
|
@@ -7147,6 +7194,19 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7147
7194
|
root: process.env["NIXAMP_LABEL_ROOT"] || (labelHome ? join(labelHome.root, "ai") : join(stateDir(), "ai-label")),
|
|
7148
7195
|
owner: options.owner || "",
|
|
7149
7196
|
mayStart: mayStartStation,
|
|
7197
|
+
// A release is told to nixamp.com as this server's owner; nixamp.com tells the artist's followers.
|
|
7198
|
+
announce: (release) => {
|
|
7199
|
+
const session = readSession();
|
|
7200
|
+
const here = stations.publicBase?.() ?? "";
|
|
7201
|
+
if (!session?.token || !/^https:\/\//.test(here))
|
|
7202
|
+
return;
|
|
7203
|
+
void fetch(`${session.site.replace(/\/+$/, "")}/api/v1/music/released`, {
|
|
7204
|
+
method: "POST",
|
|
7205
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${session.token}` },
|
|
7206
|
+
body: JSON.stringify({ ...release, server: here }),
|
|
7207
|
+
signal: AbortSignal.timeout(15_000),
|
|
7208
|
+
}).then((answer) => console.log(` ai label: nixamp.com was told of "${release.title}" (${answer.status})`)).catch(() => undefined);
|
|
7209
|
+
},
|
|
7150
7210
|
log: (line) => console.log(line),
|
|
7151
7211
|
});
|
|
7152
7212
|
aiRadio.startSchedule();
|
|
@@ -7397,18 +7457,54 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7397
7457
|
supportMonthly?.startSchedule();
|
|
7398
7458
|
// The AI label's songs for sale: purchases kept here, the music zipped by the server that holds it.
|
|
7399
7459
|
const jwtSecret = process.env["NIXAMP_JWT_SECRET"] ?? "";
|
|
7460
|
+
// The servers whose music nixamp.com sells and plays: the directory and the guide's peers.
|
|
7461
|
+
const musicServers = () => {
|
|
7462
|
+
const listed = directory ? directory.list().map((one) => peerBase(one.url)).filter(Boolean) : [];
|
|
7463
|
+
return [...new Set([...guidePeers(), ...listed])];
|
|
7464
|
+
};
|
|
7465
|
+
// nixamp.com/music: every server's label in one catalogue (music-hub.ts).
|
|
7466
|
+
const musicHub = options.directory ? new MusicHub({ peers: musicServers }) : undefined;
|
|
7400
7467
|
const musicStore = supportPayments && supportPayments.enabled && pool && jwtSecret ? new MusicStore({
|
|
7401
7468
|
db: pool,
|
|
7402
7469
|
support: supportPayments,
|
|
7403
7470
|
mail: process.env["RESEND_API_KEY"] ? { apiKey: process.env["RESEND_API_KEY"], from: process.env["NIXAMP_MAIL_FROM"] ?? "nixamp <notifications@nixamp.com>" } : null,
|
|
7404
7471
|
site: nixampSite,
|
|
7405
7472
|
secret: sha("sha256").update(`music-grant:${jwtSecret}`).digest("hex"),
|
|
7406
|
-
servers:
|
|
7407
|
-
|
|
7408
|
-
return [...new Set([...guidePeers(), ...listed])];
|
|
7409
|
-
},
|
|
7473
|
+
servers: musicServers,
|
|
7474
|
+
...(musicHub ? { resolveServer: (id) => musicHub.resolve(id) } : {}),
|
|
7410
7475
|
log: (line) => console.log(line),
|
|
7411
7476
|
}) : undefined;
|
|
7477
|
+
/**
|
|
7478
|
+
* A server says an album (or song) of its label landed: its artist's
|
|
7479
|
+
* followers are told. Only the account that owns a listed server may say
|
|
7480
|
+
* so, only for an artist that server's catalogue has, once per release.
|
|
7481
|
+
*/
|
|
7482
|
+
const announced = new Set();
|
|
7483
|
+
const musicReleased = async (request, body) => {
|
|
7484
|
+
const me = accounts ? await accounts.whoIs(tokenFrom(request.headers)).catch(() => null) : null;
|
|
7485
|
+
if (!me)
|
|
7486
|
+
return { status: 401, body: { error: "sign in as the server's owner" } };
|
|
7487
|
+
const base = peerBase(String(body["server"] ?? ""));
|
|
7488
|
+
const owns = directory?.list().some((one) => one.ownerId === me.id && peerBase(one.url) === base) ?? false;
|
|
7489
|
+
if (!base || !owns || !musicHub)
|
|
7490
|
+
return { status: 403, body: { error: "that server is not yours, or not listed" } };
|
|
7491
|
+
const catalogue = await musicHub.catalogue();
|
|
7492
|
+
const id = serverId(base);
|
|
7493
|
+
const artist = catalogue.genres.flatMap((one) => one.artists).find((one) => one.server === id && one.key === body["artist"]);
|
|
7494
|
+
const what = String(body["title"] ?? "").replace(/[\r\n]/g, " ").slice(0, 120);
|
|
7495
|
+
if (!artist || !what)
|
|
7496
|
+
return { status: 404, body: { error: "no such artist on that server" } };
|
|
7497
|
+
const key = `${id}:${artist.key}:${what}`;
|
|
7498
|
+
if (announced.has(key))
|
|
7499
|
+
return { status: 200, body: { told: false, why: "already" } };
|
|
7500
|
+
announced.add(key);
|
|
7501
|
+
tellAudienceOf(artist.follow, {
|
|
7502
|
+
title: `New from ${artist.name}`,
|
|
7503
|
+
body: body["kind"] === "song" ? `"${what}" is out. Listen free on nixamp.` : `The album "${what}" is out. Listen free on nixamp.`,
|
|
7504
|
+
url: `${nixampSite}/music/artist/${id}/${artist.key}`,
|
|
7505
|
+
});
|
|
7506
|
+
return { status: 202, body: { told: true, follow: artist.follow } };
|
|
7507
|
+
};
|
|
7412
7508
|
if (translationPasses)
|
|
7413
7509
|
void translationPasses.access().catch(() => console.error("nixamp: translation checkout could not warm; it will retry on demand"));
|
|
7414
7510
|
const liveVoice = accounts && process.env["NIXAMP_DUBBING"] !== "off" ? new LiveVoice({
|
|
@@ -7556,8 +7652,14 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7556
7652
|
body: `${what} Listen at ${DEFAULT_DIRECTORY}/directory, or call ${CALL_IN_NUMBER} and key ${listing.code}.`.trim(),
|
|
7557
7653
|
url: listing.url,
|
|
7558
7654
|
};
|
|
7655
|
+
tellAudienceOf(listing.ownerId, note);
|
|
7656
|
+
};
|
|
7657
|
+
/** Everyone following `followed` (an account, or `artist:<slug>`), by every way they asked to be told. */
|
|
7658
|
+
const tellAudienceOf = (followed, note) => {
|
|
7659
|
+
if (follows === undefined)
|
|
7660
|
+
return;
|
|
7559
7661
|
void follows
|
|
7560
|
-
.audience(
|
|
7662
|
+
.audience(followed)
|
|
7561
7663
|
.then((audience) => notifyAll(audience, note, {
|
|
7562
7664
|
...(process.env["RESEND_API_KEY"]
|
|
7563
7665
|
? {
|
|
@@ -7960,6 +8062,7 @@ export async function serve(argv, version = "0.1.0") {
|
|
|
7960
8062
|
...(supportPayments ? { support: supportPayments } : {}),
|
|
7961
8063
|
...(supportMonthly ? { supportSubscriptions: supportMonthly } : {}),
|
|
7962
8064
|
...(musicStore ? { musicStore } : {}),
|
|
8065
|
+
...(musicHub ? { music: { hub: musicHub, released: musicReleased } } : {}),
|
|
7963
8066
|
...(process.env["COINPAY_WEBHOOK_SECRET"] ? { coinpayWebhookSecret: process.env["COINPAY_WEBHOOK_SECRET"] } : {}),
|
|
7964
8067
|
...(sharedTranslations ? { sharedTranslations } : {}),
|
|
7965
8068
|
...(translator ? { translator } : {}),
|