2021-10-10 18:32:07 +00:00
|
|
|
import { Model, UUID, WithRelationships, withRelationships } from '@/api/admin/index';
|
|
|
|
import { Location } from '@/api/admin/location';
|
2021-10-24 20:14:04 +00:00
|
|
|
import http, { QueryBuilderParams, withQueryBuilderParams } from '@/api/http';
|
2022-02-27 17:54:25 +00:00
|
|
|
import { Transformers } from '@definitions/admin';
|
2021-10-10 18:32:07 +00:00
|
|
|
import { Server } from '@/api/admin/server';
|
|
|
|
|
|
|
|
interface NodePorts {
|
|
|
|
http: {
|
|
|
|
listen: number;
|
|
|
|
public: number;
|
|
|
|
};
|
|
|
|
sftp: {
|
|
|
|
listen: number;
|
|
|
|
public: number;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Allocation extends Model {
|
|
|
|
id: number;
|
|
|
|
ip: string;
|
|
|
|
port: number;
|
|
|
|
alias: string | null;
|
|
|
|
isAssigned: boolean;
|
|
|
|
relationships: {
|
|
|
|
node?: Node;
|
|
|
|
server?: Server | null;
|
|
|
|
};
|
2021-10-10 19:03:28 +00:00
|
|
|
getDisplayText(): string;
|
2021-10-10 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Node extends Model {
|
|
|
|
id: number;
|
|
|
|
uuid: UUID;
|
|
|
|
isPublic: boolean;
|
|
|
|
locationId: number;
|
|
|
|
databaseHostId: number;
|
|
|
|
name: string;
|
|
|
|
description: string | null;
|
|
|
|
fqdn: string;
|
|
|
|
ports: NodePorts;
|
|
|
|
scheme: 'http' | 'https';
|
|
|
|
isBehindProxy: boolean;
|
|
|
|
isMaintenanceMode: boolean;
|
|
|
|
memory: number;
|
|
|
|
memoryOverallocate: number;
|
|
|
|
disk: number;
|
|
|
|
diskOverallocate: number;
|
|
|
|
uploadSize: number;
|
|
|
|
daemonBase: string;
|
|
|
|
createdAt: Date;
|
|
|
|
updatedAt: Date;
|
|
|
|
relationships: {
|
|
|
|
location?: Location;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a single node and returns it.
|
|
|
|
*/
|
|
|
|
export const getNode = async (id: string | number): Promise<WithRelationships<Node, 'location'>> => {
|
|
|
|
const { data } = await http.get(`/api/application/nodes/${id}`, {
|
|
|
|
params: {
|
2021-10-10 20:21:21 +00:00
|
|
|
include: [ 'location' ],
|
2021-10-10 18:32:07 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-02-27 16:26:13 +00:00
|
|
|
return withRelationships(Transformers.toNode(data.data), 'location');
|
2021-10-10 18:32:07 +00:00
|
|
|
};
|
2021-10-24 20:14:04 +00:00
|
|
|
|
|
|
|
export const searchNodes = async (params: QueryBuilderParams<'name'>): Promise<Node[]> => {
|
|
|
|
const { data } = await http.get('/api/application/nodes', {
|
|
|
|
params: withQueryBuilderParams(params),
|
|
|
|
});
|
|
|
|
|
2022-02-27 16:26:13 +00:00
|
|
|
return data.data.map(Transformers.toNode);
|
2021-10-24 20:14:04 +00:00
|
|
|
};
|
2021-10-29 06:04:28 +00:00
|
|
|
|
|
|
|
export const getAllocations = async (id: string | number, params?: QueryBuilderParams<'ip' | 'server_id'>): Promise<Allocation[]> => {
|
|
|
|
const { data } = await http.get(`/api/application/nodes/${id}/allocations`, {
|
|
|
|
params: withQueryBuilderParams(params),
|
|
|
|
});
|
|
|
|
|
2022-02-27 16:26:13 +00:00
|
|
|
return data.data.map(Transformers.toAllocation);
|
2021-10-29 06:04:28 +00:00
|
|
|
};
|