mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-07-27 16:12:29 +02:00
Added an API to add & delete entries from the skippedArtists list in the settings. fixes [#405]
This commit is contained in:
39
src/features/api/features/settings/settings.ts
Normal file
39
src/features/api/features/settings/settings.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Request, Router } from "express";
|
||||
import { settings } from "../../../../constants/settings";
|
||||
import { mediaInfo } from "../../../../scripts/mediaInfo";
|
||||
import {
|
||||
addSkippedArtists,
|
||||
removeSkippedArtists,
|
||||
settingsStore,
|
||||
} from "../../../../scripts/settings";
|
||||
import { BrowserWindow } from "electron";
|
||||
import { globalEvents } from "../../../../constants/globalEvents";
|
||||
|
||||
export const addSettingsAPI = (expressApp: Router, mainWindow: BrowserWindow) => {
|
||||
expressApp.get("/settings/skipped-artists", (req, res) => {
|
||||
res.json(settingsStore.get<string, string[]>(settings.skippedArtists));
|
||||
});
|
||||
|
||||
expressApp.post("/settings/skipped-artists", (req: Request<object, object, string[]>, res) => {
|
||||
addSkippedArtists(req.body);
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
expressApp.post(
|
||||
"/settings/skipped-artists/delete",
|
||||
(req: Request<object, object, string[]>, res) => {
|
||||
removeSkippedArtists(req.body);
|
||||
res.sendStatus(200);
|
||||
}
|
||||
);
|
||||
|
||||
expressApp.post("/settings/skipped-artists/current", (req, res) => {
|
||||
addSkippedArtists([mediaInfo.artists]);
|
||||
mainWindow.webContents.send("globalEvent", globalEvents.next);
|
||||
res.sendStatus(200);
|
||||
});
|
||||
expressApp.delete("/settings/skipped-artists/current", (req, res) => {
|
||||
removeSkippedArtists([mediaInfo.artists]);
|
||||
res.sendStatus(200);
|
||||
});
|
||||
};
|
@@ -4,6 +4,7 @@ import { settings } from "../../constants/settings";
|
||||
import { settingsStore } from "../../scripts/settings";
|
||||
import { addCurrentInfo } from "./features/current";
|
||||
import { addPlaybackControl } from "./features/player";
|
||||
import { addSettingsAPI } from "./features/settings/settings";
|
||||
import { addLegacyApi } from "./legacy";
|
||||
|
||||
/**
|
||||
@@ -11,12 +12,14 @@ import { addLegacyApi } from "./legacy";
|
||||
*/
|
||||
export const startApi = (mainWindow: BrowserWindow) => {
|
||||
const expressApp = express();
|
||||
expressApp.use(express.json());
|
||||
expressApp.get("/", (req, res) => res.send("Hello World!"));
|
||||
|
||||
// add features
|
||||
addLegacyApi(expressApp, mainWindow);
|
||||
addPlaybackControl(expressApp, mainWindow);
|
||||
addCurrentInfo(expressApp);
|
||||
addSettingsAPI(expressApp, mainWindow);
|
||||
|
||||
const port = settingsStore.get<string, number>(settings.apiSettings.port);
|
||||
const expressInstance = expressApp.listen(port, "127.0.0.1");
|
||||
|
@@ -159,3 +159,25 @@ export const hideSettingsWindow = function () {
|
||||
export const closeSettingsWindow = function () {
|
||||
settingsWindow = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* add artists to the list of skipped artists
|
||||
* @param artists list of artists to append
|
||||
*/
|
||||
export const addSkippedArtists = (artists: string[]) => {
|
||||
const { skippedArtists } = settings;
|
||||
const previousStoreValue = settingsStore.get<string, string[]>(skippedArtists);
|
||||
settingsStore.set(skippedArtists, Array.from(new Set([...previousStoreValue, ...artists])));
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove artists from the list of skipped artists
|
||||
* @param artists list of artists to remove
|
||||
*/
|
||||
export const removeSkippedArtists = (artists: string[]) => {
|
||||
const { skippedArtists } = settings;
|
||||
const previousStoreValue = settingsStore.get<string, string[]>(skippedArtists);
|
||||
const filteredArtists = previousStoreValue.filter((value) => !artists.includes(value));
|
||||
|
||||
settingsStore.set(skippedArtists, filteredArtists);
|
||||
};
|
||||
|
Reference in New Issue
Block a user