Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from LITdevs/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
emilianya authored Nov 14, 2023
2 parents 52efc49 + 7fb4239 commit 23a7ae9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 95 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "lightquark",
"version": "0.0.49",
"version": "0.0.53",
"description": "Proof of Concept",
"exports": "./src/index.ts",
"repository": "https://github.com/LITdevs/Lightquark.git",
Expand All @@ -21,7 +21,7 @@
"file-type": "^18.0.0",
"form-data": "^4.0.0",
"jose": "^4.10.4",
"mongoose": "^7.6.4",
"mongoose": "^8.0.0",
"sharp": "^0.32.1",
"tail": "^2.2.4",
"typescript": "^4.8.4",
Expand Down
65 changes: 1 addition & 64 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fs from "fs";
import { initialize } from 'unleash-client';
import {kitty} from "./util/kitty.js";
export const networkInformation = JSON.parse(fs.readFileSync("network.json").toString());
const pjson = JSON.parse(fs.readFileSync("package.json").toString());
export const pjson = JSON.parse(fs.readFileSync("package.json").toString());
const app = express();

Sentry.init({
Expand Down Expand Up @@ -73,70 +73,7 @@ app.use("/v2/channel", channelv2);
import home from './routes/home.js';
app.use("/", home)

app.get("/v*/network", (req, res) => {
networkInformation.version = pjson.version;
networkInformation.capabilities = {
base: true, // Everything before capabilities was added
userStatus: unleash.isEnabled("LQ_Status", res.locals.unleashContext) // User statuses
}
res.json(networkInformation);
})
/*
app.post("/roleCreateTest", async (req, res) => {
let Role = db.getRoles();
let role = new Role({
name: "Test Role",
color: "#000000",
quark: "643aa2e550c913775aec2058",
description: "This is a test role",
createdBy: "646893a40ca841fd8e8f953e",
priority: 0
})
await role.save();
res.json(role);
})

app.get("/roleGetTest", async (req, res) => {
let Role = db.getRoles();
console.time("roleGetTest")
// Find role 646894100df66a3fc81e0919 and populate permissionAssignments
let role = await Role.findById("646897a40644cbd91f00d400").populate("permissionAssignments").populate("roleAssignments");
console.timeEnd("roleGetTest")
res.json(role);
})
app.get("/paGetTest", async (req, res) => {
let PA = db.getPermissionAssignments();
console.time("paGetTest")
// Find role 646894100df66a3fc81e0919 and populate permissionAssignments
let pa = await PA.findById("646898dbefcff8c704e31f19").populate("role");
console.timeEnd("paGetTest");
res.json(pa);
})
app.post("/permissionCreateTest", async (req, res) => {
let PermissionAssignment = db.getPermissionAssignments();
let pa = new PermissionAssignment({
role: "646897a40644cbd91f00d400",
permission: "ADMIN",
type: "allow",
scopeType: "quark",
scopeId: "643aa2e550c913775aec2058"
})
await pa.save();
res.json(pa);
})
app.post("/raCreateTest", async (req, res) => {
let RoleAssignment = db.getRoleAssignments();
let ra = new RoleAssignment({
role: "646897a40644cbd91f00d400",
user: "646893a40ca841fd8e8f953e"
})
await ra.save();
res.json(ra);
})
*/

app.all("*", (req, res) => {
res.reply(new NotFoundReply("Endpoint not found"));
Expand Down
11 changes: 10 additions & 1 deletion src/routes/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const knownClients = JSON.parse(fs.readFileSync("src/util/knownClients.json").to
import CapabilityParser from "../util/CapabilityParser.js";
import ServerErrorReply from "../classes/reply/ServerErrorReply.js";
import db from "../db.js";
import {networkInformation} from "../index.js";
import {networkInformation, pjson, unleash} from "../index.js";

router.get("/features/:clientName", async (req, res) => {
try {
Expand Down Expand Up @@ -146,4 +146,13 @@ router.get("/v*/stats", (req, res ) => {
})
})

router.get("/v*/network", (req, res) => {
networkInformation.version = pjson.version;
networkInformation.capabilities = {
base: true, // Everything before capabilities was added
userStatus: unleash.isEnabled("LQ_Status", res.locals.unleashContext) // User statuses
}
res.json(networkInformation);
})

export default router;
6 changes: 3 additions & 3 deletions src/routes/v1/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function handleMessage(message, ws, user, socketId) {
if (validEvent !== 1) return ws.send(JSON.stringify({
eventId: "error",
message: "Invalid event",
attemptedEvent: event,
event,
code: validEvent
}));

Expand All @@ -111,13 +111,13 @@ async function handleMessage(message, ws, user, socketId) {
await sm.subscribe(event, sub, user, socketId);
ws.send(JSON.stringify({eventId: "subscribe", message: "Successfully subscribed to event", code: 200}));
} else {
ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403}));
ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403, event}));
}
} else if (event.split("_")[0] === "quark") {
let Quarks = db.getQuarks();
try {
let quark = await Quarks.findOne({_id: event.split("_")[1], members: user._id});
if (!quark) return ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403}));
if (!quark) return ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403, event}));
const sub = (data) => {
ws.send(JSON.stringify(data));
}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v2/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ router.delete("/:id", Auth, P("DELETE_CHANNEL", "channel"), async (req, res) =>
/**
* Edit a channel by id
*/
// TODO: Allow roles to edit channels
router.patch("/:id", Auth, async (req, res) => {
if (!req.params.id) return res.status(400).json(new InvalidReplyMessage("Provide a channel id"));
if (!mongoose.isValidObjectId(req.params.id)) return res.status(400).json(new InvalidReplyMessage("Invalid channel id"));
Expand Down Expand Up @@ -312,7 +311,8 @@ router.post("/:id/messages", Auth, P("WRITE_MESSAGE", "channel"), RequiredProper
_id: res.locals.user._id,
username: await getNick(res.locals.user._id, quark._id),
avatarUri: res.locals.user.avatar,
admin: !!res.locals.user.admin
admin: !!res.locals.user.admin,
isBot: !!res.locals.user.isBot
}
let data = {
eventId: "messageCreate",
Expand Down
44 changes: 21 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ asynckit@^0.4.0:
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

axios@^1.1.3:
version "1.5.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.0.tgz#f02e4af823e2e46a9768cfc74691fdd0517ea267"
integrity sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==
axios@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7"
integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
Expand Down Expand Up @@ -353,10 +353,10 @@ braces@~3.0.2:
dependencies:
fill-range "^7.0.1"

bson@^5.5.0:
version "5.5.1"
resolved "https://registry.yarnpkg.com/bson/-/bson-5.5.1.tgz#f5849d405711a7f23acdda9a442375df858e6833"
integrity sha512-ix0EwukN2EpC0SRWIj/7B5+A6uQMQy6KMREI9qQqvgpkV2frH63T0UDVd1SYedL6dNCmDBYB3QtXi4ISk9YT+g==
bson@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/bson/-/bson-6.2.0.tgz#4b6acafc266ba18eeee111373c2699304a9ba0a3"
integrity sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==

buffer@^5.5.0:
version "5.7.1"
Expand Down Expand Up @@ -1188,25 +1188,23 @@ mongodb-connection-string-url@^2.6.0:
"@types/whatwg-url" "^8.2.1"
whatwg-url "^11.0.0"

mongodb@5.9.0:
version "5.9.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-5.9.0.tgz#5a22065fa8cfaf1d58bf2e3c451cd2c4bfa983a2"
integrity sha512-g+GCMHN1CoRUA+wb1Agv0TI4YTSiWr42B5ulkiAfLLHitGK1R+PkSAf3Lr5rPZwi/3F04LiaZEW0Kxro9Fi2TA==
mongodb@6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-6.2.0.tgz#2c9dcb3eeaf528ed850e94b3df392de6c6b0d7ab"
integrity sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==
dependencies:
bson "^5.5.0"
mongodb-connection-string-url "^2.6.0"
socks "^2.7.1"
optionalDependencies:
"@mongodb-js/saslprep" "^1.1.0"
bson "^6.2.0"
mongodb-connection-string-url "^2.6.0"

mongoose@^7.6.4:
version "7.6.4"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-7.6.4.tgz#2f6b796789d0d24636cd7607d7d9c7a302bb550b"
integrity sha512-kadPkS/f5iZJrrMxxOvSoOAErXmdnb28lMvHmuYgmV1ZQTpRqpp132PIPHkJMbG4OC2H0eSXYw/fNzYTH+LUcw==
mongoose@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-8.0.0.tgz#f14175eebfaf5256855d7cbd58bf862819b3fd12"
integrity sha512-PzwkLgm1Jhj0NQdgGfnFsu0QP9V1sBFgbavEgh/IPAUzKAagzvEhuaBuAQOQGjczVWnpIU9tBqyd02cOTgsPlA==
dependencies:
bson "^5.5.0"
bson "^6.2.0"
kareem "2.5.1"
mongodb "5.9.0"
mongodb "6.2.0"
mpath "0.9.0"
mquery "5.0.0"
ms "2.1.3"
Expand Down Expand Up @@ -1644,7 +1642,7 @@ socks-proxy-agent@^7.0.0:
debug "^4.3.3"
socks "^2.6.2"

socks@^2.6.2, socks@^2.7.1:
socks@^2.6.2:
version "2.7.1"
resolved "https://registry.yarnpkg.com/socks/-/socks-2.7.1.tgz#d8e651247178fde79c0663043e07240196857d55"
integrity sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==
Expand Down

1 comment on commit 23a7ae9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes deployed to server
Branch prod

Please sign in to comment.