From 1f330b81c4705d02f08dc283906548fab4b2442b Mon Sep 17 00:00:00 2001 From: Abhishek Y <abhisheky@Abhisheks-MacBook-Pro.local> Date: Thu, 4 Jan 2024 09:22:25 +0530 Subject: [PATCH] Add support for xInput --- src/tl/tl.service.ts | 2 +- src/types/common.type.ts | 3 +++ src/x-input/x-input.service.ts | 42 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/types/common.type.ts create mode 100644 src/x-input/x-input.service.ts diff --git a/src/tl/tl.service.ts b/src/tl/tl.service.ts index 728d19d..42a71a3 100644 --- a/src/tl/tl.service.ts +++ b/src/tl/tl.service.ts @@ -4,7 +4,7 @@ import path from 'path'; import appRootPath from "app-root-path"; import fs from 'fs'; import { ObjectUtil } from "../util/object.util"; -import * as tlHelpers from './tl.helper' +import * as tlHelpers from './tl.helper'; import { AppLogger } from "../app/app.logger"; @injectable() diff --git a/src/types/common.type.ts b/src/types/common.type.ts new file mode 100644 index 0000000..3bc2f0d --- /dev/null +++ b/src/types/common.type.ts @@ -0,0 +1,3 @@ +export interface KeyValue { + [key: string]: any +} \ No newline at end of file diff --git a/src/x-input/x-input.service.ts b/src/x-input/x-input.service.ts new file mode 100644 index 0000000..148d774 --- /dev/null +++ b/src/x-input/x-input.service.ts @@ -0,0 +1,42 @@ +import { inject, injectable } from "inversify"; +import { AppLogger } from "../app/app.logger"; +import { KeyValue } from '../types/common.type'; +import { PSClientService } from "../psclient/psclient.service"; +import HttpClient from "../httpclient/http.service"; + +const XINPUTKEY = 'xinput'; + +@injectable() +export class XInputService { + constructor( + @inject(AppLogger) private logger: AppLogger, + @inject(PSClientService) private psClientService: PSClientService, + @inject(HttpClient) private httpClient: HttpClient + ) { } + + async getXInputForm(data: KeyValue) { + // wrap this into try catch block + const newData = { ...data }; + for (const key in data) { + if (key === XINPUTKEY && data[key].form.mime_type === 'text/html') { + const xInputRes = await this.httpClient.post<string>(data[key].form.url, { + context: { + action: data.context.action + } + }); + delete data[key].form.url; + newData[key].form.html = this.sanatizeXInputHtml(xInputRes); + } else if (typeof data[key] === 'object' && data[key] !== null) { + this.getXInputForm(data[key]); + } + } + return newData; + } + + async sanatizeXInputHtml(html: string) { + // Get action value from form tag, value is url to which form will be submitted + // Encrypt action url + // Add hidden field in form with name as bpp_url - this of better name + // Remove action and method from form tag + } +} -- GitLab