mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-29 09:23:04 +00:00
fix(backend): request.body may be undefined (#9356)
This commit is contained in:
parent
72e7909911
commit
c3cb218975
1 changed files with 5 additions and 5 deletions
|
@ -54,21 +54,21 @@ export class ApiCallService implements OnApplicationShutdown {
|
||||||
@bindThis
|
@bindThis
|
||||||
public handleRequest(
|
public handleRequest(
|
||||||
endpoint: IEndpoint & { exec: any },
|
endpoint: IEndpoint & { exec: any },
|
||||||
request: FastifyRequest<{ Body: Record<string, unknown>, Querystring: Record<string, unknown> }>,
|
request: FastifyRequest<{ Body: Record<string, unknown> | undefined, Querystring: Record<string, unknown> }>,
|
||||||
reply: FastifyReply,
|
reply: FastifyReply,
|
||||||
) {
|
) {
|
||||||
const body = request.method === 'GET'
|
const body = request.method === 'GET'
|
||||||
? request.query
|
? request.query
|
||||||
: request.body;
|
: request.body;
|
||||||
|
|
||||||
const token = body['i'];
|
const token = body?.['i'];
|
||||||
if (token != null && typeof token !== 'string') {
|
if (token != null && typeof token !== 'string') {
|
||||||
reply.code(400);
|
reply.code(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.authenticateService.authenticate(token).then(([user, app]) => {
|
this.authenticateService.authenticate(token).then(([user, app]) => {
|
||||||
this.call(endpoint, user, app, body, null, request).then((res) => {
|
this.call(endpoint, user, app, body, null, request).then((res) => {
|
||||||
if (request.method === 'GET' && endpoint.meta.cacheSec && !body['i'] && !user) {
|
if (request.method === 'GET' && endpoint.meta.cacheSec && !body?.['i'] && !user) {
|
||||||
reply.header('Cache-Control', `public, max-age=${endpoint.meta.cacheSec}`);
|
reply.header('Cache-Control', `public, max-age=${endpoint.meta.cacheSec}`);
|
||||||
}
|
}
|
||||||
this.send(reply, res);
|
this.send(reply, res);
|
||||||
|
@ -199,7 +199,7 @@ export class ApiCallService implements OnApplicationShutdown {
|
||||||
name: string;
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
} | null,
|
} | null,
|
||||||
request: FastifyRequest<{ Body: Record<string, unknown>, Querystring: Record<string, unknown> }>,
|
request: FastifyRequest<{ Body: Record<string, unknown> | undefined, Querystring: Record<string, unknown> }>,
|
||||||
) {
|
) {
|
||||||
const isSecure = user != null && token == null;
|
const isSecure = user != null && token == null;
|
||||||
const isModerator = user != null && (user.isModerator || user.isAdmin);
|
const isModerator = user != null && (user.isModerator || user.isAdmin);
|
||||||
|
|
Loading…
Reference in a new issue