mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 13:00:13 +02:00
temp progress
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { getServerById } from '/@/renderer/store';
|
||||
import {
|
||||
controller as subsonicAdapter,
|
||||
apiClient as subsonicApiClient,
|
||||
middleware as subsonicMiddleware,
|
||||
} from '/@/shared/api/subsonic/subsonic-controller';
|
||||
import { ApiController } from '/@/shared/types/adapter/api-controller-types';
|
||||
import { ServerType } from '/@/shared/types/domain/server-domain-types';
|
||||
|
||||
export const serverApi = {
|
||||
[ServerType.JELLYFIN]: {
|
||||
apiClient: null,
|
||||
controller: {},
|
||||
middleware: null,
|
||||
},
|
||||
[ServerType.NAVIDROME]: {
|
||||
apiClient: null,
|
||||
controller: {},
|
||||
middleware: null,
|
||||
},
|
||||
[ServerType.SUBSONIC]: {
|
||||
apiClient: subsonicApiClient,
|
||||
controller: subsonicAdapter,
|
||||
middleware: subsonicMiddleware,
|
||||
},
|
||||
};
|
||||
|
||||
export const api = (serverId: string): ApiController => {
|
||||
const server = getServerById(serverId);
|
||||
|
||||
if (!server) {
|
||||
throw new Error('No server or api client selected');
|
||||
}
|
||||
|
||||
const { apiClient, controller, middleware } = serverApi[server.type];
|
||||
|
||||
if (middleware) {
|
||||
apiClient.use(middleware(server));
|
||||
}
|
||||
|
||||
if (!apiClient) {
|
||||
throw new Error('No api client found');
|
||||
}
|
||||
|
||||
return controller as ApiController;
|
||||
};
|
||||
@@ -4,11 +4,9 @@ import { NavidromeController } from '/@/renderer/api/navidrome/navidrome-control
|
||||
import { SubsonicController } from '/@/renderer/api/subsonic/subsonic-controller';
|
||||
import { useAuthStore } from '/@/renderer/store';
|
||||
import { toast } from '/@/shared/components/toast/toast';
|
||||
import {
|
||||
AuthenticationResponse,
|
||||
ControllerEndpoint,
|
||||
ServerType,
|
||||
} from '/@/shared/types/domain-types';
|
||||
import { ControllerEndpoint } from '/@/shared/types/domain/api-domain-types';
|
||||
import { AuthenticationResponse } from '/@/shared/types/domain/auth-domain-types';
|
||||
import { ServerType } from '/@/shared/types/domain/server-domain-types';
|
||||
|
||||
type ApiController = {
|
||||
jellyfin: ControllerEndpoint;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { SubsonicController } from '/@/renderer/api/subsonic/subsonic-controller
|
||||
import { NDSongListSort } from '/@/shared/api/navidrome.types';
|
||||
import { ndNormalize } from '/@/shared/api/navidrome/navidrome-normalize';
|
||||
import { ndType } from '/@/shared/api/navidrome/navidrome-types';
|
||||
import { ssNormalize } from '/@/shared/api/subsonic/subsonic-normalize';
|
||||
import { normalize } from '/@/shared/api/subsonic/subsonic-normalize';
|
||||
import { SubsonicExtensions } from '/@/shared/api/subsonic/subsonic-types';
|
||||
import { getFeatures, hasFeature, VersionInfo } from '/@/shared/api/utils';
|
||||
import { albumListSortMap } from '/@/shared/types/domain/album-domain-types';
|
||||
@@ -14,7 +14,7 @@ import { AuthenticationResponse } from '/@/shared/types/domain/auth-domain-types
|
||||
import { genreListSortMap } from '/@/shared/types/domain/genre-domain-types';
|
||||
import {
|
||||
playlistListSortMap,
|
||||
PlaylistSongListArgs,
|
||||
PlaylistSongListRequest,
|
||||
PlaylistSongListResponse,
|
||||
} from '/@/shared/types/domain/playlist-domain-types';
|
||||
import {
|
||||
@@ -424,7 +424,9 @@ export const NavidromeController: ControllerEndpoint = {
|
||||
apiClientProps,
|
||||
query: { ...query, limit: 1, startIndex: 0 },
|
||||
}).then((result) => result!.totalRecordCount!),
|
||||
getPlaylistSongList: async (args: PlaylistSongListArgs): Promise<PlaylistSongListResponse> => {
|
||||
getPlaylistSongList: async (
|
||||
args: PlaylistSongListRequest,
|
||||
): Promise<PlaylistSongListResponse> => {
|
||||
const { apiClientProps, query } = args;
|
||||
|
||||
const res = await ndApiClient(apiClientProps).getPlaylistSongList({
|
||||
@@ -520,7 +522,7 @@ export const NavidromeController: ControllerEndpoint = {
|
||||
if (res.status === 200 && res.body.similarSongs?.song) {
|
||||
const similar = res.body.similarSongs.song.reduce<Song[]>((acc, song) => {
|
||||
if (song.id !== query.songId) {
|
||||
acc.push(ssNormalize.song(song, apiClientProps.server));
|
||||
acc.push(normalize.song(song, apiClientProps.server));
|
||||
}
|
||||
|
||||
return acc;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { z } from 'zod';
|
||||
|
||||
import { contract, ssApiClient } from '/@/renderer/api/subsonic/subsonic-api';
|
||||
import { randomString } from '/@/renderer/utils';
|
||||
import { ssNormalize } from '/@/shared/api/subsonic/subsonic-normalize';
|
||||
import { normalize } from '/@/shared/api/subsonic/subsonic-normalize';
|
||||
import {
|
||||
AlbumListSortType,
|
||||
ssType,
|
||||
@@ -200,11 +200,11 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
}
|
||||
|
||||
return {
|
||||
...ssNormalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
albums: artist.album?.map((album) => ssNormalize.album(album, apiClientProps.server)),
|
||||
...normalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
albums: artist.album?.map((album) => normalize.album(album, apiClientProps.server)),
|
||||
similarArtists:
|
||||
artistInfo?.similarArtist?.map((artist) =>
|
||||
ssNormalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
normalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
) || null,
|
||||
};
|
||||
},
|
||||
@@ -224,7 +224,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
const artists = (res.body.artists?.index || []).flatMap((index) => index.artist);
|
||||
|
||||
let results = artists.map((artist) =>
|
||||
ssNormalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
normalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
);
|
||||
|
||||
if (query.searchTerm) {
|
||||
@@ -260,7 +260,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
throw new Error('Failed to get album detail');
|
||||
}
|
||||
|
||||
return ssNormalize.album(res.body.album, apiClientProps.server);
|
||||
return normalize.album(res.body.album, apiClientProps.server);
|
||||
},
|
||||
getAlbumList: async (args) => {
|
||||
const { apiClientProps, query } = args;
|
||||
@@ -284,7 +284,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
|
||||
const results =
|
||||
res.body.searchResult3?.album?.map((album) =>
|
||||
ssNormalize.album(album, apiClientProps.server),
|
||||
normalize.album(album, apiClientProps.server),
|
||||
) || [];
|
||||
|
||||
return {
|
||||
@@ -319,7 +319,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
return artist.body.artist.album ?? [];
|
||||
});
|
||||
|
||||
const items = albums.map((album) => ssNormalize.album(album, apiClientProps.server));
|
||||
const items = albums.map((album) => normalize.album(album, apiClientProps.server));
|
||||
|
||||
return {
|
||||
items: sortAlbumList(items, query.sortBy, query.sortOrder),
|
||||
@@ -341,7 +341,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
|
||||
const results =
|
||||
res.body.starred?.album?.map((album) =>
|
||||
ssNormalize.album(album, apiClientProps.server),
|
||||
normalize.album(album, apiClientProps.server),
|
||||
) || [];
|
||||
|
||||
return {
|
||||
@@ -404,7 +404,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
return {
|
||||
items:
|
||||
res.body.albumList2.album?.map((album) =>
|
||||
ssNormalize.album(album, apiClientProps.server, 300),
|
||||
normalize.album(album, apiClientProps.server, 300),
|
||||
) || [],
|
||||
startIndex: query.startIndex,
|
||||
totalRecordCount: null,
|
||||
@@ -574,7 +574,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
}
|
||||
|
||||
let results = artists.map((artist) =>
|
||||
ssNormalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
normalize.albumArtist(artist, apiClientProps.server, 300),
|
||||
);
|
||||
|
||||
if (query.searchTerm) {
|
||||
@@ -635,7 +635,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
break;
|
||||
}
|
||||
|
||||
const genres = results.map(ssNormalize.genre);
|
||||
const genres = results.map(normalize.genre);
|
||||
|
||||
return {
|
||||
items: genres,
|
||||
@@ -674,7 +674,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
throw new Error('Failed to get playlist detail');
|
||||
}
|
||||
|
||||
return ssNormalize.playlist(res.body.playlist, apiClientProps.server);
|
||||
return normalize.playlist(res.body.playlist, apiClientProps.server);
|
||||
},
|
||||
getPlaylistList: async ({ apiClientProps, query }) => {
|
||||
const sortOrder = query.sortOrder.toLowerCase() as 'asc' | 'desc';
|
||||
@@ -719,7 +719,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
}
|
||||
|
||||
return {
|
||||
items: results.map((playlist) => ssNormalize.playlist(playlist, apiClientProps.server)),
|
||||
items: results.map((playlist) => normalize.playlist(playlist, apiClientProps.server)),
|
||||
startIndex: 0,
|
||||
totalRecordCount: results.length,
|
||||
};
|
||||
@@ -755,7 +755,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
}
|
||||
|
||||
let results =
|
||||
res.body.playlist.entry?.map((song) => ssNormalize.song(song, apiClientProps.server)) ||
|
||||
res.body.playlist.entry?.map((song) => normalize.song(song, apiClientProps.server)) ||
|
||||
[];
|
||||
|
||||
if (query.sortBy && query.sortOrder) {
|
||||
@@ -788,7 +788,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
const results = res.body.randomSongs?.song || [];
|
||||
|
||||
return {
|
||||
items: results.map((song) => ssNormalize.song(song, apiClientProps.server)),
|
||||
items: results.map((song) => normalize.song(song, apiClientProps.server)),
|
||||
startIndex: 0,
|
||||
totalRecordCount: res.body.randomSongs?.song?.length || 0,
|
||||
};
|
||||
@@ -873,7 +873,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
|
||||
return res.body.similarSongs.song.reduce<Song[]>((acc, song) => {
|
||||
if (song.id !== query.songId) {
|
||||
acc.push(ssNormalize.song(song, apiClientProps.server));
|
||||
acc.push(normalize.song(song, apiClientProps.server));
|
||||
}
|
||||
|
||||
return acc;
|
||||
@@ -892,7 +892,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
throw new Error('Failed to get song detail');
|
||||
}
|
||||
|
||||
return ssNormalize.song(res.body.song, apiClientProps.server);
|
||||
return normalize.song(res.body.song, apiClientProps.server);
|
||||
},
|
||||
getSongList: async ({ apiClientProps, query }) => {
|
||||
const fromAlbumPromises: Promise<ServerInferResponses<typeof contract.getAlbum>>[] = [];
|
||||
@@ -918,7 +918,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
return {
|
||||
items:
|
||||
res.body.searchResult3?.song?.map((song) =>
|
||||
ssNormalize.song(song, apiClientProps.server),
|
||||
normalize.song(song, apiClientProps.server),
|
||||
) || [],
|
||||
startIndex: query.startIndex,
|
||||
totalRecordCount: null,
|
||||
@@ -942,7 +942,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
const results = res.body.songsByGenre?.song || [];
|
||||
|
||||
return {
|
||||
items: results.map((song) => ssNormalize.song(song, apiClientProps.server)) || [],
|
||||
items: results.map((song) => normalize.song(song, apiClientProps.server)) || [],
|
||||
startIndex: 0,
|
||||
totalRecordCount: null,
|
||||
};
|
||||
@@ -961,7 +961,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
|
||||
const results =
|
||||
(res.body.starred?.song || []).map((song) =>
|
||||
ssNormalize.song(song, apiClientProps.server),
|
||||
normalize.song(song, apiClientProps.server),
|
||||
) || [];
|
||||
|
||||
return {
|
||||
@@ -1035,7 +1035,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
}
|
||||
|
||||
return {
|
||||
items: results.map((song) => ssNormalize.song(song, apiClientProps.server)),
|
||||
items: results.map((song) => normalize.song(song, apiClientProps.server)),
|
||||
startIndex: 0,
|
||||
totalRecordCount: results.length,
|
||||
};
|
||||
@@ -1060,7 +1060,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
return {
|
||||
items:
|
||||
res.body.searchResult3?.song?.map((song) =>
|
||||
ssNormalize.song(song, apiClientProps.server),
|
||||
normalize.song(song, apiClientProps.server),
|
||||
) || [],
|
||||
startIndex: 0,
|
||||
totalRecordCount: null,
|
||||
@@ -1297,7 +1297,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
return {
|
||||
items:
|
||||
res.body.topSongs?.song?.map((song) =>
|
||||
ssNormalize.song(song, apiClientProps.server),
|
||||
normalize.song(song, apiClientProps.server),
|
||||
) || [],
|
||||
startIndex: 0,
|
||||
totalRecordCount: res.body.topSongs?.song?.length || 0,
|
||||
@@ -1367,13 +1367,13 @@ export const SubsonicController: ControllerEndpoint = {
|
||||
|
||||
return {
|
||||
albumArtists: (res.body.searchResult3?.artist || [])?.map((artist) =>
|
||||
ssNormalize.albumArtist(artist, apiClientProps.server),
|
||||
normalize.albumArtist(artist, apiClientProps.server),
|
||||
),
|
||||
albums: (res.body.searchResult3?.album || []).map((album) =>
|
||||
ssNormalize.album(album, apiClientProps.server),
|
||||
normalize.album(album, apiClientProps.server),
|
||||
),
|
||||
songs: (res.body.searchResult3?.song || []).map((song) =>
|
||||
ssNormalize.song(song, apiClientProps.server),
|
||||
normalize.song(song, apiClientProps.server),
|
||||
),
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user