Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
// adpanel:node-assignment - a legacy name or address cannot override an explicit assignment to another node.
|
||||
const NODE_SERVER_ASSIGNMENT_WHERE = `servers.node_id = ?
|
||||
OR (
|
||||
(servers.node_id = ? OR LOWER(servers.node_id) = ? OR servers.ip = ?)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM nodes n
|
||||
WHERE (n.id = servers.node_id OR n.uuid = servers.node_id)
|
||||
AND n.id <> ?
|
||||
)
|
||||
)`;
|
||||
|
||||
function nodeServerAssignmentParams(node) {
|
||||
return [node.id, String(node.uuid || node.id).trim(), String(node.name || "").trim().toLowerCase(), String(node.address || "").trim(), node.id];
|
||||
}
|
||||
|
||||
function assignedServerPortUses(entry) {
|
||||
const uses = new Map();
|
||||
const resources = entry.resources;
|
||||
const addresses = new Map((Array.isArray(resources?.portAllocations) ? resources.portAllocations : [])
|
||||
.map(allocation => [Number(allocation?.port), allocation?.ip]));
|
||||
const add = (value, portType) => {
|
||||
if (typeof value !== "number" && typeof value !== "string") return;
|
||||
if (!/^\d{1,5}$/.test(String(value).trim())) return;
|
||||
const port = Number(value);
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535 || uses.has(port)) return;
|
||||
uses.set(port, { port, portType, ip: String(addresses.get(port) || entry.ip || "").trim() });
|
||||
};
|
||||
add(entry.port, "primary");
|
||||
if (!uses.size) add(entry.runtime?.port ?? entry.runtime?.ports?.[0], "runtime");
|
||||
add(entry.reinstallPendingPort, "reinstall");
|
||||
|
||||
for (const port of Array.isArray(resources?.ports) ? resources.ports : []) {
|
||||
add(port, "additional");
|
||||
}
|
||||
return Array.from(uses.values());
|
||||
}
|
||||
|
||||
function serverEntryAssignedHostPorts(entry) {
|
||||
return assignedServerPortUses(entry).map(use => use.port);
|
||||
}
|
||||
|
||||
module.exports = { NODE_SERVER_ASSIGNMENT_WHERE, nodeServerAssignmentParams, assignedServerPortUses, serverEntryAssignedHostPorts };
|
||||
Reference in new issue
Block a user