diff --git a/src/tl/tl.service.ts b/src/tl/tl.service.ts index 728d19d9c77a84fb15b0bc30c67899a82ee496f5..42a71a3cf7b06a01a2b5af4289fb8c6a35725779 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 0000000000000000000000000000000000000000..3bc2f0d06c19dc94c0ddc3d8ab132113bfe43039 --- /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 0000000000000000000000000000000000000000..148d7748755b3193c5f97233da449b978f282550 --- /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 + } +}