[FEATURE] Integrated Minecluster with Cairo & Established Gitea workflows (#12)

Co-authored-by: Dunemask <dunemask@gmail.com>
Reviewed-on: https://gitea.dunemask.dev/elysium/minecluster/pulls/12
This commit is contained in:
dunemask 2024-02-05 02:13:32 +00:00
parent edbfc2348a
commit 78c5b72482
30 changed files with 391 additions and 53 deletions

View file

@ -1,6 +1,7 @@
CREATE SEQUENCE servers_id_seq;
CREATE TABLE servers (
id bigint NOT NULL DEFAULT nextval('servers_id_seq') PRIMARY KEY,
owner_cairo_id bigint,
host varchar(255) DEFAULT NULL,
name varchar(255) DEFAULT NULL,
version varchar(63) DEFAULT 'latest',

View file

@ -2,7 +2,7 @@ import pg from "../postgres.js";
import {
deleteQuery,
insertQuery,
selectWhereQuery,
selectWhereAllQuery,
updateWhereAllQuery,
} from "../pg-query.js";
import ExpressClientError from "../../util/ExpressClientError.js";
@ -12,9 +12,18 @@ const asExpressClientError = (e) => {
throw new ExpressClientError({ m: e.message, c: 409 });
};
const getMclName = (host, id) => `${host.replaceAll(".", "-")}-${id}`;
const getMclName = (host, id) =>
`${host.toLowerCase().replaceAll(".", "-")}-${id}`;
export async function createServerEntry(serverSpec) {
export async function checkAuthorization(serverId, cairoId) {
const q = selectWhereAllQuery(table, {
id: serverId,
owner_cairo_id: cairoId,
});
return (await pg.query(q)).length === 1;
}
export async function createServerEntry(cairoId, serverSpec) {
const {
name,
host,
@ -33,6 +42,7 @@ export async function createServerEntry(serverSpec) {
var q = insertQuery(table, {
name,
owner_cairo_id: cairoId,
host,
version,
server_type,
@ -52,6 +62,7 @@ export async function createServerEntry(serverSpec) {
const entries = await pg.query(q);
const {
id,
owner_cairo_id: ownerCairoId,
name,
host,
version,
@ -72,6 +83,7 @@ export async function createServerEntry(serverSpec) {
name,
mclName,
id,
ownerCairoId,
host,
version,
serverType,
@ -99,7 +111,7 @@ export async function deleteServerEntry(serverId) {
export async function getServerEntry(serverId) {
if (!serverId) asExpressClientError({ message: "Server ID Required!" });
const q = selectWhereQuery(table, { id: serverId });
const q = selectWhereAllQuery(table, { id: serverId });
try {
const serverSpecs = await pg.query(q);
if (serverSpecs.length === 0) return [];
@ -107,6 +119,7 @@ export async function getServerEntry(serverId) {
throw Error("Multiple servers found with the same name!");
const {
id,
owner_cairo_id: ownerCairoId,
name,
host,
version,
@ -127,6 +140,7 @@ export async function getServerEntry(serverId) {
name,
mclName,
id,
ownerCairoId,
host,
version,
serverType,
@ -149,6 +163,7 @@ export async function getServerEntry(serverId) {
export async function modifyServerEntry(serverSpec) {
const {
id,
// ownerCairoId: owner_cairo_id, // DIsabled! If these becomes a reqest, please create a new function!
name,
host,
version,