Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
od-spell-caster
/node_modules
17 changes: 5 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
FROM golang AS build
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /od-spell-caster .
FROM oven/bun:slim AS build

FROM scratch
COPY --from=build /od-spell-caster /od-spell-caster
COPY main.ts main.ts
COPY util.ts util.ts
COPY consts.ts consts.ts

# bandaid fix
# we'll have to fix this later...
# COPY ./fullchain.pem fullchain.pem
# COPY ./privkey.pem privkey.pem
# COPY ./ash.yaml ./ash.yaml
CMD ["/od-spell-caster"]
ENTRYPOINT ["bun", "run", "main.ts"]
24 changes: 24 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pipeline {
agent any

stages {

stage('Docker Build') {
steps {
sh 'docker compose build'
}
}

stage('Docker Kill') {
steps {
sh 'docker compose down --rmi \'all\''
}
}

stage('Docker Run') {
steps {
sh 'docker compose up -d'
}
}
}
}
29 changes: 29 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
services:
od-ash_tray:
od-spell-caster:
build: .
ports:
- "0.0.0.0:4242:4242"
# environment:
# - ASH_TRAY_ID
# - ASH_TRAY_DIRECTORY=/cdn
# - ASH_TRAY_KEY
# - ASH_TRAY_PORT=7377
# volumes:
# - /cdn:/cdn:rw
# - /etc/letsencrypt/live/onlinedi.vision:/certs:r
- "0.0.0.0:6666:6666"

9 changes: 9 additions & 0 deletions consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const spell_cast_api = 'https://onlinedi.vision/api/spell/cast';
const get_user_servers_api = 'https://onlinedi.vision/api/get_user_servers'
const port = 6666;

module.exports = {
spell_cast_api,
get_user_servers_api,
port
};
52 changes: 19 additions & 33 deletions main.js → main.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,48 @@
const spell_cast_api = 'https://onlinedi.vision/api/spell/cast';
const consts = require('./consts.ts');
const util = require('./util.ts');

let spell_key = '';
let all_ws = {'1313': []};
let connected_ws = [];
let secrets = [];

async function addSecretToScylla(username) {
let payload = await fetch(
spell_cast_api,
{
method: 'POST',
body: {
'username': username
}
}
);

if(!payload.ok) {
console.log("[FAILED FETCH] [addSecretToScylla]" + username)
return
}

let secret = JSON.parse(await payload.json());
return [ secret['key'], secret['spell'] ];
}

async function includeAllServers(username) {}

async function registerSpellKey() {}
console.log("Starting Websockets Server on port: " + consts.port);

Bun.serve({
port: consts.port,

fetch(req, server) {

console.log('[LOG] [Bun.serve] Upgrading ' + req);

server.upgrade(req,{
data: {
username: new URL(req.url).searchParams.get('username')
}
}));
});
return new Response("Upgrade failed", { status: 500 });
},

websocket: {
data,
async message(ws, message) {
console.log(all_ws);

console.log('[LOG] [message]');
if(!connected_ws.includes(ws) && secrets.includes(message)) {
connected_ws.push(ws);
console.log(connected_ws);

let payload = await includeAllServers(data['username']);
if(payload.ok) {
ws.send("CONNECTED");
return
} else {
ws.send("ERROR");
}
return;
}

if(message.startsWith("TOKEN:")) {
let token = await util.includeAllServers(data.username, message.split(":")[1]);

ws.send(token);
return;
}

Object.keys(all_ws).forEach((key) => {
if(all_ws[key].includes(ws)) {
Expand All @@ -69,7 +55,7 @@ Bun.serve({
},

async open(ws) {
let res = await addSecretToScylla(data['username']);
let res = await util.addSecretToScylla(data['username']);
let [ key, spell ] = res;
secrets.push(spell);
ws.send(key);
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "od-spell-caster",
"private": true,
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5"
}
}
29 changes: 29 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": false,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
49 changes: 49 additions & 0 deletions util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const consts = require('./consts.ts');

async function addSecretToScylla(username) {
let payload = await fetch(
consts.spell_cast_api,
{
method: 'POST',
body: {
'username': username
}
}
);

if(!payload.ok) {
console.log("[FAILED FETCH] [addSecretToScylla]" + username)
return
}

let secret = JSON.parse(await payload.json());
return [ secret['key'], secret['spell'] ];
}

async function includeAllServers(username, token) {
let get_user_servers_payload = await fetch(
consts.get_user_servers_api,
{
method: 'POST',
body: {
'username': username,
'token': token
}
}
).json();

for (let sid in get_user_servers_paylod['s_list']) {
if(!all_ws.has(sid)) {
all_ws.set(sid, []);
}
all_ws.get(sid).push(sid);
}

return token;
}

module.exports = {
addSecretToScylla,
includeAllServers
};