mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
Remove unused files
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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<JFAuthenticate>(
|
||||
`${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<NDAuthenticate>(`${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' };
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export * from './routes/DashboardRoute';
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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);
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user