werefox-cafe/src/info/pages/minecraft/index.js.unused

105 lines
2.8 KiB
Plaintext

import HomePage from "../../components/home-page";
import ICard from "../../components/introduction-card";
import WCard from "../../components/werefox-card";
import axios from "axios";
export const getPlugins = async () =>
await axios
.get("http://192.168.0.202:8111/api/plugins/list", {
headers: {
authorization:
"rawCvRhEhSJR9TDo9Snw25ZyNYzTKERMsZSVbseqMTyh957JhpbhspderiUAzb7d",
},
})
.then(
(result) => {
return result.data;
},
(error) => {
console.log(error);
return null;
}
);
// Yes, I know that I'm posting this authorization key publicly and that isn't generally a safe practice, but if someone can actually access that address in my local network, I have bigger problems.
export const getInfo = async () =>
await axios
.get("http://192.168.0.202:8111/api/server", {
headers: {
authorization:
"rawCvRhEhSJR9TDo9Snw25ZyNYzTKERMsZSVbseqMTyh957JhpbhspderiUAzb7d",
},
})
.then(
(result) => {
return result.data;
},
(error) => {
console.log(error);
return null;
}
);
// Grab data from a static YAML file
export async function getStaticProps() {
const fs = require("fs");
const yaml = require("js-yaml");
let INTRODUCTION = {};
const info = await Promise.resolve(getInfo());
const plugins = await Promise.resolve(getPlugins());
const plugins_sorted = plugins.plugins
.map((p) => {
return p[0].toUpperCase() + p.substr(1);
})
.sort();
try {
let fileContent = fs.readFileSync(
"./data/minecraft/introduction.yml",
"utf8"
);
INTRODUCTION = yaml.load(fileContent);
} catch (e) {
console.log(e);
}
return {
props: {
INTRODUCTION,
plugins_list: plugins_sorted,
server_info: info,
},
};
}
export default function Minecraft({ plugins_list, server_info, INTRODUCTION }) {
const server_info_keys = {
serverVersion: "Server Version",
serverBukkitVersion: "Bukkit Version",
};
return (
<HomePage
theme="Ada"
page_title="Minecraft Server Info"
card_title="Minecraft Server Info"
>
<WCard theme="Ada" title="Queercule Minecraft Server">
<ICard theme="Ada" introduction={INTRODUCTION.intro} emoji_paths={{}} />
</WCard>
<WCard theme="Ada" title="Server Info">
{Object.keys(server_info_keys).map((key) => (
<div key={key} className="">
{server_info_keys[key]}: {server_info[key]}
</div>
))}
</WCard>
<WCard theme="Ada" title="Plugins">
{Object.keys(plugins_list).map((plugin) => (
<div key={plugin} className="">
- {plugins_list[plugin]}
</div>
))}
</WCard>
</HomePage>
);
}