mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
add isAdmin to auth state
This commit is contained in:
@@ -91,6 +91,7 @@ export const JellyfinController: InternalControllerEndpoint = {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
credential: res.body.AccessToken,
|
credential: res.body.AccessToken,
|
||||||
|
isAdmin: Boolean(res.body.User.Policy.IsAdministrator),
|
||||||
userId: res.body.User.Id,
|
userId: res.body.User.Id,
|
||||||
username: res.body.User.Name,
|
username: res.body.User.Name,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ export const NavidromeController: InternalControllerEndpoint = {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
credential: `u=${body.username}&s=${res.body.data.subsonicSalt}&t=${res.body.data.subsonicToken}`,
|
credential: `u=${body.username}&s=${res.body.data.subsonicSalt}&t=${res.body.data.subsonicToken}`,
|
||||||
|
isAdmin: Boolean(res.body.data.isAdmin),
|
||||||
ndCredential: res.body.data.token,
|
ndCredential: res.body.data.token,
|
||||||
userId: res.body.data.id,
|
userId: res.body.data.id,
|
||||||
username: res.body.data.username,
|
username: res.body.data.username,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const c = initContract();
|
|||||||
export const contract = c.router({
|
export const contract = c.router({
|
||||||
authenticate: {
|
authenticate: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'ping.view',
|
path: 'getUser.view',
|
||||||
query: ssType._parameters.authenticate,
|
query: ssType._parameters.authenticate,
|
||||||
responses: {
|
responses: {
|
||||||
200: ssType._response.authenticate,
|
200: ssType._response.authenticate,
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ export const SubsonicController: InternalControllerEndpoint = {
|
|||||||
query: {
|
query: {
|
||||||
c: 'Feishin',
|
c: 'Feishin',
|
||||||
f: 'json',
|
f: 'json',
|
||||||
|
username: body.username,
|
||||||
v: '1.13.0',
|
v: '1.13.0',
|
||||||
...credentialParams,
|
...credentialParams,
|
||||||
},
|
},
|
||||||
@@ -143,7 +144,8 @@ export const SubsonicController: InternalControllerEndpoint = {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
credential,
|
credential,
|
||||||
userId: null,
|
isAdmin: resp.body.user.adminRoles,
|
||||||
|
userId: resp.body.user.username,
|
||||||
username: body.username,
|
username: body.username,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ const LoginRoute = () => {
|
|||||||
const serverItem: ServerListItemWithCredential = {
|
const serverItem: ServerListItemWithCredential = {
|
||||||
credential: data.credential,
|
credential: data.credential,
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
|
isAdmin: data.isAdmin,
|
||||||
name: serverName,
|
name: serverName,
|
||||||
type: serverType as ServerType,
|
type: serverType as ServerType,
|
||||||
url: serverUrl.replace(/\/$/, ''),
|
url: serverUrl.replace(/\/$/, ''),
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
|
|||||||
const serverItem: ServerListItemWithCredential = {
|
const serverItem: ServerListItemWithCredential = {
|
||||||
credential: data.credential,
|
credential: data.credential,
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
|
isAdmin: data.isAdmin,
|
||||||
name: values.name,
|
name: values.name,
|
||||||
type: values.type as ServerType,
|
type: values.type as ServerType,
|
||||||
url: values.url.replace(/\/$/, ''),
|
url: values.url.replace(/\/$/, ''),
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export const EditServerForm = ({ isUpdate, onCancel, password, server }: EditSer
|
|||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
|
isAdmin: server?.isAdmin,
|
||||||
legacyAuth: false,
|
legacyAuth: false,
|
||||||
name: server?.name,
|
name: server?.name,
|
||||||
password: password || '',
|
password: password || '',
|
||||||
@@ -94,6 +95,7 @@ export const EditServerForm = ({ isUpdate, onCancel, password, server }: EditSer
|
|||||||
const serverItem: ServerListItemWithCredential = {
|
const serverItem: ServerListItemWithCredential = {
|
||||||
credential: data.credential,
|
credential: data.credential,
|
||||||
id: server.id,
|
id: server.id,
|
||||||
|
isAdmin: data.isAdmin,
|
||||||
name: values.name,
|
name: values.name,
|
||||||
type: values.type,
|
type: values.type,
|
||||||
url: values.url,
|
url: values.url,
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ export const useCurrentServer = () =>
|
|||||||
return {
|
return {
|
||||||
features: state.currentServer?.features,
|
features: state.currentServer?.features,
|
||||||
id: state.currentServer?.id,
|
id: state.currentServer?.id,
|
||||||
|
isAdmin: state.currentServer?.isAdmin,
|
||||||
musicFolderId: state.currentServer?.musicFolderId,
|
musicFolderId: state.currentServer?.musicFolderId,
|
||||||
name: state.currentServer?.name,
|
name: state.currentServer?.name,
|
||||||
preferInstantMix: state.currentServer?.preferInstantMix,
|
preferInstantMix: state.currentServer?.preferInstantMix,
|
||||||
@@ -132,6 +133,14 @@ export const useCurrentServer = () =>
|
|||||||
};
|
};
|
||||||
}, shallow) as ServerListItem;
|
}, shallow) as ServerListItem;
|
||||||
|
|
||||||
|
export const useIsAdmin = () =>
|
||||||
|
useAuthStore((state) => {
|
||||||
|
return {
|
||||||
|
isAdmin: state.currentServer?.isAdmin ?? false,
|
||||||
|
userId: state.currentServer?.userId,
|
||||||
|
};
|
||||||
|
}, shallow);
|
||||||
|
|
||||||
export const useCurrentServerWithCredential = () =>
|
export const useCurrentServerWithCredential = () =>
|
||||||
useAuthStore((state) => state.currentServer) as ServerListItemWithCredential;
|
useAuthStore((state) => state.currentServer) as ServerListItemWithCredential;
|
||||||
|
|
||||||
@@ -146,3 +155,14 @@ export const getServerById = (id?: string) => {
|
|||||||
|
|
||||||
return useAuthStore.getState().actions.getServer(id);
|
return useAuthStore.getState().actions.getServer(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const usePermissions = () => {
|
||||||
|
const { isAdmin, userId } = useIsAdmin();
|
||||||
|
|
||||||
|
return {
|
||||||
|
playlists: {
|
||||||
|
editPublic: isAdmin,
|
||||||
|
},
|
||||||
|
userId: userId,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -7,7 +7,24 @@ const baseResponse = z.object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const authenticate = z.null();
|
const authenticate = z.object({
|
||||||
|
user: z.object({
|
||||||
|
adminRoles: z.boolean(),
|
||||||
|
commentRole: z.boolean(),
|
||||||
|
coverArtRole: z.boolean(),
|
||||||
|
downloadRole: z.boolean(),
|
||||||
|
folder: z.string().array(),
|
||||||
|
jukeboxRole: z.boolean(),
|
||||||
|
playlistRole: z.boolean(),
|
||||||
|
podcastRole: z.boolean(),
|
||||||
|
scrobblingEnabled: z.boolean(),
|
||||||
|
settingsRole: z.boolean(),
|
||||||
|
shareRole: z.boolean(),
|
||||||
|
streamRole: z.boolean(),
|
||||||
|
uploadRole: z.boolean(),
|
||||||
|
username: z.string(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
const authenticateParameters = z.object({
|
const authenticateParameters = z.object({
|
||||||
c: z.string(),
|
c: z.string(),
|
||||||
@@ -16,6 +33,7 @@ const authenticateParameters = z.object({
|
|||||||
s: z.string().optional(),
|
s: z.string().optional(),
|
||||||
t: z.string().optional(),
|
t: z.string().optional(),
|
||||||
u: z.string(),
|
u: z.string(),
|
||||||
|
username: z.string(),
|
||||||
v: z.string(),
|
v: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ export type QueueSong = Song & {
|
|||||||
export type ServerListItem = {
|
export type ServerListItem = {
|
||||||
features?: ServerFeatures;
|
features?: ServerFeatures;
|
||||||
id: string;
|
id: string;
|
||||||
|
isAdmin?: boolean;
|
||||||
musicFolderId?: string[];
|
musicFolderId?: string[];
|
||||||
name: string;
|
name: string;
|
||||||
preferInstantMix?: boolean;
|
preferInstantMix?: boolean;
|
||||||
@@ -237,6 +238,7 @@ export type Artist = {
|
|||||||
|
|
||||||
export type AuthenticationResponse = {
|
export type AuthenticationResponse = {
|
||||||
credential: string;
|
credential: string;
|
||||||
|
isAdmin?: boolean;
|
||||||
ndCredential?: string;
|
ndCredential?: string;
|
||||||
userId: null | string;
|
userId: null | string;
|
||||||
username: string;
|
username: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user