Create new Miiverse endpoint creation script

This commit is contained in:
Matthew Lopez
2023-12-21 20:01:24 -05:00
parent 57a9f83434
commit 4ef90ce2bb
3 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
// This should run in the miiverse-api container
const mongoose = require("mongoose");
const { connect } = require("./dist/database");
const { Endpoint } = require("./dist/models/endpoint");
async function runAsync() {
await connect();
await resetEndpoints();
await createEndpoint(
0,
"dev",
"api.olv.pretendo.cc",
"api.olv.pretendo.cc",
"portal.olv.pretendo.cc",
"ctr.olv.pretendo.cc"
);
await mongoose.connection.close();
}
runAsync().then(() => {
console.log("Done creating endpoints.");
process.exit(0);
});
async function resetEndpoints() {
console.log("Deleting all endpoints...");
await Endpoint.deleteMany({});
console.log("Endpoint collection reset.");
}
async function createEndpoint(
status,
server_access_level,
host,
api_host,
portal_host,
n3ds_host
) {
const newEndpoint = new Endpoint({
status: status,
server_access_level: server_access_level,
// Unused
topics: true,
// Unused
guest_access: true,
host: host,
api_host: api_host,
portal_host: portal_host,
n3ds_host: n3ds_host,
});
console.log("Saving new endpoint:");
console.log(newEndpoint);
await newEndpoint.save();
}

View File

@@ -1,3 +1,4 @@
// This should run in the account container
const mongoose = require("mongoose");
const { connect } = require("./dist/database");
const { Server } = require("./dist/models/server");

View File

@@ -9,6 +9,7 @@ done
git_base=$(git rev-parse --show-toplevel)
create_server_script=$(cat "$git_base/scripts/run-in-container/create-server-in-database.js")
create_endpoint_script=$(cat "$git_base/scripts/run-in-container/create-endpoint-in-database.js")
necessary_environment="friends miiverse-api wiiu-chat"
. "$git_base/environment/system.local.env"
@@ -26,5 +27,9 @@ docker compose exec -e COMPUTER_IP="$COMPUTER_IP" \
-e WIIU_CHAT_PORT="$PN_WIIU_CHAT_AUTHENTICATION_SERVER_PORT" \
account node -e "$create_server_script"
docker compose up -d miiverse-api
docker compose exec miiverse-api node -e "$create_endpoint_script"
# TODO: Script should a PNID's access_level to 3 and server_access_level to dev
# so users can access the servers