Files
feishin/src/renderer/utils/resolve-song-path.ts
T
jeffvli 61cc87e0b7 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
2026-06-19 22:02:25 -07:00

27 lines
816 B
TypeScript

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]);
};