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

@ -35,9 +35,11 @@
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>
<form id="registerform">
<label for="name">name/username</label> <label for="name">name/username</label>
<input type="text" id="name" /> <input type="text" id="name" />
<button id="submit">generate keys & register</button> <button id="submit" type="submit">generate keys & register</button>
</form>
</div> </div>
<div id="chat" class="hidden"> <div id="chat" class="hidden">
<h1>vybe</h1> <h1>vybe</h1>

11
db.js
View File

@ -1,5 +1,6 @@
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) { db.query = function (sql, params) {
var that = this; var that = this;
@ -11,4 +12,12 @@ db.query = function (sql, params) {
}); });
}; };
(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; 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'));