misc_pterodactyl-panel/resources/scripts/api/admin/servers/createServer.ts

75 lines
2 KiB
TypeScript
Raw Normal View History

2021-01-06 23:38:39 +00:00
import http from '@/api/http';
import { Server, rawDataToServer } from '@/api/admin/servers/getServers';
interface CreateServerRequest {
name: string;
description: string | null;
user: number;
egg: number;
dockerImage: string;
startup: string;
skipScripts: boolean;
oomDisabled: boolean;
startOnCompletion: boolean;
environment: string[];
allocation: {
default: number;
additional: number[];
};
limits: {
cpu: number;
disk: number;
io: number;
memory: number;
swap: number;
threads: string;
};
featureLimits: {
allocations: number;
backups: number;
databases: number;
};
}
export default (r: CreateServerRequest, include: string[] = []): Promise<Server> => {
2021-01-06 23:38:39 +00:00
return new Promise((resolve, reject) => {
http.post('/api/application/servers', {
name: r.name,
description: r.description,
user: r.user,
egg: r.egg,
docker_image: r.dockerImage,
startup: r.startup,
skip_scripts: r.skipScripts,
oom_disabled: r.oomDisabled,
start_on_completion: r.startOnCompletion,
environment: r.environment,
allocation: {
default: r.allocation.default,
additional: r.allocation.additional,
},
limits: {
cpu: r.limits.cpu,
disk: r.limits.disk,
io: r.limits.io,
memory: r.limits.memory,
swap: r.limits.swap,
threads: r.limits.threads,
},
featureLimits: {
allocations: r.featureLimits.allocations,
backups: r.featureLimits.backups,
databases: r.featureLimits.databases,
},
}, { params: { include: include.join(',') } })
2021-01-06 23:38:39 +00:00
.then(({ data }) => resolve(rawDataToServer(data)))
.catch(reject);
});
};