From c404dd5396d0c61e72c0460987f65afa09a4130a Mon Sep 17 00:00:00 2001 From: Exerra Date: Tue, 14 Jul 2026 01:03:26 +0300 Subject: [PATCH] feat(applemusic): add support for custom headers in API requests Introduced a `headers` configuration option to allow setting custom request headers, such as 'Origin', for Apple Music API requests. Updated configuration schema and source implementation to apply these headers. --- config/applemusic.json.example | 27 +++++++++++++++++++ .../config/source/applemusic.ts | 8 +++++- src/backend/sources/AppleMusicSource.ts | 5 ++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 config/applemusic.json.example diff --git a/config/applemusic.json.example b/config/applemusic.json.example new file mode 100644 index 00000000..33193712 --- /dev/null +++ b/config/applemusic.json.example @@ -0,0 +1,27 @@ +[ + { + "id": "myAppleMusic", + "name": "My Apple Music", + "enable": true, + "clients": [], + "data": { + // either key or token needs to be provided + "key": { + "id": "2HPSNJZ88N", + "teamId": "SN6YASW8G4", + "p8": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEG...-----END PRIVATE KEY-----" + }, + "token": "your-jwt-token-here", + "mediaUserToken": "your-media-user-token-here", + // optional: custom headers for API requests (e.g. Origin) + //"headers": { + // "Origin": "https://music.apple.com" + //} + // optional: polling interval in seconds (default 60) + //"interval": 60 + }, + "options": { + "logDiff": true + } + } +] diff --git a/src/backend/common/infrastructure/config/source/applemusic.ts b/src/backend/common/infrastructure/config/source/applemusic.ts index 9b2aff8b..333dcb65 100644 --- a/src/backend/common/infrastructure/config/source/applemusic.ts +++ b/src/backend/common/infrastructure/config/source/applemusic.ts @@ -11,7 +11,13 @@ export interface AppleMusicData extends CommonSourceData, PollingOptions { key?: AppleMusicKey token?: string mediaUserToken?: string - storefront?: string + /** + * Custom headers to include in every Apple Music API request. + * Useful for setting Origin header, etc. + * + * @examples [{"Origin": "https://music.apple.com"}] + */ + headers?: Record } export interface AppleMusicSourceConfig extends CommonSourceConfig { diff --git a/src/backend/sources/AppleMusicSource.ts b/src/backend/sources/AppleMusicSource.ts index 2549ef8a..8fc0b3fe 100644 --- a/src/backend/sources/AppleMusicSource.ts +++ b/src/backend/sources/AppleMusicSource.ts @@ -53,6 +53,7 @@ export default class AppleMusicSource extends AbstractSource { key, token, mediaUserToken, + headers, } = this.config.data || {}; if (!key && !token) { @@ -72,6 +73,10 @@ export default class AppleMusicSource extends AbstractSource { this.musicKit.token = token!; } + if (headers) { + this.musicKit.headers = headers; + } + return true; } -- 2.51.2