🚧 fix server bundle
This commit is contained in:
parent
f70a24ab6a
commit
194ef5478e
10
api/src/routes/users/@me/devices.ts
Normal file
10
api/src/routes/users/@me/devices.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post("/", (req: Request, res: Response) => {
|
||||
// TODO:
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
export default router;
|
||||
18
bundle/.vscode/launch.json
vendored
Normal file
18
bundle/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"sourceMaps": true,
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch server bundle",
|
||||
"program": "${workspaceFolder}/dist/start.js",
|
||||
"preLaunchTask": "tsc: build - tsconfig.json",
|
||||
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
|
||||
"envFile": "${workspaceFolder}/.env"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
bundle/package-lock.json
generated
BIN
bundle/package-lock.json
generated
Binary file not shown.
@ -4,7 +4,7 @@
|
||||
"description": "",
|
||||
"main": "src/start.js",
|
||||
"scripts": {
|
||||
"postinstall": "cd ../api/ && npm i && cd ../cdn/ && npm i && cd ../gateway/ && npm i && ",
|
||||
"postinstall": "cd ../api/ && npm i && cd ../cdn/ && npm i && cd ../gateway/ && npm i",
|
||||
"build": "npm run build:api && npm run build:cdn && npm run build:gateway && npm run build:bundle",
|
||||
"build:bundle": "tsc -b .",
|
||||
"build:api": "cd ../api/ && npm run build",
|
||||
|
||||
@ -9,9 +9,10 @@ import express from "express";
|
||||
import { Config } from "../../util/dist";
|
||||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
const server = http.createServer();
|
||||
const port = Number(process.env.PORT) || 8080;
|
||||
const production = true;
|
||||
server.on("request", app);
|
||||
|
||||
// @ts-ignore
|
||||
const api = new APIServer({ server, port, production, app });
|
||||
@ -22,8 +23,14 @@ const gateway = new GatewayServer({ server, port, production });
|
||||
|
||||
async function main() {
|
||||
await Config.set({
|
||||
cdn: { endpointClientKeepDefault: true, endpoint: `http://localhost:${port}` },
|
||||
gateway: { endpointClientKeepDefault: true, endpoint: `ws://localhost:${port}` },
|
||||
cdn: {
|
||||
endpointClient: "${location.host}",
|
||||
endpoint: `http://localhost:${port}`,
|
||||
},
|
||||
gateway: {
|
||||
endpointClient: '${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}',
|
||||
endpoint: `ws://localhost:${port}`,
|
||||
},
|
||||
});
|
||||
|
||||
await api.start();
|
||||
|
||||
29
fosscord-server.code-workspace
Normal file
29
fosscord-server.code-workspace
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "api"
|
||||
},
|
||||
{
|
||||
"path": "dashboard"
|
||||
},
|
||||
{
|
||||
"path": "bundle"
|
||||
},
|
||||
{
|
||||
"path": "cdn"
|
||||
},
|
||||
{
|
||||
"path": "gateway"
|
||||
},
|
||||
{
|
||||
"path": "rtc"
|
||||
},
|
||||
{
|
||||
"path": "util"
|
||||
},
|
||||
{
|
||||
"path": "webrtc"
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
||||
@ -23,6 +23,8 @@ export class Server {
|
||||
});
|
||||
|
||||
this.server.on("upgrade", (request, socket, head) => {
|
||||
console.log("socket requests upgrade", request.url);
|
||||
// @ts-ignore
|
||||
this.ws.handleUpgrade(request, socket, head, (socket) => {
|
||||
this.ws.emit("connection", socket, request);
|
||||
});
|
||||
|
||||
@ -58,13 +58,14 @@ export async function setupListener(this: WebSocket) {
|
||||
this.permissions[guild] = x;
|
||||
this.listeners;
|
||||
this.events[guild] = await listenEvent(guild, consumer, opts);
|
||||
for (const channel of guild_channels) {
|
||||
|
||||
for (const channel of guild_channels.filter((c) => c.guild_id === guild)) {
|
||||
if (x.overwriteChannel(channel.permission_overwrites).has("VIEW_CHANNEL")) {
|
||||
this.events[channel.id] = await listenEvent(channel.id, consumer, opts);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((e) => {});
|
||||
.catch((e) => console.log("couldn't get permission for guild " + guild, e));
|
||||
}
|
||||
|
||||
this.once("close", () => {
|
||||
@ -74,14 +75,14 @@ export async function setupListener(this: WebSocket) {
|
||||
}
|
||||
|
||||
// TODO: only subscribe for events that are in the connection intents
|
||||
function consume(this: WebSocket, opts: EventOpts) {
|
||||
async function consume(this: WebSocket, opts: EventOpts) {
|
||||
const { data, event } = opts;
|
||||
const id = data.id as string;
|
||||
const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm
|
||||
|
||||
const consumer = consume.bind(this);
|
||||
const listenOpts = opts as ListenEventOpts;
|
||||
console.log("event", event);
|
||||
// console.log("event", event);
|
||||
|
||||
// subscription managment
|
||||
switch (event) {
|
||||
@ -94,14 +95,14 @@ function consume(this: WebSocket, opts: EventOpts) {
|
||||
if (!permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) return;
|
||||
// TODO: check if user has permission to channel
|
||||
case "GUILD_CREATE":
|
||||
listenEvent(id, consumer, listenOpts);
|
||||
this.events[id] = await listenEvent(id, consumer, listenOpts);
|
||||
break;
|
||||
case "CHANNEL_UPDATE":
|
||||
const exists = this.events[id];
|
||||
// @ts-ignore
|
||||
if (permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) {
|
||||
if (exists) break;
|
||||
listenEvent(id, consumer, listenOpts);
|
||||
this.events[id] = await listenEvent(id, consumer, listenOpts);
|
||||
} else {
|
||||
if (!exists) return; // return -> do not send channel update events for hidden channels
|
||||
opts.cancel(id);
|
||||
|
||||
@ -43,11 +43,11 @@ export interface KafkaBroker {
|
||||
|
||||
export interface DefaultOptions {
|
||||
gateway: {
|
||||
endpointClientKeepDefault?: boolean;
|
||||
endpointClient: string | null;
|
||||
endpoint: string | null;
|
||||
};
|
||||
cdn: {
|
||||
endpointClientKeepDefault?: boolean;
|
||||
endpointClient: string | null;
|
||||
endpoint: string | null;
|
||||
};
|
||||
general: {
|
||||
@ -150,11 +150,11 @@ export interface DefaultOptions {
|
||||
|
||||
export const DefaultOptions: DefaultOptions = {
|
||||
gateway: {
|
||||
endpointClientKeepDefault: false,
|
||||
endpointClient: null,
|
||||
endpoint: null,
|
||||
},
|
||||
cdn: {
|
||||
endpointClientKeepDefault: false,
|
||||
endpointClient: null,
|
||||
endpoint: null,
|
||||
},
|
||||
general: {
|
||||
|
||||
@ -16,6 +16,7 @@ export async function emitEvent(payload: Omit<Event, "created_at">) {
|
||||
const successful = RabbitMQ.channel?.publish(id, "", Buffer.from(`${data}`), { type: payload.event });
|
||||
if (!successful) throw new Error("failed to send event");
|
||||
} else {
|
||||
console.log("emit event", id);
|
||||
events.emit(id, payload);
|
||||
}
|
||||
}
|
||||
@ -44,7 +45,11 @@ export async function listenEvent(event: string, callback: (event: EventOpts) =>
|
||||
// @ts-ignore
|
||||
return rabbitListen(opts?.channel || RabbitMQ.channel, event, callback, { acknowledge: opts?.acknowledge });
|
||||
} else {
|
||||
const cancel = () => events.removeListener(event, callback);
|
||||
const cancel = () => {
|
||||
console.log("cancel event", event);
|
||||
events.removeListener(event, callback);
|
||||
};
|
||||
console.log("listen event", event);
|
||||
events.addListener(event, (opts) => callback({ ...opts, cancel }));
|
||||
|
||||
return cancel;
|
||||
|
||||
Reference in New Issue
Block a user