feat(user): added description and global guest user mute

This commit is contained in:
Maieul BOYER 2025-12-18 14:46:02 +01:00 committed by Maix0
parent bcba86ed8a
commit 556138d624
24 changed files with 1856 additions and 1460 deletions

View file

@ -8,6 +8,366 @@
"schemas": {}
},
"paths": {
"/api/user/allowGuestMessage": {
"post": {
"operationId": "allowGuestMessage",
"responses": {
"200": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"success"
]
},
"msg": {
"enum": [
"guestMessage.success"
]
}
}
}
}
}
},
"401": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"anyOf": [
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
},
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
}
]
}
}
}
},
"403": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"failure"
]
},
"msg": {
"enum": [
"guestMessage.failure.notLoggedIn"
]
}
}
}
}
}
}
}
}
},
"/api/user/denyGuestMessage": {
"post": {
"operationId": "denyGuestMessage",
"responses": {
"200": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"success"
]
},
"msg": {
"enum": [
"guestMessage.success"
]
}
}
}
}
}
},
"401": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"anyOf": [
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
},
{
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
}
]
}
}
}
},
"403": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"failure"
]
},
"msg": {
"enum": [
"guestMessage.failure.notLoggedIn"
]
}
}
}
}
}
}
}
}
},
"/api/user/changeDesc": {
"post": {
"operationId": "changeDesc",
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"desc"
],
"properties": {
"desc": {
"type": "string"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"success"
]
},
"msg": {
"enum": [
"changedesc.success"
]
}
}
}
}
}
},
"400": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"failure"
]
},
"msg": {
"enum": [
"changedesc.failure.descTooLong"
]
}
}
}
}
}
},
"401": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"notLoggedIn"
]
},
"msg": {
"enum": [
"auth.noCookie",
"auth.invalidKind",
"auth.noUser",
"auth.invalid"
]
}
}
}
}
}
},
"403": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"kind",
"msg"
],
"properties": {
"kind": {
"enum": [
"failure"
]
},
"msg": {
"enum": [
"changedesc.failure.notLoggedIn"
]
}
}
}
}
}
}
}
}
},
"/api/user/changeDisplayName": {
"put": {
"operationId": "changeDisplayName",

View file

@ -26,7 +26,7 @@
"fastify": "^5.6.2",
"fastify-cli": "^7.4.1",
"fastify-plugin": "^5.1.0",
"typebox": "^1.0.63"
"typebox": "^1.0.64"
},
"devDependencies": {
"@types/node": "^22.19.3",

View file

@ -0,0 +1,47 @@
import { FastifyPluginAsync } from 'fastify';
import { isNullish, MakeStaticResponse, typeResponse } from '@shared/utils';
export const GuestMessageRes = {
'200': typeResponse('success', 'guestMessage.success'),
'403': typeResponse('failure', 'guestMessage.failure.notLoggedIn'),
};
export type GuestMessageRes = MakeStaticResponse<typeof GuestMessageRes>;
const allowRoute: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
void _opts;
fastify.post(
'/api/user/allowGuestMessage',
{ schema: { response: GuestMessageRes, operationId: 'allowGuestMessage' }, config: { requireAuth: true } },
async function(req, res) {
if (isNullish(req.authUser)) { return res.makeResponse(403, 'failure', 'guestMessage.failure.notLoggedIn'); }
this.db.allowGuestMessage(req.authUser.id);
return res.makeResponse(200, 'success', 'guestMessage.success');
},
);
};
const denyRoute: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
void _opts;
fastify.post(
'/api/user/denyGuestMessage',
{ schema: { response: GuestMessageRes, operationId: 'denyGuestMessage' }, config: { requireAuth: true } },
async function(req, res) {
if (isNullish(req.authUser)) { return res.makeResponse(403, 'failure', 'guestMessage.failure.notLoggedIn'); }
this.db.denyGuestMessage(req.authUser.id);
return res.makeResponse(200, 'success', 'guestMessage.success');
},
);
};
const route: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.register(allowRoute);
fastify.register(denyRoute);
};
export default route;

View file

@ -0,0 +1,36 @@
import { FastifyPluginAsync } from 'fastify';
import { Static, Type } from 'typebox';
import { isNullish, MakeStaticResponse, typeResponse } from '@shared/utils';
export const ChangeDescRes = {
'200': typeResponse('success', 'changedesc.success'),
'400': typeResponse('failure', 'changedesc.failure.descTooLong'),
'403': typeResponse('failure', 'changedesc.failure.notLoggedIn'),
};
export type ChangeDescRes = MakeStaticResponse<typeof ChangeDescRes>;
export const ChangeDescBody = Type.Object({ desc: Type.String() });
export type ChangeDescBody = Static<typeof ChangeDescBody>;
const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
void _opts;
fastify.post<{ Body: ChangeDescBody }>(
'/api/user/changeDesc',
{ schema: { body: ChangeDescBody, response: ChangeDescRes, operationId: 'changeDesc' }, config: { requireAuth: true } },
async function(req, res) {
if (isNullish(req.authUser)) { return res.makeResponse(403, 'failure', 'changedesc.failure.notLoggedIn'); }
if (req.body.desc.length > 75) {
return res.makeResponse(400, 'failure', 'changedesc.failure.descTooLong');
}
this.db.setUserDescription(req.authUser.id, req.body.desc);
return res.makeResponse(200, 'success', 'changedesc.success');
},
);
};
export default route;