mirror of
https://github.com/jeffvli/feishin.git
synced 2026-08-10 14:23:18 +02:00
add initial files
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { api } from 'renderer/lib';
|
||||
import { AlbumsResponse, BasePaginationRequest } from './types';
|
||||
|
||||
export interface AlbumsRequest extends BasePaginationRequest {
|
||||
orderBy: string;
|
||||
serverFolderIds?: string;
|
||||
sortBy: string;
|
||||
}
|
||||
|
||||
const getAlbum = async (params: { id: number }, signal?: AbortSignal) => {
|
||||
const { data } = await api.get<AlbumsResponse>(`/albums/${params.id}`, {
|
||||
signal,
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
const getAlbums = async (params: AlbumsRequest, signal?: AbortSignal) => {
|
||||
const { data } = await api.get<AlbumsResponse>(`/albums`, {
|
||||
params,
|
||||
signal,
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
export const albumsApi = {
|
||||
getAlbum,
|
||||
getAlbums,
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
// import axios from 'axios';
|
||||
import axios from 'axios';
|
||||
import { LoginResponse, PingResponse } from './types';
|
||||
|
||||
const login = async (
|
||||
serverUrl: string,
|
||||
body: {
|
||||
password: string;
|
||||
username: string;
|
||||
}
|
||||
) => {
|
||||
const { data } = await axios.post<LoginResponse>(
|
||||
`${serverUrl}/api/auth/login`,
|
||||
body
|
||||
);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const ping = async (serverUrl: string) => {
|
||||
const { data } = await axios.get<PingResponse>(`${serverUrl}/api/auth/ping`, {
|
||||
timeout: 2000,
|
||||
});
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const refresh = async (serverUrl: string, body: { refreshToken: string }) => {
|
||||
const { data } = await axios.post(`${serverUrl}/api/auth/refresh`, body);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const authApi = {
|
||||
login,
|
||||
ping,
|
||||
refresh,
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useQuery } from 'react-query';
|
||||
import { albumsApi } from '../albumsApi';
|
||||
import { queryKeys } from '../queryKeys';
|
||||
|
||||
export const useAlbum = (albumId: number) => {
|
||||
return useQuery({
|
||||
queryFn: () => albumsApi.getAlbum(albumId),
|
||||
queryKey: queryKeys.album(albumId),
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
import { AlbumsRequest } from './albumsApi';
|
||||
|
||||
export const queryKeys = {
|
||||
album: (albumId: number) => ['album', albumId] as const,
|
||||
albums: (params: AlbumsRequest) => ['albums', params] as const,
|
||||
ping: (url: string) => ['ping', url] as const,
|
||||
servers: ['servers'] as const,
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import { api } from 'renderer/lib';
|
||||
|
||||
const getServers = async () => {
|
||||
const { data } = await api.get<any[]>('/servers');
|
||||
return data;
|
||||
};
|
||||
|
||||
const createServer = async (body: {
|
||||
name: string;
|
||||
remoteUserId: string;
|
||||
token: string;
|
||||
url: string;
|
||||
username: string;
|
||||
}) => {
|
||||
const { data } = await api.post<any>('/servers', body);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const serversApi = {
|
||||
createServer,
|
||||
getServers,
|
||||
};
|
||||
@@ -0,0 +1,162 @@
|
||||
export interface BaseResponse<T> {
|
||||
data: T;
|
||||
error?: string | any;
|
||||
response: 'Success' | 'Error';
|
||||
statusCode: number;
|
||||
}
|
||||
|
||||
export interface BasePaginatedResponse<T> {
|
||||
data: T;
|
||||
error?: string | any;
|
||||
pagination: {
|
||||
nextPage: string | null;
|
||||
prevPage: string | null;
|
||||
startIndex: number;
|
||||
totalEntries: number;
|
||||
};
|
||||
response: 'Success' | 'Error';
|
||||
statusCode: number;
|
||||
}
|
||||
|
||||
export interface BasePaginationRequest {
|
||||
limit: number;
|
||||
page: number;
|
||||
}
|
||||
|
||||
export type ServerResponse = {
|
||||
createdAt: string;
|
||||
id: number;
|
||||
name: string;
|
||||
remoteUserId: string;
|
||||
serverFolder?: ServerFolderResponse[];
|
||||
serverType: string;
|
||||
token: string;
|
||||
updatedAt: string;
|
||||
url: string;
|
||||
username: string;
|
||||
};
|
||||
|
||||
export type ServerFolderResponse = {
|
||||
createdAt: string;
|
||||
enabled: boolean;
|
||||
id: number;
|
||||
isPublic: boolean;
|
||||
name: string;
|
||||
remoteId: string;
|
||||
serverId: number;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type User = {
|
||||
createdAt: string;
|
||||
enabled: boolean;
|
||||
id: number;
|
||||
isAdmin: boolean;
|
||||
password: string;
|
||||
updatedAt: string;
|
||||
username: string;
|
||||
};
|
||||
|
||||
export type Login = {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
} & User;
|
||||
|
||||
export type Ping = {
|
||||
description: string;
|
||||
name: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export type GenreResponse = {
|
||||
createdAt: string;
|
||||
id: number;
|
||||
name: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type ArtistResponse = {
|
||||
biography: string | null;
|
||||
createdAt: string;
|
||||
id: number;
|
||||
name: string;
|
||||
remoteCreatedAt: string | null;
|
||||
remoteId: string;
|
||||
serverFolderId: number;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type ExternalResponse = {
|
||||
createdAt: string;
|
||||
id: number;
|
||||
name: string;
|
||||
updatedAt: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type ImageResponse = {
|
||||
createdAt: string;
|
||||
id: number;
|
||||
name: string;
|
||||
updatedAt: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type PingResponse = BaseResponse<Ping>;
|
||||
|
||||
export type LoginResponse = BaseResponse<Login>;
|
||||
|
||||
export type UserResponse = BaseResponse<User>;
|
||||
|
||||
export type AlbumResponse = BaseResponse<Album>;
|
||||
|
||||
export type AlbumsResponse = BasePaginatedResponse<Album[]>;
|
||||
|
||||
export interface Album {
|
||||
_count: Count;
|
||||
albumArtistId: number;
|
||||
createdAt: string;
|
||||
date: string;
|
||||
genres: GenreResponse[];
|
||||
id: number;
|
||||
name: string;
|
||||
remoteCreatedAt: string;
|
||||
remoteId: string;
|
||||
serverFolderId: number;
|
||||
songs: Song[];
|
||||
updatedAt: string;
|
||||
year: number;
|
||||
}
|
||||
|
||||
export interface Song {
|
||||
album?: Partial<Album>;
|
||||
albumId: number;
|
||||
artistName: null;
|
||||
artists?: ArtistResponse[];
|
||||
bitRate: number;
|
||||
container: string;
|
||||
createdAt: string;
|
||||
date: string;
|
||||
disc: number;
|
||||
duration: number;
|
||||
externals?: ExternalResponse[];
|
||||
id: number;
|
||||
images?: ImageResponse[];
|
||||
name: string;
|
||||
remoteCreatedAt: string;
|
||||
remoteId: string;
|
||||
serverFolderId: number;
|
||||
track: number;
|
||||
updatedAt: string;
|
||||
year: number;
|
||||
}
|
||||
|
||||
export type Count = {
|
||||
artists?: number;
|
||||
externals?: number;
|
||||
favorites?: number;
|
||||
genres?: number;
|
||||
images?: number;
|
||||
ratings?: number;
|
||||
songs?: number;
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { api } from 'renderer/lib';
|
||||
import { UserResponse } from './types';
|
||||
|
||||
const getUsers = async () => {
|
||||
const { data } = await api.get<UserResponse>('/users');
|
||||
return data;
|
||||
};
|
||||
|
||||
export const usersApi = {
|
||||
getUsers,
|
||||
};
|
||||
Reference in New Issue
Block a user