mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 21:16:17 +02:00
Handle album add with local creds
This commit is contained in:
@@ -1,16 +1,21 @@
|
|||||||
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { api } from '@/renderer/api';
|
import { api } from '@/renderer/api';
|
||||||
|
import { queryKeys } from '@/renderer/api/query-keys';
|
||||||
|
import { useServerCredential } from '@/renderer/features/shared';
|
||||||
|
import { useAuthStore, usePlayerStore } from '@/renderer/store';
|
||||||
import { LibraryItem, Play } from '@/renderer/types';
|
import { LibraryItem, Play } from '@/renderer/types';
|
||||||
import { useAuthStore, usePlayerStore } from '../../../store';
|
|
||||||
import { mpvPlayer } from '../utils/mpvPlayer';
|
import { mpvPlayer } from '../utils/mpvPlayer';
|
||||||
|
|
||||||
export const usePlayQueueHandler = () => {
|
export const usePlayQueueHandler = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const serverId = useAuthStore((state) => state.currentServer?.id) || '';
|
const serverId = useAuthStore((state) => state.currentServer?.id) || '';
|
||||||
|
const { serverToken, isImageTokenRequired } = useServerCredential();
|
||||||
const addToQueue = usePlayerStore((state) => state.addToQueue);
|
const addToQueue = usePlayerStore((state) => state.addToQueue);
|
||||||
|
|
||||||
const handlePlayQueueAdd = async (options: {
|
const handlePlayQueueAdd = async (options: {
|
||||||
byData?: any[];
|
byData?: any[];
|
||||||
byItemType?: {
|
byItemType?: {
|
||||||
id: number;
|
id: string;
|
||||||
type: LibraryItem;
|
type: LibraryItem;
|
||||||
};
|
};
|
||||||
play: Play;
|
play: Play;
|
||||||
@@ -21,52 +26,38 @@ export const usePlayQueueHandler = () => {
|
|||||||
|
|
||||||
if (options.byItemType) {
|
if (options.byItemType) {
|
||||||
const deviceId = localStorage.getItem('device_id');
|
const deviceId = localStorage.getItem('device_id');
|
||||||
// const { state } = JSON.parse(
|
|
||||||
// localStorage.getItem('authentication') || '{}'
|
|
||||||
// );
|
|
||||||
|
|
||||||
if (!deviceId) return;
|
if (!deviceId || !options.byItemType.id) return;
|
||||||
|
|
||||||
let songs = null;
|
let songs = null;
|
||||||
if (options.byItemType.type === LibraryItem.ALBUM) {
|
if (options.byItemType.type === LibraryItem.ALBUM) {
|
||||||
const { data } = await api.albums.getAlbumDetail({
|
const albumDetail = await queryClient.fetchQuery(
|
||||||
albumId: options.byItemType.id,
|
queryKeys.albums.detail(options.byItemType.id),
|
||||||
serverId,
|
async () =>
|
||||||
});
|
api.albums.getAlbumDetail({
|
||||||
|
albumId: options.byItemType!.id,
|
||||||
|
serverId,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
songs = data.songs;
|
songs = albumDetail.data.songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const endpoint = getEndpointByItemType(options.byItemType.type);
|
|
||||||
|
|
||||||
// const { data } = await endpoint({
|
|
||||||
// albumId: options.byItemType.id,
|
|
||||||
// serverId,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const songs = data.songs?.map((song) => {
|
|
||||||
// const auth = getServerFolderAuth(
|
|
||||||
// state.serverUrl,
|
|
||||||
// song.serverFolderId
|
|
||||||
// );
|
|
||||||
|
|
||||||
// if (auth) {
|
|
||||||
// const streamUrl =
|
|
||||||
// auth.type === 'jellyfin'
|
|
||||||
// ? getJellyfinStreamUrl(auth, song, deviceId)
|
|
||||||
// : getSubsonicStreamUrl(auth, song, deviceId);
|
|
||||||
|
|
||||||
// return {
|
|
||||||
// ...song,
|
|
||||||
// streamUrl,
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return song;
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (!songs) return;
|
if (!songs) return;
|
||||||
|
|
||||||
|
// * Adds server token
|
||||||
|
if (serverToken) {
|
||||||
|
songs = songs.map((song) => {
|
||||||
|
return {
|
||||||
|
...song,
|
||||||
|
imageUrl: isImageTokenRequired
|
||||||
|
? `${song.imageUrl}${serverToken}`
|
||||||
|
: song.imageUrl,
|
||||||
|
streamUrl: `${song.streamUrl}${serverToken}`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const playerData = addToQueue(songs, options.play);
|
const playerData = addToQueue(songs, options.play);
|
||||||
|
|
||||||
if (options.play === Play.NEXT || options.play === Play.LAST) {
|
if (options.play === Play.NEXT || options.play === Play.LAST) {
|
||||||
|
|||||||
Reference in New Issue
Block a user