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

View File

@ -1,56 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>vybe</title>
<style>
* {
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
}
body {
background: #171719;
color: #d8d8d8;
}
.hidden {
display: none;
}
#msginput {
margin-top: 15px;
}
.message {
margin-bottom: 5px;
}
</style>
</head>
<body>
<div id="register">
<h1>welcome to vybe</h1>
<h3>this site is in beta</h3>
<p>
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
version your keys are stored in your browser storage only.
</p>
<label for="name">name/username</label>
<input type="text" id="name" />
<button id="submit">generate keys & register</button>
</div>
<div id="chat" class="hidden">
<h1>vybe</h1>
<h3>messages will appear below as they are sent</h3>
<button id="loadmore">load more messages</button>
<div id="messages"></div>
<form id="msginput">
<input type="text" placeholder="write a message..." id="msg" />
<button type="submit" class="hidden" id="sendmsg"></button>
</form>
</div>
<script src="/openpgp.min.js"></script>
<script src="/chat.js"></script>
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>vybe</title>
<style>
* {
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
}
body {
background: #171719;
color: #d8d8d8;
}
.hidden {
display: none;
}
#msginput {
margin-top: 15px;
}
.message {
margin-bottom: 5px;
}
</style>
</head>
<body>
<div id="register">
<h1>welcome to vybe</h1>
<h3>this site is in beta</h3>
<p>
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
version your keys are stored in your browser storage only.
</p>
<form id="registerform">
<label for="name">name/username</label>
<input type="text" id="name" />
<button id="submit" type="submit">generate keys & register</button>
</form>
</div>
<div id="chat" class="hidden">
<h1>vybe</h1>
<h3>messages will appear below as they are sent</h3>
<button id="loadmore">load more messages</button>
<div id="messages"></div>
<form id="msginput">
<input type="text" placeholder="write a message..." id="msg" />
<button type="submit" class="hidden" id="sendmsg"></button>
</form>
</div>
<script src="/openpgp.min.js"></script>
<script src="/chat.js"></script>
<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 db = new sqlite3.Database("./vybe.db");
db.query = function (sql, params) {
var that = this;
return new Promise(function (resolve, reject) {
that.all(sql, params, function (error, rows) {
if (error) reject(error);
else resolve({ rows: rows });
});
});
};
module.exports = db;
const sqlite3 = require("sqlite3");
const fs = require('fs');
const db = new sqlite3.Database('vybe.db');
db.query = function (sql, params) {
var that = this;
return new Promise(function (resolve, reject) {
that.all(sql, params, function (error, rows) {
if (error) reject(error);
else resolve({ rows: rows });
});
});
};
(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, () => {
console.log("server running on port " + PORT);
});
app.use(express.static('client'));