| 1 | // Een Apple Music-AFSPEELLIJST kreeg geen embed maar de kale shortcode.
|
|---|
| 2 | //
|
|---|
| 3 | // Barts melding (17-8): het concept "The Mixtape" toonde in preview letterlijk
|
|---|
| 4 | // [[embed:https://music.apple.com/nl/playlist/romance/pl.u-LdbqzVvI3go5g]].
|
|---|
| 5 | //
|
|---|
| 6 | // De keten: detectProvider herkende hem wel (die kijkt niet verder dan
|
|---|
| 7 | // /playlist/), applemusicIframe eiste een NUMMER als id -- goed voor een album
|
|---|
| 8 | // of nummer, maar een afspeellijst heet pl.u-LdbqzVvI3go5g -- en gaf null,
|
|---|
| 9 | // waarna embedMediaShortcodes terugviel op de shortcode zelf. Twee fouten dus,
|
|---|
| 10 | // en de tweede maakte de eerste onbegrijpelijk: een lezer ziet geen "dit kan
|
|---|
| 11 | // ik niet", hij ziet rommel.
|
|---|
| 12 | import { test } from 'node:test';
|
|---|
| 13 | import assert from 'node:assert/strict';
|
|---|
| 14 |
|
|---|
| 15 | const { default: AudioEmbedService } = await import('../src/services/AudioEmbedService.js');
|
|---|
| 16 |
|
|---|
| 17 | const PLAYLIST = 'https://music.apple.com/nl/playlist/romance/pl.u-LdbqzVvI3go5g';
|
|---|
| 18 | const ALBUM = 'https://music.apple.com/nl/album/abbey-road/1441164426';
|
|---|
| 19 |
|
|---|
| 20 | test('een afspeellijst wordt een echte iframe, geen shortcode', () => {
|
|---|
| 21 | const out = AudioEmbedService.embedMediaShortcodes(`[[embed:${PLAYLIST}]]`);
|
|---|
| 22 | assert.ok(!out.includes('[[embed:'), 'de shortcode staat er niet meer');
|
|---|
| 23 | assert.match(out, /embed\.music\.apple\.com\/nl\/playlist\/romance\/pl\.u-LdbqzVvI3go5g/);
|
|---|
| 24 | assert.match(out, /<iframe/);
|
|---|
| 25 | });
|
|---|
| 26 |
|
|---|
| 27 | test('een album met een numeriek id blijft werken', () => {
|
|---|
| 28 | // De reparatie mag de vorm die het WEL deed niet kwijtraken.
|
|---|
| 29 | const out = AudioEmbedService.embedMediaShortcodes(`[[embed:${ALBUM}]]`);
|
|---|
| 30 | assert.match(out, /embed\.music\.apple\.com\/nl\/album\/abbey-road\/1441164426/);
|
|---|
| 31 | assert.ok(!out.includes('[[embed:'));
|
|---|
| 32 | });
|
|---|
| 33 |
|
|---|
| 34 | test('wat we niet kunnen bouwen zegt dat, in plaats van de shortcode te tonen', () => {
|
|---|
| 35 | // Herkend als Apple Music (de detectie kijkt tot /playlist/), maar het id is
|
|---|
| 36 | // onbruikbaar. Vroeger: de kale shortcode op de pagina.
|
|---|
| 37 | const raar = 'https://music.apple.com/nl/playlist/romance/@@@';
|
|---|
| 38 | const out = AudioEmbedService.embedMediaShortcodes(`[[embed:${raar}]]`);
|
|---|
| 39 | assert.ok(!out.includes('[[embed:'), 'nooit de shortcode aan de lezer');
|
|---|
| 40 | assert.match(out, /post-embed-missing/);
|
|---|
| 41 | });
|
|---|
| 42 |
|
|---|
| 43 | test('het pad kan niet uit de embed-host breken', () => {
|
|---|
| 44 | // Wat gevangen wordt gaat rechtstreeks achter embed.music.apple.com/ aan,
|
|---|
| 45 | // dus geen slash, vraagteken of hekje in het id.
|
|---|
| 46 | for (const kwaad of [
|
|---|
| 47 | 'https://music.apple.com/nl/playlist/x/pl.a/../../evil',
|
|---|
| 48 | 'https://music.apple.com/nl/playlist/x/pl.a?next=https://evil.example',
|
|---|
| 49 | 'https://music.apple.com/nl/playlist/x/pl.a#https://evil.example',
|
|---|
| 50 | ]) {
|
|---|
| 51 | const out = AudioEmbedService.embedMediaShortcodes(`[[embed:${kwaad}]]`);
|
|---|
| 52 | assert.ok(!/evil\.example/.test(out), `geen vreemde host uit ${kwaad}`);
|
|---|
| 53 | }
|
|---|
| 54 | });
|
|---|