first commit
This commit is contained in:
commit
5c13c3860c
3
.env.example
Normal file
3
.env.example
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Credentials
|
||||||
|
USERNAME="username"
|
||||||
|
PASSWORD="password"
|
||||||
134
.gitignore
vendored
Normal file
134
.gitignore
vendored
Normal file
@ -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/
|
||||||
9
LICENSE
Normal file
9
LICENSE
Normal file
@ -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.
|
||||||
28
package-lock.json
generated
Normal file
28
package-lock.json
generated
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
package.json
Normal file
23
package.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/core/cosmetics.js
Normal file
54
src/core/cosmetics.js
Normal file
@ -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
|
||||||
96
src/core/moderation.js
Normal file
96
src/core/moderation.js
Normal file
@ -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
|
||||||
97
src/core/player.js
Normal file
97
src/core/player.js
Normal file
@ -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
|
||||||
47
src/lib.js
Normal file
47
src/lib.js
Normal file
@ -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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user