2019-06-29 23:14:32 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
|
|
|
|
export interface Allocation {
|
|
|
|
ip: string;
|
|
|
|
alias: string | null;
|
|
|
|
port: number;
|
2019-08-17 23:03:10 +00:00
|
|
|
default: boolean;
|
2019-06-29 23:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Server {
|
|
|
|
id: string;
|
|
|
|
uuid: string;
|
|
|
|
name: string;
|
|
|
|
node: string;
|
2019-12-07 23:58:37 +00:00
|
|
|
sftpDetails: {
|
|
|
|
ip: string;
|
|
|
|
port: number;
|
|
|
|
};
|
2019-06-29 23:14:32 +00:00
|
|
|
description: string;
|
|
|
|
allocations: Allocation[];
|
|
|
|
limits: {
|
|
|
|
memory: number;
|
|
|
|
swap: number;
|
|
|
|
disk: number;
|
|
|
|
io: number;
|
|
|
|
cpu: number;
|
2020-03-29 21:12:35 +00:00
|
|
|
threads: string;
|
2019-06-29 23:14:32 +00:00
|
|
|
};
|
|
|
|
featureLimits: {
|
|
|
|
databases: number;
|
|
|
|
allocations: number;
|
2020-04-26 19:12:29 +00:00
|
|
|
backups: number;
|
2019-06-29 23:14:32 +00:00
|
|
|
};
|
2020-04-26 00:58:09 +00:00
|
|
|
isSuspended: boolean;
|
|
|
|
isInstalling: boolean;
|
2019-06-29 23:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const rawDataToServerObject = (data: any): Server => ({
|
|
|
|
id: data.identifier,
|
|
|
|
uuid: data.uuid,
|
|
|
|
name: data.name,
|
|
|
|
node: data.node,
|
2019-12-07 23:58:37 +00:00
|
|
|
sftpDetails: {
|
|
|
|
ip: data.sftp_details.ip,
|
|
|
|
port: data.sftp_details.port,
|
|
|
|
},
|
2019-06-29 23:14:32 +00:00
|
|
|
description: data.description ? ((data.description.length > 0) ? data.description : null) : null,
|
2020-03-29 00:25:04 +00:00
|
|
|
allocations: [ {
|
2019-06-29 23:14:32 +00:00
|
|
|
ip: data.allocation.ip,
|
|
|
|
alias: null,
|
|
|
|
port: data.allocation.port,
|
2019-08-17 23:03:10 +00:00
|
|
|
default: true,
|
2020-03-29 00:25:04 +00:00
|
|
|
} ],
|
2019-06-29 23:14:32 +00:00
|
|
|
limits: { ...data.limits },
|
|
|
|
featureLimits: { ...data.feature_limits },
|
2020-04-26 00:58:09 +00:00
|
|
|
isSuspended: data.is_suspended,
|
|
|
|
isInstalling: data.is_installing,
|
2019-06-29 23:14:32 +00:00
|
|
|
});
|
|
|
|
|
2020-03-29 00:25:04 +00:00
|
|
|
export default (uuid: string): Promise<[ Server, string[] ]> => {
|
2019-06-29 23:14:32 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.get(`/api/client/servers/${uuid}`)
|
2020-03-29 00:25:04 +00:00
|
|
|
.then(({ data }) => resolve([
|
|
|
|
rawDataToServerObject(data.attributes),
|
|
|
|
data.meta?.is_server_owner ? ['*'] : (data.meta?.user_permissions || []),
|
|
|
|
]))
|
2019-06-29 23:14:32 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|