2021-10-26 11:02:32 -04:00
|
|
|
const { checkLogin } = require("../util-server");
|
|
|
|
const Database = require("../database");
|
|
|
|
|
2022-04-21 12:10:23 -04:00
|
|
|
/**
|
|
|
|
* Handlers for database
|
|
|
|
* @param {Socket} socket Socket.io instance
|
2023-08-11 03:46:41 -04:00
|
|
|
* @returns {void}
|
2022-04-21 12:10:23 -04:00
|
|
|
*/
|
2024-08-24 12:40:50 -04:00
|
|
|
module.exports.databaseSocketHandler = (socket) => {
|
2021-10-26 11:02:32 -04:00
|
|
|
|
|
|
|
// Post or edit incident
|
|
|
|
socket.on("getDatabaseSize", async (callback) => {
|
|
|
|
try {
|
|
|
|
checkLogin(socket);
|
|
|
|
callback({
|
|
|
|
ok: true,
|
|
|
|
size: Database.getSize(),
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
callback({
|
|
|
|
ok: false,
|
|
|
|
msg: error.message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("shrinkDatabase", async (callback) => {
|
|
|
|
try {
|
|
|
|
checkLogin(socket);
|
2024-03-15 10:02:55 -04:00
|
|
|
await Database.shrink();
|
2021-10-26 11:02:32 -04:00
|
|
|
callback({
|
|
|
|
ok: true,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
callback({
|
|
|
|
ok: false,
|
|
|
|
msg: error.message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|