diff --git a/src/ws/model/interface/index.ts b/src/ws/model/interface/index.ts index 38c104c..317814c 100644 --- a/src/ws/model/interface/index.ts +++ b/src/ws/model/interface/index.ts @@ -11,6 +11,10 @@ export interface options { * @default true */ authentication?: boolean; + /** + * @default 'null' + */ + token?: string session?: string | string[] | undefined; } diff --git a/src/ws/routers/functions/start-session.ts b/src/ws/routers/functions/start-session.ts index fd9b2e5..e0d8eb7 100644 --- a/src/ws/routers/functions/start-session.ts +++ b/src/ws/routers/functions/start-session.ts @@ -4,11 +4,13 @@ import { sessionClient } from '../../help/sessions'; import { spawn } from 'child_process'; import { InicializeRouters } from './inicialize-routers'; import { Request, Response } from 'express'; +import crypto from 'crypto'; export async function startSession(req: Request, res: Response, option: options) { const body = req.body; const reHttp = /^https?:/; const $_HEADERS_USER = req.headers.user; + const $_HEADERS_PASS = req.headers.user_pass; if (option.authentication) { const user = await Users.CheckUserLogin(req); @@ -24,8 +26,14 @@ export async function startSession(req: Request, res: Response, option: options) const session = await sessionClient.newSession($_HEADERS_USER); if (session) { + const MergeToken = typeof $_HEADERS_USER === 'string' && typeof $_HEADERS_PASS === 'string'? $_HEADERS_USER + $_HEADERS_PASS: ''; + const token = crypto + .createHash('md5') + .update(MergeToken) + .digest('hex'); option.session = $_HEADERS_USER; option.url = body.url; + option.token = token; const spawnArgs = [ __dirname + '../../../services/hydra.js', diff --git a/src/ws/services/hydra.ts b/src/ws/services/hydra.ts index 25d9306..74e4a86 100644 --- a/src/ws/services/hydra.ts +++ b/src/ws/services/hydra.ts @@ -13,6 +13,7 @@ function sendParent(data: any) { async function Webhook(options: any, info: any) { if (!!options.url && options.url.length) { return new Promise(async (resolve, reject) => { + Object.assign(info, {token: options.token}) await axios .post(options.url, info) .then(function (response) {