mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-13 20:10:07 +02:00
Update scanner (frontend)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ax } from '@/renderer/lib/axios';
|
||||
import { SortOrder } from '@/types';
|
||||
import { SortOrder } from '@/renderer/types';
|
||||
import {
|
||||
AlbumDetailResponse,
|
||||
AlbumListResponse,
|
||||
@@ -25,13 +25,19 @@ export type AlbumListParams = PaginationParams & {
|
||||
};
|
||||
|
||||
const getAlbumDetail = async (
|
||||
query: { albumId: number; serverId: string },
|
||||
query: { albumId: string; serverId: string },
|
||||
signal?: AbortSignal
|
||||
) => {
|
||||
const { data } = await ax.get<AlbumDetailResponse>(
|
||||
`/servers/${query.serverId}/albums/${query.albumId}`,
|
||||
{ signal }
|
||||
);
|
||||
|
||||
// const songs = data.data.songs?.map((s) => ({
|
||||
// ...s,
|
||||
// streamUrl:
|
||||
// }));
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// import axios from 'axios';
|
||||
import axios from 'axios';
|
||||
import { LoginResponse, PingResponse } from './types';
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { tasksApi } from '@/renderer/api/tasks.api';
|
||||
import { albumsApi } from './albums.api';
|
||||
import { authApi } from './auth.api';
|
||||
import { serversApi } from './servers.api';
|
||||
import { usersApi } from './users.api';
|
||||
|
||||
export * from './sockets.api';
|
||||
|
||||
export const api = {
|
||||
albums: albumsApi,
|
||||
auth: authApi,
|
||||
servers: serversApi,
|
||||
tasks: tasksApi,
|
||||
users: usersApi,
|
||||
};
|
||||
|
||||
@@ -3,13 +3,19 @@ import { AlbumListParams } from './albums.api';
|
||||
export const queryKeys = {
|
||||
albums: {
|
||||
detail: (albumId: string) => ['albums', albumId] as const,
|
||||
list: (params: AlbumListParams) => ['albums', 'list', params] as const,
|
||||
list: (serverId: string, params: AlbumListParams) =>
|
||||
['albums', 'list', serverId, params] as const,
|
||||
root: ['albums'],
|
||||
songList: (albumId: string) => ['albums', albumId, 'songs'] as const,
|
||||
},
|
||||
ping: (url: string) => ['ping', url] as const,
|
||||
servers: {
|
||||
list: () => ['servers', 'list'] as const,
|
||||
list: (params?: any) => ['servers', 'list', params] as const,
|
||||
root: ['servers'],
|
||||
},
|
||||
tasks: {
|
||||
list: () => ['tasks', 'list'] as const,
|
||||
root: ['tasks'],
|
||||
},
|
||||
users: {
|
||||
detail: (userId: string) => ['users', userId] as const,
|
||||
|
||||
@@ -9,14 +9,21 @@ import { ax } from '@/renderer/lib/axios';
|
||||
|
||||
export type ServerListResponse = BaseResponse<Server[]>;
|
||||
|
||||
const getServerList = async (signal?: AbortSignal) => {
|
||||
const { data } = await ax.get<ServerListResponse>('/servers', { signal });
|
||||
const getServerList = async (
|
||||
params?: { enabled?: boolean },
|
||||
signal?: AbortSignal
|
||||
) => {
|
||||
const { data } = await ax.get<ServerListResponse>('/servers', {
|
||||
params,
|
||||
signal,
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
export type CreateServerBody = {
|
||||
legacy?: boolean;
|
||||
name: string;
|
||||
noCredential?: boolean;
|
||||
password: string;
|
||||
type: ServerType;
|
||||
url: string;
|
||||
@@ -30,6 +37,15 @@ const createServer = async (body: CreateServerBody) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
const deleteServer = async (options: { query: { serverId: string } }) => {
|
||||
const { query } = options;
|
||||
const { data } = await ax.post<NullResponse>(
|
||||
`/servers/${query.serverId}`,
|
||||
{}
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const updateServer = async (
|
||||
query: { serverId: string },
|
||||
body: Partial<CreateServerBody>
|
||||
@@ -78,12 +94,68 @@ const disableUrl = async (query: { serverId: string; urlId: string }) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
// const deleteFolder = async (query: { serverId: string; folderId: string }) => {
|
||||
// const { data } = await ax.delete<NullResponse>(
|
||||
// `/servers/${query.serverId}/folder/${query.folderId}`
|
||||
// );
|
||||
// return data;
|
||||
// };
|
||||
|
||||
const enableFolder = async (query: { folderId: string; serverId: string }) => {
|
||||
const { data } = await ax.post<NullResponse>(
|
||||
`/servers/${query.serverId}/folder/${query.folderId}/enable`,
|
||||
{}
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const disableFolder = async (query: { folderId: string; serverId: string }) => {
|
||||
const { data } = await ax.post<NullResponse>(
|
||||
`/servers/${query.serverId}/folder/${query.folderId}/disable`,
|
||||
{}
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
export type ScanServerBody = {
|
||||
serverFolderId?: string[];
|
||||
};
|
||||
|
||||
const quickScan = async (options: {
|
||||
body: ScanServerBody;
|
||||
query: { serverId: string };
|
||||
}) => {
|
||||
const { body, query } = options;
|
||||
const { data } = await ax.post<NullResponse>(
|
||||
`/servers/${query.serverId}/scan`,
|
||||
body
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const fullScan = async (options: {
|
||||
body: ScanServerBody;
|
||||
query: { serverId: string };
|
||||
}) => {
|
||||
const { body, query } = options;
|
||||
const { data } = await ax.post<NullResponse>(
|
||||
`/servers/${query.serverId}/full-scan`,
|
||||
body
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const serversApi = {
|
||||
createServer,
|
||||
createUrl,
|
||||
deleteServer,
|
||||
deleteUrl,
|
||||
disableFolder,
|
||||
disableUrl,
|
||||
enableFolder,
|
||||
enableUrl,
|
||||
fullScan,
|
||||
getServerList,
|
||||
quickScan,
|
||||
updateServer,
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ export const jfAuthenticate = async (options: {
|
||||
{ pw: password, username },
|
||||
{
|
||||
headers: {
|
||||
'X-Emby-Authorization': `MediaBrowser Client="Sonixd", Device="PC", DeviceId="Sonixd", Version="1.0.0-alpha1"`,
|
||||
'X-Emby-Authorization': `MediaBrowser Client="Feishin", Device="PC", DeviceId="Feishin", Version="1.0.0-alpha1"`,
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -76,7 +76,7 @@ const ssAuthenticate = async (options: {
|
||||
}
|
||||
|
||||
const { data } = await axios.get(
|
||||
`${cleanServerUrl}/rest/ping.view?v=1.13.0&c=sonixd&f=json&${token}`
|
||||
`${cleanServerUrl}/rest/ping.view?v=1.13.0&c=Feishin&f=json&${token}`
|
||||
);
|
||||
|
||||
return { token, ...data };
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { io } from 'socket.io-client';
|
||||
|
||||
const { username } = JSON.parse(
|
||||
localStorage.getItem('store_authentication') || '{}'
|
||||
).state.permissions;
|
||||
|
||||
export const socket = io('http://localhost:8843', {
|
||||
query: { username },
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { BaseResponse, NullResponse, Task } from '@/renderer/api/types';
|
||||
import { ax } from '@/renderer/lib/axios';
|
||||
|
||||
export type TaskListResponse = BaseResponse<Task[]>;
|
||||
|
||||
const getActiveTasks = async (signal?: AbortSignal) => {
|
||||
const { data } = await ax.get<TaskListResponse>('/tasks', {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const cancelAllTasks = async () => {
|
||||
const { data } = await ax.post<NullResponse>('/tasks/cancel', {});
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export type TaskResponse = BaseResponse<Task>;
|
||||
|
||||
const cancelTask = async (query: { taskId: string }) => {
|
||||
const { data } = await ax.post<TaskResponse>(
|
||||
`/tasks/${query.taskId}/cancel`,
|
||||
{}
|
||||
);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const tasksApi = {
|
||||
cancelAllTasks,
|
||||
cancelTask,
|
||||
getActiveTasks,
|
||||
};
|
||||
@@ -84,6 +84,7 @@ export type Server = {
|
||||
createdAt: string;
|
||||
id: string;
|
||||
name: string;
|
||||
noCredential: boolean;
|
||||
remoteUserId: string;
|
||||
serverFolders?: RelatedServerFolder[];
|
||||
serverPermissions?: RelatedServerPermission[];
|
||||
@@ -96,6 +97,7 @@ export type Server = {
|
||||
};
|
||||
|
||||
export type RelatedServerFolder = {
|
||||
enabled: boolean;
|
||||
id: string;
|
||||
lastScannedAt: string | null;
|
||||
name: string;
|
||||
@@ -282,6 +284,32 @@ export type RelatedArtist = {
|
||||
remoteId: string;
|
||||
};
|
||||
|
||||
export type RelatedServer = {
|
||||
id: string;
|
||||
name: string;
|
||||
type: ServerType;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type RelatedUser = {
|
||||
enabled: boolean;
|
||||
id: string;
|
||||
isAdmin: boolean;
|
||||
username: string;
|
||||
};
|
||||
|
||||
export type Task = {
|
||||
createdAt: string;
|
||||
id: string;
|
||||
isCompleted: boolean;
|
||||
isError: boolean;
|
||||
message: string;
|
||||
server: RelatedServer | null;
|
||||
type: TaskType;
|
||||
updatedAt: string;
|
||||
user: RelatedUser | null;
|
||||
};
|
||||
|
||||
export type PingResponse = BaseResponse<Ping>;
|
||||
|
||||
export type LoginResponse = BaseResponse<Login>;
|
||||
|
||||
Reference in New Issue
Block a user