From 5c13c3860c81ec28d171160c631419160670079a Mon Sep 17 00:00:00 2001 From: azures04 Date: Mon, 19 Jan 2026 01:58:26 +0100 Subject: [PATCH] first commit --- .env.example | 3 + .gitignore | 134 +++++++++++++++++++++++++++++++++++++++++ LICENSE | 9 +++ README.md | 2 + package-lock.json | 28 +++++++++ package.json | 23 +++++++ src/core/cosmetics.js | 54 +++++++++++++++++ src/core/moderation.js | 96 +++++++++++++++++++++++++++++ src/core/player.js | 97 +++++++++++++++++++++++++++++ src/lib.js | 47 +++++++++++++++ test.js | 9 +++ 11 files changed, 502 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/core/cosmetics.js create mode 100644 src/core/moderation.js create mode 100644 src/core/player.js create mode 100644 src/lib.js create mode 100644 test.js diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a9f5862 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +# Credentials +USERNAME="username" +PASSWORD="password" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f2628a --- /dev/null +++ b/.gitignore @@ -0,0 +1,134 @@ +# ---> Node +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +#Bifrost Globals +data/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..32ab865 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2026 azures04 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b658649 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Bifrost + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c6c4b84 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "bifrost", + "version": "0.0.1-alpha", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "bifrost", + "version": "0.0.1-alpha", + "license": "MIT", + "dependencies": { + "dotenv": "^17.2.3" + } + }, + "node_modules/dotenv": { + "version": "17.2.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", + "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..847df0b --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "bifrost", + "version": "0.0.1-alpha", + "description": "a simple tool to interact with my own yggdrasil api and services\"a simple tool to interact with my own yggdrasil api and services", + "repository": { + "type": "git", + "url": "https://gitea.azures.fr/azures04/Bifrost" + }, + "license": "MIT", + "author": { + "url": "https://gitea.azures.fr/Azures04", + "name": "azures04", + "email": "gilleslazure04@gmail.com" + }, + "type": "commonjs", + "main": "src/lib.js", + "scripts": { + "test": "node ." + }, + "dependencies": { + "dotenv": "^17.2.3" + } +} diff --git a/src/core/cosmetics.js b/src/core/cosmetics.js new file mode 100644 index 0000000..6d17f1a --- /dev/null +++ b/src/core/cosmetics.js @@ -0,0 +1,54 @@ +const fs = require("node:fs") +const crypto = require("node:crypto") + +class CosmeticsManager { + #token + #api + + constructor(token, api) { + this.#api = api + this.#token = token + } + + async uploadCape(capePath, capeAlias = "") { + try { + const fileBuffer = fs.readFileSync(capePath) + const fileBlob = new Blob([fileBuffer], { type: "image/png" }) + + const formData = new FormData() + formData.append("file", fileBlob, `${crypto.randomUUID()}.png`) + formData.append("alias", capeAlias) + + const request = await fetch(`${this.#api}/admin/cosmetics/capes/upload`, { + method: "POST", + headers: { + "Authorization": `Bearer ${this.#token}` + }, + body: formData + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async removeCape(capeHash) { + try { + const request = await fetch(`${this.#api}/admin/cosmetics/capes/${capeHash}`, { + method: "DELETE", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } +} + +module.exports = CosmeticsManager \ No newline at end of file diff --git a/src/core/moderation.js b/src/core/moderation.js new file mode 100644 index 0000000..9c7a582 --- /dev/null +++ b/src/core/moderation.js @@ -0,0 +1,96 @@ +class ModerationManager { + #token + #api + + constructor(token, api) { + this.#api = api + this.#token = token + } + + async getProfilesBanStatus(playerUUID) { + try { + const request = await fetch(`${this.#api}/admin/ban/${playerUUID}`, { + method: "GET", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async getProfilesBanHistory(playerUUID) { + try { + const request = await fetch(`${this.#api}/admin/ban/${playerUUID}/history`, { + method: "GET", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async getProfilesActions(playerUUID) { + try { + const request = await fetch(`${this.#api}/admin/ban/${playerUUID}/actions`, { + method: "GET", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async banPlayer(playerUUID, reasonKey, reasonMessage, duration) { + try { + const request = await fetch(`${this.#api}/admin/ban/${playerUUID}`, { + method: "PUT", + headers: { + "Authorization": `Bearer ${this.#token}` + }, + body: JSON.stringify({ + duration, + reasonKey, + reasonMessage, + }) + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async unbanPlayer(playerUUID) { + try { + const request = await fetch(`${this.#api}/admin/ban/${playerUUID}`, { + method: "DELETE", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } +} + +module.exports = ModerationManager \ No newline at end of file diff --git a/src/core/player.js b/src/core/player.js new file mode 100644 index 0000000..626d758 --- /dev/null +++ b/src/core/player.js @@ -0,0 +1,97 @@ +class PlayerManager { + #token + #api + + constructor(token, api) { + this.#api = api + this.#token = token + } + + async revokeCape(playerUUID, capeHash) { + try { + const request = await fetch(`${this.#api}/admin/players/textures/cape/${playerUUID}/${capeHash}`, { + method: "DELETE", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async grantCape(playerUUID, capeHash) { + try { + const request = await fetch(`${this.#api}/admin/players/textures/cape/${playerUUID}/${capeHash}`, { + method: "PUT", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async resetSkin(playerUUID) { + try { + const request = await fetch(`${this.#api}/admin/players/textures/skin/${playerUUID}`, { + method: "DELETE", + headers: { + "Authorization": `Bearer ${this.#token}` + } + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async changePassword(playerUUID, newPassword) { + try { + const request = await fetch(`${this.#api}/admin/players/textures/skin/${playerUUID}`, { + method: "POST", + headers: { + "Authorization": `Bearer ${this.#token}` + }, + body: JSON.stringify({ + newPassword + }) + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } + + async changeUsername(playerUUID, newUsername) { + try { + const request = await fetch(`${this.#api}/admin/players/textures/skin/${playerUUID}`, { + method: "POST", + headers: { + "Authorization": `Bearer ${this.#token}` + }, + body: JSON.stringify({ + newUsername + }) + }) + + const response = await request.json() + return response + } catch (error) { + throw error + } + } +} + +module.exports = PlayerManager \ No newline at end of file diff --git a/src/lib.js b/src/lib.js new file mode 100644 index 0000000..e689550 --- /dev/null +++ b/src/lib.js @@ -0,0 +1,47 @@ +const CosmecticsManager = require("./core/cosmetics") +const ModerationManager = require("./core/moderation") +const PlayerManager = require("./core/player") + +class Bifrost { + #token + #api + + constructor(api = "https://yggdrasil.azures.fr/") { + this.#token = "" + this.#api = api.replace(/\/+$/, "") + } + + async login(username, password) { + try { + const loginState = await fetch(`${this.#api}/admin/login`, { + headers: { + "content-type": "application/json" + }, + method: "POST", + body: JSON.stringify({ + username, + password + }) + }) + if (!loginState.status == 200) { + console.log(loginState.text()) + throw new Error("Failed to login") + } + + const json = await loginState.json() + this.#token = json.token + return { + cosmectics: new CosmecticsManager(this.#token, this.#api), + moderation: new ModerationManager(this.#token, this.#api), + player: new PlayerManager(this.#token, this.#api), + } + } catch (error) { + console.error(error) + return process.exit(1) + } + } +} + +module.exports = { + Bifrost +} \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..60bd11d --- /dev/null +++ b/test.js @@ -0,0 +1,9 @@ +require("dotenv").config() +const { Bifrost } = require("./src/lib") +const bifrost = new Bifrost() + +async function main() { + const client = await bifrost.login(process.env.USERNAME, process.env.PASSWORD) +} + +main() \ No newline at end of file