Nigel/block user (#60)
* WIP block users * Add test to check if the person for user X is blocked or not * Added function isBlocked return true if user x is blocked by user y * Added block ans un block messages * Route / broadcast added ny Maix * notification block and un block with icon now works, started clean up * cleaning up the code * cleaning up the code - WIP * cleaning up the code - WIP * clean up code - WIP * clean up code - WIP * WIP block users * Add test to check if the person for user X is blocked or not * Added function isBlocked return true if user x is blocked by user y * Added block ans un block messages * REBASE -trying * REBASE trying * REBASE problems * REBASE problems * REBASE problems * MERGE problems * REBASE problem * REBASE problem * clean up code - WIP * MERGED master into nigel/blockUser * linter OK * TTT problem with package * Deletes tic tac and icons
This commit is contained in:
parent
64a820c0f0
commit
85eca5d301
60 changed files with 2613 additions and 1891 deletions
|
|
@ -1,2 +0,0 @@
|
|||
/dist
|
||||
/node_modules
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Directory layout
|
||||
```plaintext
|
||||
./src/tic-tac-toe
|
||||
├── entrypoint.sh
|
||||
├── package.json
|
||||
├── README.md
|
||||
├── src
|
||||
│ ├── app.ts # The microservice app file, where the major part of the backend code lives.
|
||||
│ └── run.ts # Equivalent of server.ts, it is the entrypoint for our service.
|
||||
├── tsconfig.json
|
||||
└── vite.config.js
|
||||
```
|
||||
|
||||
# Anatomy of a microservice
|
||||
|
||||
# Backend
|
||||
|
||||
# Frontend
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
# run the CMD [ ... ] from the dockerfile
|
||||
exec "$@"
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"name": "tic-tac-toe",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "npm run build && node dist/run.js",
|
||||
"build": "vite build",
|
||||
"build:prod": "vite build --outDir=/dist --minify=true --sourcemap=false",
|
||||
"REMOVEME-build:openapi": "VITE_ENTRYPOINT=src/openapi.ts vite build && node dist/openapi.cjs >openapi.json",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"packageManager": "pnpm@10.24.0"
|
||||
}
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
// import fastify, { FastifyInstance, FastifyPluginAsync } from 'fastify';
|
||||
// // TODO: Import Fastify formbody
|
||||
// // TODO: Import Fastify multipart
|
||||
// // TODO: Import shared database
|
||||
// // TODO: Import shared auth
|
||||
// // TODO: Import shared swagger
|
||||
// // TODO: Import shared utils
|
||||
// // TODO: Import socketio
|
||||
|
||||
// // @brief ???
|
||||
// declare const __SERVICE_NAME: string;
|
||||
|
||||
// // TODO: Import the plugins defined for this microservice
|
||||
// // TODO: Import the routes defined for this microservice
|
||||
|
||||
// // @brief The microservice app (as a plugin for Fastify), kinda like a main function I guess ???
|
||||
// // @param fastify
|
||||
// // @param opts
|
||||
// export const app: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
|
||||
// // Register all the fastify plugins that this app will use
|
||||
|
||||
// // Once it is done:
|
||||
// fastify.ready((err) => {
|
||||
// if (err) {
|
||||
// throw err;
|
||||
// }
|
||||
// // TODO: Supposedly, something should be there I guess
|
||||
// });
|
||||
// };
|
||||
// // Export it as the default for this file.
|
||||
// export default app;
|
||||
|
||||
// // TODO: Understand what is this for in /src/chat/src/app.ts
|
||||
// // declare module 'fastify' {
|
||||
// // interface FastifyInstance {
|
||||
// // io: Server<{
|
||||
// // hello: (message: string) => string;
|
||||
// // MsgObjectServer: (data: { message: ClientMessage }) => void;
|
||||
// // message: (msg: string) => void;
|
||||
// // testend: (sock_id_client: string) => void;
|
||||
// // }>;
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // TODO: Same for this, also in /src/chat/src/app.ts
|
||||
// // async function onReady(fastify: FastifyInstance) {
|
||||
// // function connectedUser(io?: Server, target?: string): number {
|
||||
// // let count = 0;
|
||||
// // const seen = new Set<string>();
|
||||
// // // <- only log/count unique usernames
|
||||
|
||||
// // for (const [socketId, username] of clientChat) {
|
||||
// // // Basic sanity checks
|
||||
// // if (typeof socketId !== 'string' || socketId.length === 0) {
|
||||
// // clientChat.delete(socketId);
|
||||
// // continue;
|
||||
// // }
|
||||
// // if (typeof username !== 'string' || username.length === 0) {
|
||||
// // clientChat.delete(socketId);
|
||||
// // continue;
|
||||
// // }
|
||||
|
||||
// // // If we have the io instance, attempt to validate the socket is still connected
|
||||
// // if (io && typeof io.sockets?.sockets?.get === 'function') {
|
||||
// // const s = io.sockets.sockets.get(socketId) as
|
||||
// // | Socket
|
||||
// // | undefined;
|
||||
// // // If socket not found or disconnected, remove from map and skip
|
||||
// // if (!s || s.disconnected) {
|
||||
// // clientChat.delete(socketId);
|
||||
// // continue;
|
||||
// // }
|
||||
|
||||
// // // Skip duplicates (DO NOT delete them — just don't count)
|
||||
// // if (seen.has(username)) {
|
||||
// // continue;
|
||||
// // }
|
||||
// // // socket exists and is connected
|
||||
// // seen.add(username);
|
||||
// // count++;
|
||||
// // // console.log(color.green,"count: ", count);
|
||||
// // console.log(color.yellow, 'Client:', color.reset, username);
|
||||
|
||||
// // const targetSocketId = target;
|
||||
// // io.to(targetSocketId!).emit('listObj', username);
|
||||
|
||||
// // console.log(
|
||||
// // color.yellow,
|
||||
// // 'Chat Socket ID:',
|
||||
// // color.reset,
|
||||
// // socketId,
|
||||
// // );
|
||||
// // continue;
|
||||
// // }
|
||||
|
||||
// // // If no io provided, assume entries in the map are valid and count them.
|
||||
// // count++;
|
||||
// // console.log(
|
||||
// // color.red,
|
||||
// // 'Client (unverified):',
|
||||
// // color.reset,
|
||||
// // username,
|
||||
// // );
|
||||
// // console.log(
|
||||
// // color.red,
|
||||
// // 'Chat Socket ID (unverified):',
|
||||
// // color.reset,
|
||||
// // socketId,
|
||||
// // );
|
||||
// // }
|
||||
|
||||
// // return count;
|
||||
// // }
|
||||
|
||||
// // function broadcast(data: ClientMessage, sender?: string) {
|
||||
// // fastify.io.fetchSockets().then((sockets) => {
|
||||
// // for (const s of sockets) {
|
||||
// // if (s.id !== sender) {
|
||||
// // // Send REAL JSON object
|
||||
// // const clientName = clientChat.get(s.id) || null;
|
||||
// // if (clientName !== null) {
|
||||
// // s.emit('MsgObjectServer', { message: data });
|
||||
// // }
|
||||
// // console.log(' Target window socket ID:', s.id);
|
||||
// // console.log(' Target window ID:', [...s.rooms]);
|
||||
// // console.log(' Sender window ID:', sender ? sender : 'none');
|
||||
// // }
|
||||
// // }
|
||||
// // });
|
||||
// // }
|
||||
|
||||
// // fastify.io.on('connection', (socket: Socket) => {
|
||||
// // socket.on('message', (message: string) => {
|
||||
// // console.info(
|
||||
// // color.blue,
|
||||
// // 'Socket connected!',
|
||||
// // color.reset,
|
||||
// // socket.id,
|
||||
// // );
|
||||
// // console.log(
|
||||
// // color.blue,
|
||||
// // 'Received message from client',
|
||||
// // color.reset,
|
||||
// // message,
|
||||
// // );
|
||||
|
||||
// // const obj: ClientMessage = JSON.parse(message) as ClientMessage;
|
||||
// // clientChat.set(socket.id, obj.user);
|
||||
// // console.log(
|
||||
// // color.green,
|
||||
// // 'Message from client',
|
||||
// // color.reset,
|
||||
// // `Sender: login name: "${obj.user}" - windowID "${obj.SenderWindowID}" - text message: "${obj.text}"`,
|
||||
// // );
|
||||
// // // Send object directly — DO NOT wrap it in a string
|
||||
// // broadcast(obj, obj.SenderWindowID);
|
||||
// // console.log(
|
||||
// // color.red,
|
||||
// // 'connected in the Chat :',
|
||||
// // connectedUser(fastify.io),
|
||||
// // color.reset,
|
||||
// // );
|
||||
// // });
|
||||
|
||||
// // socket.on('testend', (sock_id_cl: string) => {
|
||||
// // console.log('testend received from client socket id:', sock_id_cl);
|
||||
// // });
|
||||
|
||||
// // socket.on('list', () => {
|
||||
// // console.log(color.red, 'list activated', color.reset, socket.id);
|
||||
// // connectedUser(fastify.io, socket.id);
|
||||
// // });
|
||||
|
||||
// // socket.on('disconnecting', (reason) => {
|
||||
// // const clientName = clientChat.get(socket.id) || null;
|
||||
// // console.log(
|
||||
// // color.green,
|
||||
// // `Client disconnecting: ${clientName} (${socket.id}) reason:`,
|
||||
// // reason,
|
||||
// // );
|
||||
// // if (reason === 'transport error') return;
|
||||
|
||||
// // if (clientName !== null) {
|
||||
// // const obj = {
|
||||
// // type: 'chat',
|
||||
// // user: clientName,
|
||||
// // token: '',
|
||||
// // text: 'LEFT the chat',
|
||||
// // timestamp: Date.now(),
|
||||
// // SenderWindowID: socket.id,
|
||||
// // };
|
||||
|
||||
// // broadcast(obj, obj.SenderWindowID);
|
||||
// // // clientChat.delete(obj.user);
|
||||
// // }
|
||||
// // });
|
||||
// // });
|
||||
// // }
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// @file run.ts
|
||||
// @brief The entrypoint to the service.
|
||||
|
||||
// Entry point of the microservice, ran by the Dockerfile.
|
||||
|
||||
import fastify, { FastifyInstance } from 'fastify';
|
||||
import app from './app';
|
||||
// TODO: Import the microservice app
|
||||
|
||||
// @brief Entrypoint for the microservice's backend.
|
||||
const start = async () => {
|
||||
// TODO: Thingies to send to log service (if I understood that correctly from /src/chat/src/run.ts)
|
||||
|
||||
// TODO: Add the logging thingy to the call to fastify()
|
||||
const fastInst: FastifyInstance = fastify();
|
||||
try {
|
||||
process.on('SIGTERM', () => {
|
||||
fastInst.log.info('Requested to shutdown');
|
||||
process.exit(143);
|
||||
});
|
||||
// TODO: Uncomment when app.ts will be import-able.
|
||||
await fastInst.register(app);
|
||||
await fastInst.listen({ port: 80, host: '0.0.0.0' });
|
||||
}
|
||||
catch (err) {
|
||||
fastInst.log.error(err);
|
||||
process.exit(1);
|
||||
};
|
||||
};
|
||||
|
||||
start();
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import tsconfigPaths from 'vite-tsconfig-paths';
|
||||
import nodeExternals from 'rollup-plugin-node-externals';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
|
||||
function collectDeps(...pkgJsonPaths) {
|
||||
const allDeps = new Set();
|
||||
for (const pkgPath of pkgJsonPaths) {
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
||||
for (const dep of Object.keys(pkg.dependencies || {})) {
|
||||
allDeps.add(dep);
|
||||
}
|
||||
for (const peer of Object.keys(pkg.peerDependencies || {})) {
|
||||
allDeps.add(peer);
|
||||
}
|
||||
}
|
||||
return Array.from(allDeps);
|
||||
};
|
||||
|
||||
const externals = collectDeps(
|
||||
'./package.json',
|
||||
'../@shared/package.json',
|
||||
);
|
||||
|
||||
export default defineConfig({
|
||||
root: __dirname,
|
||||
define: {
|
||||
__SERVICE_NAME: '"tic-tac-toe"',
|
||||
},
|
||||
// service root
|
||||
plugins: [tsconfigPaths(), nodeExternals()],
|
||||
build: {
|
||||
ssr: true,
|
||||
outDir: 'dist',
|
||||
emptyOutDir: true,
|
||||
lib: {
|
||||
entry: path.resolve(__dirname, process.env.VITE_ENTRYPOINT ?? 'src/run.ts'),
|
||||
// adjust main entry
|
||||
formats: ['cjs'],
|
||||
// CommonJS for Node.js
|
||||
fileName: () => 'index.js',
|
||||
},
|
||||
rollupOptions: {
|
||||
external: externals,
|
||||
},
|
||||
target: 'node22',
|
||||
// or whatever Node version you use
|
||||
sourcemap: true,
|
||||
minify: false,
|
||||
// for easier debugging
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue