| 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 | });
|
|---|
| 55 |
|
|---|
| 56 | // ── De hoogte hoort bij wat je insluit (Bart, 20-8) ─────────────────────────
|
|---|
| 57 | // Op boiert.eu/the-mixtape stond een afspeellijst in een venster van 175px: de
|
|---|
| 58 | // maat van een LOS NUMMER. Je zag ongeveer een derde, en `overflow:hidden`
|
|---|
| 59 | // maakte de rest ook nog onbereikbaar.
|
|---|
| 60 | //
|
|---|
| 61 | // 450 is niet uit de documentatie overgenomen maar nagemeten: de embed-pagina
|
|---|
| 62 | // van pl.u-LdbqzVvI3go5g geeft zijn <main> en <body> allebei precies 450px.
|
|---|
| 63 | test('een afspeellijst krijgt 450px, niet de hoogte van een los nummer', () => {
|
|---|
| 64 | const html = AudioEmbedService.generateIframe('applemusic',
|
|---|
| 65 | { url: 'https://music.apple.com/nl/playlist/romance/pl.u-LdbqzVvI3go5g' });
|
|---|
| 66 | assert.match(html, /height:450px/, 'een lijst is 450 hoog');
|
|---|
| 67 | assert.ok(!/height:175px/.test(html), 'en zeker niet 175');
|
|---|
| 68 | });
|
|---|
| 69 |
|
|---|
| 70 | test('een album ook: dat is dezelfde speler met een lijst erin', () => {
|
|---|
| 71 | const html = AudioEmbedService.generateIframe('applemusic',
|
|---|
| 72 | { url: 'https://music.apple.com/nl/album/blue/1440857781' });
|
|---|
| 73 | assert.match(html, /height:450px/);
|
|---|
| 74 | });
|
|---|
| 75 |
|
|---|
| 76 | test('een los nummer blijft klein', () => {
|
|---|
| 77 | const html = AudioEmbedService.generateIframe('applemusic',
|
|---|
| 78 | { url: 'https://music.apple.com/nl/song/blue/1440857785' });
|
|---|
| 79 | assert.match(html, /height:175px/, 'een enkel nummer heeft geen lijst te tonen');
|
|---|
| 80 | });
|
|---|
| 81 |
|
|---|
| 82 | test('en de soort wordt uit de URL gelezen, niet geraden', () => {
|
|---|
| 83 | // Dezelfde id-vorm, ander soort: alleen het woord in het pad mag beslissen.
|
|---|
| 84 | const lijst = AudioEmbedService.generateIframe('applemusic',
|
|---|
| 85 | { url: 'https://music.apple.com/us/playlist/x/pl.abc123def456' });
|
|---|
| 86 | const nummer = AudioEmbedService.generateIframe('applemusic',
|
|---|
| 87 | { url: 'https://music.apple.com/us/song/x/123456789' });
|
|---|
| 88 | assert.match(lijst, /height:450px/);
|
|---|
| 89 | assert.match(nummer, /height:175px/);
|
|---|
| 90 | });
|
|---|