main
BuildTools 2023-05-06 23:55:04 -04:00
parent 07e51b77dc
commit f21c44abd4
4 changed files with 87 additions and 74 deletions

View File

@ -1,6 +1,6 @@
const SERVER = "192.168.1.199:3435";
async function register() { async function register(e) {
e.preventDefault();
const name = document.getElementById("name").value; const name = document.getElementById("name").value;
if (!name) return; if (!name) return;
const keys = await openpgp.generateKey({ const keys = await openpgp.generateKey({
@ -50,7 +50,7 @@ async function loadMessages() {
} }
window.onload = () => { window.onload = () => {
window.socket = io(SERVER); window.socket = io();
window.socket.on("create_user", swap); window.socket.on("create_user", swap);
window.socket.on("new_message", (msg) => { window.socket.on("new_message", (msg) => {
const el = document.createElement("div"); const el = document.createElement("div");
@ -77,7 +77,7 @@ window.onload = () => {
window.name = localStorage.getItem("name"); window.name = localStorage.getItem("name");
loadKeys(JSON.parse(keys)).then(swap); loadKeys(JSON.parse(keys)).then(swap);
} }
document.getElementById("submit").onclick = register; document.getElementById("registerform").onsubmit = register;
document.getElementById("msginput").onsubmit = message; document.getElementById("msginput").onsubmit = message;
document.getElementById("loadmore").onclick = loadMessages; document.getElementById("loadmore").onclick = loadMessages;
}; };

View File

@ -1,56 +1,58 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>vybe</title> <title>vybe</title>
<style> <style>
* { * {
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif; sans-serif;
} }
body { body {
background: #171719; background: #171719;
color: #d8d8d8; color: #d8d8d8;
} }
.hidden { .hidden {
display: none; display: none;
} }
#msginput { #msginput {
margin-top: 15px; margin-top: 15px;
} }
.message { .message {
margin-bottom: 5px; margin-bottom: 5px;
} }
</style> </style>
</head> </head>
<body> <body>
<div id="register"> <div id="register">
<h1>welcome to vybe</h1> <h1>welcome to vybe</h1>
<h3>this site is in beta</h3> <h3>this site is in beta</h3>
<p> <p>
to get started, you'll need to set up an account. we use public key to get started, you'll need to set up an account. we use public key
cryptography for security, rather than passwords. in this early beta cryptography for security, rather than passwords. in this early beta
version your keys are stored in your browser storage only. version your keys are stored in your browser storage only.
</p> </p>
<label for="name">name/username</label> <form id="registerform">
<input type="text" id="name" /> <label for="name">name/username</label>
<button id="submit">generate keys & register</button> <input type="text" id="name" />
</div> <button id="submit" type="submit">generate keys & register</button>
<div id="chat" class="hidden"> </form>
<h1>vybe</h1> </div>
<h3>messages will appear below as they are sent</h3> <div id="chat" class="hidden">
<button id="loadmore">load more messages</button> <h1>vybe</h1>
<div id="messages"></div> <h3>messages will appear below as they are sent</h3>
<form id="msginput"> <button id="loadmore">load more messages</button>
<input type="text" placeholder="write a message..." id="msg" /> <div id="messages"></div>
<button type="submit" class="hidden" id="sendmsg"></button> <form id="msginput">
</form> <input type="text" placeholder="write a message..." id="msg" />
</div> <button type="submit" class="hidden" id="sendmsg"></button>
<script src="/openpgp.min.js"></script> </form>
<script src="/chat.js"></script> </div>
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script> <script src="/openpgp.min.js"></script>
</body> <script src="/chat.js"></script>
</html> <script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
</body>
</html>

37
db.js
View File

@ -1,14 +1,23 @@
const sqlite3 = require("sqlite3"); const sqlite3 = require("sqlite3");
const db = new sqlite3.Database("./vybe.db"); const fs = require('fs');
const db = new sqlite3.Database('vybe.db');
db.query = function (sql, params) {
var that = this; db.query = function (sql, params) {
return new Promise(function (resolve, reject) { var that = this;
that.all(sql, params, function (error, rows) { return new Promise(function (resolve, reject) {
if (error) reject(error); that.all(sql, params, function (error, rows) {
else resolve({ rows: rows }); if (error) reject(error);
}); else resolve({ rows: rows });
}); });
}; });
};
module.exports = db;
(async () => {
if (!fs.existsSync('vybe.db')) {
console.log(fs.readFileSync('db/1-init.sql').toString().split(';'))
for(let sql of fs.readFileSync('db/1-init.sql').toString().split(';'))
await db.query(sql);
}
})();
module.exports = db;

View File

@ -24,3 +24,5 @@ io.on("connection", (socket) => {
server.listen(PORT, () => { server.listen(PORT, () => {
console.log("server running on port " + PORT); console.log("server running on port " + PORT);
}); });
app.use(express.static('client'));