diff --git a/packages/renderer/src/api/controller.types.ts b/packages/renderer/src/api/controller.types.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/renderer/src/api/index.ts b/packages/renderer/src/api/index.ts index 12780224f..e9c5a4e1d 100644 --- a/packages/renderer/src/api/index.ts +++ b/packages/renderer/src/api/index.ts @@ -1,7 +1,5 @@ -import { apiController } from './controller'; -import { navidromeApi } from './navidrome.api'; +import { controller } from '/@/api/controller'; export const api = { - controller: apiController, - navidrome: navidromeApi, + controller: controller, }; diff --git a/packages/renderer/src/api/shared.api.ts b/packages/renderer/src/api/shared.api.ts deleted file mode 100644 index 395dc5a1b..000000000 --- a/packages/renderer/src/api/shared.api.ts +++ /dev/null @@ -1,155 +0,0 @@ -import axios from 'axios'; -import md5 from 'md5'; -import { ServerType } from '/@/types'; -import { randomString } from '/@/utils'; - -type JFAuthenticate = { - AccessToken: string; - ServerId: string; - SessionInfo: any; - User: any; -}; - -export const jfAuthenticate = async (options: { - password: string; - url: string; - username: string; -}) => { - const { password, url, username } = options; - const cleanServerUrl = url.replace(/\/$/, ''); - - const { data } = await axios.post( - `${cleanServerUrl}/users/authenticatebyname`, - { pw: password, username }, - { - headers: { - 'X-Emby-Authorization': - 'MediaBrowser Client="Feishin", Device="PC", DeviceId="Feishin", Version="0.0.1-alpha1"', - }, - }, - ); - - return data; -}; - -type NDAuthenticate = { - id: string; - isAdmin: boolean; - name: string; - subsonicSalt: string; - subsonicToken: string; - token: string; - username: string; -}; - -const ndAuthenticate = async (options: { password: string; url: string; username: string }) => { - const { password, url, username } = options; - const cleanServerUrl = url.replace(/\/$/, ''); - - const { data } = await axios.post(`${cleanServerUrl}/auth/login`, { - password, - username, - }); - - return data; -}; - -const ssAuthenticate = async (options: { - legacy?: boolean; - password: string; - url: string; - username: string; -}) => { - let token; - - const cleanServerUrl = options.url.replace(/\/$/, ''); - - if (options.legacy) { - token = `u=${options.username}&p=${options.password}`; - } else { - const salt = randomString(); - const hash = md5(options.password + salt); - token = `u=${options.username}&s=${salt}&t=${hash}`; - } - - const { data } = await axios.get( - `${cleanServerUrl}/rest/ping.view?v=1.13.0&c=Feishin&f=json&${token}`, - ); - - return { token, ...data }; -}; - -export const remoteServerLogin = async (options: { - legacy?: boolean; - password: string; - type: ServerType; - url: string; - username: string; -}) => { - if (options.type === ServerType.JELLYFIN) { - try { - const res = await jfAuthenticate({ - password: options.password, - url: options.url, - username: options.username, - }); - - return { - remoteUserId: res.User.Id, - token: res.AccessToken, - type: ServerType.JELLYFIN, - url: options.url, - username: options.username, - }; - } catch (err: any) { - return { message: err.message, type: 'error' }; - } - } - - if (options.type === ServerType.SUBSONIC) { - const res = await ssAuthenticate({ - legacy: options.legacy, - password: options.password, - url: options.url, - username: options.username, - }); - - if (res.status === 'failed') { - return { - message: 'Could not validate username and password', - type: 'error', - }; - } - - return { - remoteUserId: '', - token: res.token, - type: ServerType.SUBSONIC, - url: options.url, - username: options.username, - }; - } - - if (options.type === ServerType.NAVIDROME) { - try { - const res = await ndAuthenticate({ - password: options.password, - url: options.url, - username: options.username, - }); - - return { - remoteUserId: res.id, - token: `u=${res.name}&s=${res.subsonicSalt}&t=${res.subsonicToken}`, - // token: res.token, - type: ServerType.NAVIDROME, - url: options.url, - username: options.username, - }; - } catch (err: any) { - return { message: err.message, type: 'error' }; - } - } - - return { message: 'Not found', type: 'error' }; -}; diff --git a/packages/renderer/src/components/check-box/index.tsx b/packages/renderer/src/components/check-box/index.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/renderer/src/features/dashboard/index.ts b/packages/renderer/src/features/dashboard/index.ts deleted file mode 100644 index 8617d0072..000000000 --- a/packages/renderer/src/features/dashboard/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './routes/DashboardRoute'; diff --git a/packages/renderer/src/features/servers/utils/validate-server.ts b/packages/renderer/src/features/servers/utils/validate-server.ts deleted file mode 100644 index fc9a3f482..000000000 --- a/packages/renderer/src/features/servers/utils/validate-server.ts +++ /dev/null @@ -1,62 +0,0 @@ -import axios from 'axios'; -import md5 from 'md5'; -import { ServerType } from '/@/types'; -import { randomString } from '/@/utils'; - -export const validateServerCredential = async (options: { - legacyAuth: boolean; - password: string; - type: ServerType; - url: string; - username: string; -}) => { - const { type, url, username, password, legacyAuth } = options; - const cleanServerUrl = url.replace(/\/$/, ''); - - try { - if (type === ServerType.SUBSONIC) { - let testConnection; - let token; - if (legacyAuth) { - token = `u=${username}&p=${password}`; - testConnection = await axios.get( - `${cleanServerUrl}/rest/ping.view?v=1.13.0&c=Feishin&f=json&${token}`, - ); - } else { - const salt = randomString(); - const hash = md5(password + salt); - token = `u=${username}&s=${salt}&t=${hash}`; - - testConnection = await axios.get( - `${cleanServerUrl}/rest/ping.view?v=1.13.0&c=Feishin&f=json&${token}`, - ); - } - - if (testConnection.data['subsonic-response'].status === 'failed') { - return { - error: `${testConnection.data['subsonic-response'].error.message}`, - }; - } - return { token, userId: '' }; - } - - const { data } = await axios.post( - `${cleanServerUrl}/users/authenticatebyname`, - { pw: password, username }, - { - headers: { - 'X-Emby-Authorization': - 'MediaBrowser Client="Feishin", Device="PC", DeviceId="Feishin", Version="0.0.1-alpha1"', - }, - }, - ); - - return { token: data.AccessToken, userId: data.User.Id }; - } catch (err) { - if (err instanceof Error) { - return { error: err.message }; - } - } - - return null; -}; diff --git a/packages/renderer/src/features/settings/utils/local-settings.ts b/packages/renderer/src/features/settings/utils/local-settings.ts deleted file mode 100644 index f7b408833..000000000 --- a/packages/renderer/src/features/settings/utils/local-settings.ts +++ /dev/null @@ -1,19 +0,0 @@ -import isElectron from 'is-electron'; - -const ipc = isElectron() ? null : null; - -export const getLocalSetting = (property: string) => ipc?.SETTINGS_GET({ property }); - -export const setLocalSetting = (property: string, value: any) => { - ipc?.SETTINGS_SET({ property, value }); -}; - -export const restartApp = () => { - ipc?.APP_RESTART(); -}; - -export const localSettings = { - get: getLocalSetting, - restart: restartApp, - set: setLocalSetting, -}; diff --git a/packages/renderer/src/lib/axios.ts b/packages/renderer/src/lib/axios.ts deleted file mode 100644 index 458cce0a8..000000000 --- a/packages/renderer/src/lib/axios.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* eslint-disable no-underscore-dangle */ -import Axios from 'axios'; -import { useAuthStore } from '/@/store'; -import { authApi } from '../api/auth.api'; - -export const ax = Axios.create({ - headers: { 'Content-Type': 'application/json' }, - withCredentials: false, -}); - -ax.interceptors.request.use( - (config) => { - const { state } = JSON.parse(localStorage.getItem('store_authentication') || '{}'); - - config.baseURL = `${state.serverUrl}/api`; - config.headers = { - Authorization: `Bearer ${state.accessToken}`, - 'Content-Type': 'application/json', - }; - return config; - }, - (error) => { - return Promise.reject(error); - }, -); - -ax.interceptors.response.use( - (res) => { - return res; - }, - async (err) => { - if (!err.response) { - return Promise.reject(err); - } - - if (err.response && err.response.status === 401) { - const { config } = err; - - const auth = useAuthStore.getState(); - - if (err.response.data.error.message === 'jwt expired' && !config.sent) { - config.sent = true; - - const { accessToken } = ( - await authApi.refresh(auth.serverUrl, { - refreshToken: auth.refreshToken, - }) - ).data; - - useAuthStore.setState({ ...auth, accessToken }); - - config.headers = { - ...config.headers, - Authorization: `Bearer ${accessToken}`, - }; - - return Axios(config); - } - - // auth.logout(); - } - return Promise.reject(err); - }, -);