From aefdcdd76e0d85f3e64555a22744eb7ffb1b5ddc Mon Sep 17 00:00:00 2001 From: Lawrence Ephrim Date: Thu, 2 May 2024 06:26:35 +0000 Subject: [PATCH] fix(gateway: wigal): replace `\n` with `^` when rendering response --- src/gateways/wigal.gateway.ts | 70 +++++++++++++++++------------------ src/types/index.ts | 2 +- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/gateways/wigal.gateway.ts b/src/gateways/wigal.gateway.ts index a57ae23..b610267 100644 --- a/src/gateways/wigal.gateway.ts +++ b/src/gateways/wigal.gateway.ts @@ -3,40 +3,38 @@ import { Gateway } from "./base.gateway"; import { State } from "@src/models"; export class WigalGateway extends Gateway { - get sessionId(): string { - return this.request.query?.sessionid!; - } - - async handleRequest(): Promise { - let _state = await this.state; - - _state ??= new State(); - - _state.mode = this.request.query?.mode as any; //todo: validate - _state.msisdn = this.request.query?.msisdn!; - _state.sessionId = this.request.query?.sessionid!; - _state.userData = this.request.query?.userdata!; - - // await this.session.setState(this.sessionId, _state); - this.request.state = _state; - this.request.input = this.request.query?.userdata!; - this.request.msisdn = _state.msisdn; - - return _state; - } - - async handleResponse(_req: Request, res: Response): Promise { - res.writeHead(200, { "Content-Type": "text/plain" }); - res.end(await this.wigalResponse()); - return; - } - - private async wigalResponse(): Promise { - const data = (await this.state)!; - return `${this.request.query?.network}|${data?.mode}|${data?.msisdn}|${ - data?.sessionId - }|${this.response.data}|${this.request.query?.username}|${ - this.request.query?.trafficid - }|${data?.menu?.nextMenu || ""}`; - } + get sessionId(): string { + return this.request.query?.sessionid!; + } + + async handleRequest(): Promise { + let _state = await this.state; + + _state ??= new State(); + + _state.mode = this.request.query?.mode as any; //todo: validate + _state.msisdn = this.request.query?.msisdn!; + _state.sessionId = this.request.query?.sessionid!; + _state.userData = this.request.query?.userdata!; + + // await this.session.setState(this.sessionId, _state); + this.request.state = _state; + this.request.input = this.request.query?.userdata!; + this.request.msisdn = _state.msisdn; + + return _state; + } + + async handleResponse(_req: Request, res: Response): Promise { + res.writeHead(200, { "Content-Type": "text/plain" }); + res.end(await this.wigalResponse()); + return; + } + + private async wigalResponse(): Promise { + const data = (await this.state)!; + return `${this.request.query?.network}|${data?.mode}|${data?.msisdn}|${data?.sessionId + }|${this.response.data?.replace('\n', '^') ?? ''}|${this.request.query?.username}|${this.request.query?.trafficid + }|${data?.menu?.nextMenu || ""}`; + } } diff --git a/src/types/index.ts b/src/types/index.ts index d788a81..5d7a349 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -16,7 +16,7 @@ export type FormInput = { validate: Validation; display: string | ((req: Request) => Promise | string); handler?: (req: Request) => Promise; - next_input?: string | ((req: Request) => Promise); + next_input?: string | ((req: Request) => Promise | string); end?: boolean | ((req: Request) => boolean); next_menu?: NextMenu; };