From 71b307e4a6c0b06b617094777819e630375a9e7e Mon Sep 17 00:00:00 2001 From: jeffvli Date: Mon, 7 Jul 2025 21:11:52 -0700 Subject: [PATCH] add new api controller types --- .../types/adapter/api-controller-types.ts | 193 ++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 src/shared/types/adapter/api-controller-types.ts diff --git a/src/shared/types/adapter/api-controller-types.ts b/src/shared/types/adapter/api-controller-types.ts new file mode 100644 index 000000000..0f2533fd2 --- /dev/null +++ b/src/shared/types/adapter/api-controller-types.ts @@ -0,0 +1,193 @@ +import { + AlbumDetailArgs, + AlbumDetailResponse, + AlbumInfo, + AlbumListArgs, + AlbumListResponse, +} from '/@/shared/types/domain/album-domain-types'; +import { BaseEndpointArgs } from '/@/shared/types/domain/api-domain-types'; +import { + AlbumArtistDetailArgs, + AlbumArtistDetailResponse, + AlbumArtistListArgs, + AlbumArtistListResponse, + ArtistListArgs, + ArtistListResponse, +} from '/@/shared/types/domain/artist-domain-types'; +import { AuthenticationResponse } from '/@/shared/types/domain/auth-domain-types'; +import { GenreListArgs, GenreListResponse } from '/@/shared/types/domain/genre-domain-types'; +import { + LyricsArgs, + LyricsResponse, + StructuredLyric, + StructuredLyricsArgs, +} from '/@/shared/types/domain/lyric-domain-types'; +import { TranscodingArgs } from '/@/shared/types/domain/player-domain-types'; +import { + AddToPlaylistArgs, + AddToPlaylistResponse, + CreatePlaylistArgs, + CreatePlaylistResponse, + DeletePlaylistArgs, + DeletePlaylistResponse, + MoveItemArgs, + PlaylistDetailArgs, + PlaylistDetailResponse, + PlaylistListArgs, + PlaylistListResponse, + PlaylistSongListArgs, + RemoveFromPlaylistArgs, + RemoveFromPlaylistResponse, + UpdatePlaylistArgs, + UpdatePlaylistResponse, +} from '/@/shared/types/domain/playlist-domain-types'; +import { SearchArgs, SearchResponse } from '/@/shared/types/domain/search-domain-types'; +import { + ServerInfo, + ServerInfoArgs, + ServerListItem, + ServerMusicFolderListArgs, + ServerMusicFolderListResponse, + ServerType, +} from '/@/shared/types/domain/server-domain-types'; +import { LibraryItem } from '/@/shared/types/domain/shared-domain-types'; +import { + RandomSongListArgs, + SimilarSongsArgs, + Song, + SongDetailArgs, + SongDetailResponse, + SongListArgs, + SongListResponse, + TopSongListArgs, + TopSongListResponse, +} from '/@/shared/types/domain/song-domain-types'; +import { TagArgs, TagsResponse } from '/@/shared/types/domain/tag-domain-types'; +import { + DownloadArgs, + FavoriteArgs, + FavoriteResponse, + RatingResponse, + ScrobbleArgs, + ScrobbleResponse, + SetRatingArgs, + ShareItemArgs, + ShareItemResponse, + UserListArgs, + UserListResponse, +} from '/@/shared/types/domain/user-domain-types'; + +export interface AdapterError { + code: number; + message: string; +} + +export type AdapterFn = ( + request: TRequest, + server: ServerListItem, + options?: AdapterRequestOptions, +) => Promise<[AdapterError, null] | [null, TResponse]>; + +export interface AdapterRequestOptions { + cache?: 'default' | 'force-cache' | 'no-cache' | 'no-store' | 'only-if-cached' | 'reload'; + credentials?: 'include' | 'omit' | 'same-origin'; + integrity?: string; + keepalive?: boolean; + mode?: 'cors' | 'navigate' | 'no-cors' | 'same-origin'; + priority?: 'auto' | 'high' | 'low'; + redirect?: 'error' | 'follow' | 'manual'; + referrer?: string; + referrerPolicy?: + | '' + | 'no-referrer' + | 'no-referrer-when-downgrade' + | 'origin' + | 'origin-when-cross-origin' + | 'same-origin' + | 'strict-origin' + | 'strict-origin-when-cross-origin' + | 'unsafe-url'; + signal?: AbortSignal | null; + window?: null; +} + +export type ControllerEndpoint = { + album: { + getDetail: (args: AlbumDetailArgs) => Promise; + getInfo?: (args: AlbumDetailArgs) => Promise; + getList: (args: AlbumListArgs) => Promise; + getListCount: (args: AlbumListArgs) => Promise; + }; + albumArtist: { + getDetail: (args: AlbumArtistDetailArgs) => Promise; + getList: (args: AlbumArtistListArgs) => Promise; + getListCount: (args: AlbumArtistListArgs) => Promise; + }; + artist: { + getList: (args: ArtistListArgs) => Promise; + getListCount: (args: ArtistListArgs) => Promise; + }; + favorite: { + create: (args: FavoriteArgs) => Promise; + delete: (args: FavoriteArgs) => Promise; + }; + genre: { + getList: (args: GenreListArgs) => Promise; + }; + musicFolder: { + getList: (args: ServerMusicFolderListArgs) => Promise; + }; + playlist: { + addTo: (args: AddToPlaylistArgs) => Promise; + create: (args: CreatePlaylistArgs) => Promise; + delete: (args: DeletePlaylistArgs) => Promise; + getDetail: (args: PlaylistDetailArgs) => Promise; + getList: (args: PlaylistListArgs) => Promise; + getListCount: (args: PlaylistListArgs) => Promise; + getSongList: (args: PlaylistSongListArgs) => Promise; + moveItem?: (args: MoveItemArgs) => Promise; + removeFrom: (args: RemoveFromPlaylistArgs) => Promise; + update: (args: UpdatePlaylistArgs) => Promise; + }; + server: { + authenticate: ( + url: string, + body: { legacy?: boolean; password: string; username: string }, + ) => Promise; + getCoverArtUrl: ( + args: { id: string; size?: number; type: LibraryItem }, + server: ServerListItem, + ) => string; + getRoles: ( + args: BaseEndpointArgs, + ) => Promise>; + getServerInfo: (args: ServerInfoArgs) => Promise; + getStreamUrl: ( + args: { bitRate?: number; format?: string; id: string }, + server: ServerListItem, + ) => string; + getTags: (args: TagArgs) => Promise; + getTranscodingUrl: (args: TranscodingArgs) => string; + getType: () => ServerType; + scrobble: (args: ScrobbleArgs) => Promise; + search: (args: SearchArgs) => Promise; + }; + song: { + getDetail: (args: SongDetailArgs) => Promise; + getDownloadUrl: (args: DownloadArgs) => string; + getList: (args: SongListArgs) => Promise; + getListCount: (args: SongListArgs) => Promise; + getLyrics?: (args: LyricsArgs) => Promise; + getRandomList: (args: RandomSongListArgs) => Promise; + getSimilar: (args: SimilarSongsArgs) => Promise; + getStructuredLyrics?: (args: StructuredLyricsArgs) => Promise; + getTopList: (args: TopSongListArgs) => Promise; + }; + user: { + getList?: (args: UserListArgs) => Promise; + setRating?: (args: SetRatingArgs) => Promise; + shareItem?: (args: ShareItemArgs) => Promise; + }; +}; + +export type ExtractAdapterResponse = T extends AdapterFn ? R : never;