Compare commits

..

5 Commits

Author SHA1 Message Date
sky
39cdf17e3e close socket 2025-10-26 15:30:09 -04:00
sky
55e3f5a3c4 fix websocket server 2025-10-26 15:21:43 -04:00
sky
496bc61c7d remove ads from some places 2025-10-26 14:47:13 -04:00
sky
204616a2d8 fix 2025-10-26 14:21:18 -04:00
sky
5770f28acb Merge pull request 'v2' (#1) from development into main
Reviewed-on: #1
2025-10-26 12:54:21 -04:00
9 changed files with 57 additions and 12 deletions

View File

@ -271,6 +271,7 @@ async function generateAccountPage(name, cookie, admin) {
}
let modifiedHTML = rawProfileHTML;
console.log(userData.music);
let songData = JSON.parse(userData.music) || false;
modifiedHTML = modifiedHTML.replaceAll("{{ name }}", sanitizeHtml(userData.name, allowNone));
modifiedHTML = modifiedHTML.replaceAll("{{ join_date }}", dayjs(userData.createdAt).fromNow());

View File

@ -44,7 +44,6 @@
<!-- seo + other things -->
<title>{{ name }}'s Profile | Selenite</title>
<link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", ()=>{
let music = {{ is_music }};

View File

@ -44,7 +44,6 @@
<!-- seo + other things -->
<title>{{ name }}'s Profile | Selenite</title>
<link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
<!-- <script>
let audioObject;
document.addEventListener("DOMContentLoaded", ()=>{

View File

@ -123,7 +123,7 @@
});
</script>
<link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
</head>
<alerts> </alerts>
<body>

View File

@ -45,10 +45,20 @@ import WebSocket, { WebSocketServer } from "ws";
const wss = new WebSocketServer({ noServer: true });
// let openSockets = 0;
wss.on("connection", function connection(ws, req, res) {
ws.send(`online=${wss.clients.size}`);
setInterval(() => {
ws.send(`online=${wss.clients.size}`);
}, 10000);
// ws.send(`online=${wss.clients.size}`);
// setInterval(() => {
// ws.send(`online=${wss.clients.size}`);
// }, 10000);
let server = new WebSocket("ws://localhost:7910");
server.on("message", async function message(data) {
let message = Buffer.from(data).toString();
if(message.startsWith("online")) {
ws.send(message);
} else if(message.startsWith("annc")) {
ws.send(message);
}
})
ws.on("error", console.error);
@ -67,14 +77,15 @@ wss.on("connection", function connection(ws, req, res) {
} else if (message.startsWith("annc")) {
let splitMessage = message.split(";;");
if(await isAdmin(splitMessage[1])) {
wss.clients.forEach(client => {
client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
})
// wss.clients.forEach(client => {
// client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
// })
server.send(message);
}
}
});
ws.on("close", () => {});
ws.on("close", () => {server.close()});
});
app.post(
"/api/event",

View File

@ -4,6 +4,7 @@
"description": "",
"exports": "./index.js",
"scripts": {
"websocket_server": "bun --watch websocket.js",
"start": "bun --watch index.js",
"svg": "node svg-converter.js"
},

View File

@ -1,6 +1,6 @@
module.exports = {
name: "Selenite", // Name of your application
script: "index.js", // Entry point of your application
script: "start.cjs", // Entry point of your application
interpreter: "bun", // Path to the Bun interpreter
watch: true,
cron_restart: '0 0 * * *',

1
start.cjs Normal file
View File

@ -0,0 +1 @@
import('./index.js');

33
websocket.js Normal file
View File

@ -0,0 +1,33 @@
import WebSocket, { WebSocketServer } from "ws";
const wss = new WebSocketServer({ noServer: true });
wss.on("connection", function connection(ws, req, res) {
ws.send(`online=${wss.clients.size}`);
setInterval(() => {
ws.send(`online=${wss.clients.size}`);
}, 10000);
ws.on("message", async function message(data, isBinary) {
let message = Buffer.from(data).toString();
if (message.startsWith("annc")) {
let splitMessage = message.split(";;");
wss.clients.forEach(client => {
client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
})
}
});
ws.on("close", () => {});
});
let port = 7910;
import express from "express";
const app = express();
const server = app.listen(port, () => {
console.log("Websocket server is online.");
console.log("- http://localhost:" + port);
});
server.on("upgrade", (request, socket, head) => {
wss.handleUpgrade(request, socket, head, (socket) => {
wss.emit("connection", socket, request);
});
});