forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-keys.ts
More file actions
28 lines (21 loc) · 1.13 KB
/
ssh-keys.ts
File metadata and controls
28 lines (21 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import useSWR, { ConfigInterface } from 'swr';
import useUserSWRContentKey from '@/plugins/useUserSWRContentKey';
import http, { FractalResponseList } from '@/api/http';
import { SSHKey, Transformers } from '@definitions/user';
import { AxiosError } from 'axios';
const useSSHKeys = (config?: ConfigInterface<SSHKey[], AxiosError>) => {
const key = useUserSWRContentKey([ 'account', 'ssh-keys' ]);
return useSWR(key, async () => {
const { data } = await http.get('/api/client/account/ssh-keys');
return (data as FractalResponseList).data.map((datum: any) => {
return Transformers.toSSHKey(datum.attributes);
});
}, { revalidateOnMount: false, ...(config || {}) });
};
const createSSHKey = async (name: string, publicKey: string): Promise<SSHKey> => {
const { data } = await http.post('/api/client/account/ssh-keys', { name, public_key: publicKey });
return Transformers.toSSHKey(data.attributes);
};
const deleteSSHKey = async (fingerprint: string): Promise<void> =>
await http.post('/api/client/account/ssh-keys/remove', { fingerprint });
export { useSSHKeys, createSSHKey, deleteSSHKey };