From 6b8db53c1ba9e020e049128deeac06186e4b4675 Mon Sep 17 00:00:00 2001 From: Thomas Amland Date: Sun, 27 Aug 2023 16:18:35 +0200 Subject: [PATCH] add/edit/delete radio stations closes https://github.com/tamland/airsonic-refix/pull/106 --- src/library/radio/RadioStations.vue | 68 ++++++++++++++++++++++++++++- src/shared/api.ts | 27 ++++++------ src/shared/utils.ts | 1 + 3 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/library/radio/RadioStations.vue b/src/library/radio/RadioStations.vue index 86ab88a..1e9928e 100644 --- a/src/library/radio/RadioStations.vue +++ b/src/library/radio/RadioStations.vue @@ -1,26 +1,68 @@ diff --git a/src/shared/api.ts b/src/shared/api.ts index df7597c..6f22681 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -320,29 +320,29 @@ export class API { .map(this.normalizeRadioStation, this) } - async addRadioStation(title: string, url: string): Promise { + async addRadioStation(title: string, url: string, description?: string): Promise { const params = { - name: title, + name: title ?? '', streamUrl: url, + homepageUrl: description?.trim() === '' ? undefined : description, } - return this - .fetch('rest/createInternetRadioStation', params) - .then(this.normalizeRadioStation) + await this.fetch('rest/createInternetRadioStation', params) + return await this.getRadioStations() } - async updateRadioStation(item: RadioStation): Promise { + async updateRadioStation(item: RadioStation): Promise { const params = { - id: item.id, - name: item.title, + id: item.id.replace('radio-', ''), + name: item.title ?? '', streamUrl: item.url, + homepageUrl: item.description?.trim() === '' ? undefined : item.description } - return this - .fetch('rest/updateInternetRadioStation', params) - .then(this.normalizeRadioStation) + await this.fetch('rest/updateInternetRadioStation', params) + return await this.getRadioStations() } async deleteRadioStation(id: string): Promise { - return this.fetch('rest/deleteInternetRadioStation', { id }) + return this.fetch('rest/deleteInternetRadioStation', { id: id.replace('radio-', '') }) } async getPodcasts(): Promise { @@ -383,7 +383,8 @@ export class API { return { id: `radio-${item.id}`, title: item.name, - description: item.homePageUrl, + // Workaround: airsonic-advanced does not use correct name + description: item.homepageUrl || item.homePageUrl, album: item.name, track: item.track, url: item.streamUrl, diff --git a/src/shared/utils.ts b/src/shared/utils.ts index e666fdb..85169e9 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -45,6 +45,7 @@ export function trackListEquals(a: Track[], b: Track[]): boolean { export function toQueryString(params: Record): string { const list = Object.entries(params) + .filter(([, value]) => value !== undefined) .map(([key, value]) => Array.isArray(value) ? value.map((x) => [key, x]) : [[key, value]]) .flat() return new URLSearchParams(list).toString()