refactor song path replacement

- path replacement during runtime instead of during API normalization
- fix Navidrome API path not appending libraryPath which caused inconsistency between ND and Subsonic paths
This commit is contained in:
jeffvli
2026-06-19 22:02:12 -07:00
parent 36624350f6
commit 61cc87e0b7
15 changed files with 119 additions and 398 deletions
+26
View File
@@ -0,0 +1,26 @@
import { useMemo } from 'react';
import { usePathReplace, useSettingsStore } from '/@/renderer/store/settings.store';
import { replacePathPrefix } from '/@/shared/api/utils';
export const resolveSongPath = (path: null | string | undefined): null | string => {
if (!path) {
return null;
}
const { pathReplace, pathReplaceWith } = useSettingsStore.getState().general;
return replacePathPrefix(path, pathReplace, pathReplaceWith);
};
export const useResolvedSongPath = (path: null | string | undefined): null | string => {
const { pathReplace, pathReplaceWith } = usePathReplace();
return useMemo(() => {
if (!path) {
return null;
}
return replacePathPrefix(path, pathReplace, pathReplaceWith);
}, [path, pathReplace, pathReplaceWith]);
};