Skip to content

Commit

Permalink
[core] noweb store
Browse files Browse the repository at this point in the history
  • Loading branch information
devlikepro committed Jun 13, 2024
1 parent 94191a2 commit df3bc97
Show file tree
Hide file tree
Showing 25 changed files with 1,666 additions and 77 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
"@nestjs/serve-static": "^2.1.3",
"@nestjs/swagger": "^7.1.11",
"@nestjs/terminus": "^10.2.3",
"@types/better-sqlite3": "^7.6.10",
"@types/lodash": "^4.14.194",
"@types/ws": "^8.5.4",
"async-lock": "^1.4.1",
"better-sqlite3": "^11.0.0",
"check-disk-space": "^3.4.0",
"class-validator": "^0.12.2",
"del": "^6.0.0",
"express-basic-auth": "^1.2.1",
"file-type": "16.5.4",
"https-proxy-agent": "^7.0.0",
"knex": "^3.1.0",
"libphonenumber-js": "^1.10.36",
"link-preview-js": "^3.0.4",
"lodash": "^4.17.21",
Expand All @@ -57,6 +60,7 @@
"requestretry": "^4.1.1",
"rimraf": "^3.0.2",
"rxjs": "^7.1.0",
"sharp": "^0.33.4",
"swagger-ui-express": "^4.1.4",
"venom-bot": "5.0.1",
"whatsapp-web.js": "https://github.com/devlikeapro/whatsapp-web.js#main-fork-update"
Expand Down
34 changes: 34 additions & 0 deletions src/api/BufferJsonReplacerInterceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BufferJSON } from '@adiwajshing/baileys/lib/Utils';
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
StreamableFile,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable()
export class BufferJsonReplacerInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
map((data) => {
if (typeof data !== 'object' || data === null) {
return data;
}
// Buffer
if (Buffer.isBuffer(data) || data?.data || data?.url) {
return data;
}

// StreamableFile
if (data instanceof StreamableFile) {
return data;
}

return JSON.parse(JSON.stringify(data, BufferJSON.replacer));
}),
);
}
}
6 changes: 6 additions & 0 deletions src/core/app.module.core.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ConsoleLogger, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { PassportModule } from '@nestjs/passport';
import { ServeStaticModule } from '@nestjs/serve-static';
import { TerminusModule } from '@nestjs/terminus';
import { BufferJsonReplacerInterceptor } from '@waha/api/BufferJsonReplacerInterceptor';
import { join } from 'path';

import { AuthController } from '../api/auth.controller';
Expand Down Expand Up @@ -82,6 +84,10 @@ const PROVIDERS = [
provide: WAHAHealthCheckService,
useClass: WAHAHealthCheckServiceCore,
},
{
provide: APP_INTERCEPTOR,
useClass: BufferJsonReplacerInterceptor,
},
DashboardConfigServiceCore,
SwaggerConfigServiceCore,
WhatsappConfigService,
Expand Down
Loading

0 comments on commit df3bc97

Please sign in to comment.