Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(media): use the saved proxy for non-uuid session ids
Yudhi Armyndharis18acb4a2f927
diff --git a/src/modules/media/media-conversion.service.spec.ts b/src/modules/media/media-conversion.service.spec.tsindex b7be676ce..1599c95b6 100644--- a/src/modules/media/media-conversion.service.spec.ts+++ b/src/modules/media/media-conversion.service.spec.ts@@ -216,14 +216,26 @@ describe('MediaConversionService', () => {expect(load).toHaveBeenCalledWith('https://example.com/note.m4a', 'socks4://stored.invalid:1080');});- // Ids are generated uuids; anything else matches no row, and asking Postgres would raise on- // the cast rather than answer.- it('does not query the row for a session id that cannot be one', async () => {+ it('uses the saved proxy for an imported safe-string session id', async () => {const load = loadSpy();- const service = makeService();+ const service = makeService(config(), { row: { proxyUrl: 'socks5://stored.invalid:1080' } });+ await service.convertToVoice('legacy-session', { url: 'https://example.com/note.m4a' });+ expect(findOne).toHaveBeenCalledWith({ where: { id: 'legacy-session' }, select: { proxyUrl: true } });+ expect(load).toHaveBeenCalledWith('https://example.com/note.m4a', 'socks5://stored.invalid:1080');+ });- await service.convertToVoice('not-a-uuid', { url: 'https://example.com/note.m4a' });+ it('keeps direct fetch behavior for an unknown safe-string id', async () => {+ const load = loadSpy();+ const service = makeService();+ await service.convertToVoice('missing-session', { url: 'https://example.com/note.m4a' });+ expect(findOne).toHaveBeenCalledTimes(1);+ expect(load).toHaveBeenCalledWith('https://example.com/note.m4a', undefined);+ });+ it('does not query a NUL-bearing session id', async () => {+ const load = loadSpy();+ const service = makeService();+ await service.convertToVoice('session\0name', { url: 'https://example.com/note.m4a' });expect(findOne).not.toHaveBeenCalled();expect(load).toHaveBeenCalledWith('https://example.com/note.m4a', undefined);});diff --git a/src/modules/media/media-conversion.service.ts b/src/modules/media/media-conversion.service.tsindex 2c7912e87..7594562f5 100644--- a/src/modules/media/media-conversion.service.ts+++ b/src/modules/media/media-conversion.service.ts@@ -1,7 +1,6 @@import { BadRequestException, Injectable, OnApplicationShutdown, ServiceUnavailableException } from '@nestjs/common';import { ConfigService } from '@nestjs/config';import { InjectRepository } from '@nestjs/typeorm';-import { isUUID } from 'class-validator';import { Repository } from 'typeorm';import { createLogger } from '../../common/services/logger.service';import { EngineRegistry } from '../../engine/engine-registry.service';@@ -159,11 +158,9 @@ export class MediaConversionService implements OnApplicationShutdown {if (this.engines.has(sessionId)) {return this.engines.proxyUrl(sessionId);}- // Ids are generated uuids, so anything else matches no row; asking Postgres would raise on the- // cast instead of answering "no session".- if (!isUUID(sessionId)) {- return undefined;- }+ // Ids are varchar, and a restored session can keep a safe non-uuid id. A NUL cannot be bound by+ // PostgreSQL, so it answers "no session" instead of raising.+ if (sessionId.includes('\0')) return undefined;const session = await this.sessionRepository.findOne({ where: { id: sessionId }, select: { proxyUrl: true } });return session?.proxyUrl ?? undefined;}