From c9f7814f5d67afed6d2ab097151a67d4cc0a994a Mon Sep 17 00:00:00 2001 From: devlikepro Date: Sun, 22 Dec 2024 16:48:18 +0700 Subject: [PATCH] [core] Refresh profile picture --- src/api/contacts.controller.ts | 9 +++++++-- src/structures/base.dto.ts | 3 ++- src/structures/contacts.dto.ts | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/api/contacts.controller.ts b/src/api/contacts.controller.ts index 524ef32f..0796f1df 100644 --- a/src/api/contacts.controller.ts +++ b/src/api/contacts.controller.ts @@ -16,6 +16,7 @@ import { WANumberExistResult, } from '../structures/chatting.dto'; import { + ContactProfilePictureQuery, ContactQuery, ContactRequest, ContactsPaginationParams, @@ -75,9 +76,13 @@ export class ContactsController { description: 'If privacy settings do not allow to get the picture, the method will return null.', }) - async getProfilePicture(@Query() query: ContactQuery) { + @UsePipes(new ValidationPipe({ transform: true, whitelist: true })) + async getProfilePicture(@Query() query: ContactProfilePictureQuery) { const whatsapp = await this.manager.getWorkingSession(query.session); - const url = await whatsapp.getContactProfilePicture(query.contactId, false); + const url = await whatsapp.getContactProfilePicture( + query.contactId, + query.refresh, + ); return { profilePictureURL: url }; } diff --git a/src/structures/base.dto.ts b/src/structures/base.dto.ts index 4f3df1ba..17e9df33 100644 --- a/src/structures/base.dto.ts +++ b/src/structures/base.dto.ts @@ -1,4 +1,4 @@ -import { IsNotEmpty } from 'class-validator'; +import { IsNotEmpty, IsString } from 'class-validator'; export const WHATSAPP_DEFAULT_SESSION_NAME = 'default'; @@ -7,6 +7,7 @@ export const WHATSAPP_DEFAULT_SESSION_NAME = 'default'; */ export class SessionQuery { @IsNotEmpty() + @IsString() session: string = WHATSAPP_DEFAULT_SESSION_NAME; } diff --git a/src/structures/contacts.dto.ts b/src/structures/contacts.dto.ts index 73af9750..0909e292 100644 --- a/src/structures/contacts.dto.ts +++ b/src/structures/contacts.dto.ts @@ -1,7 +1,9 @@ import { ApiProperty } from '@nestjs/swagger'; +import { BooleanString } from '@waha/nestjs/validation/BooleanString'; import { PaginationParams } from '@waha/structures/pagination.dto'; import { ChatIdProperty } from '@waha/structures/properties.dto'; -import { IsEnum, IsOptional, IsString } from 'class-validator'; +import { Transform } from 'class-transformer'; +import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator'; import { SessionBaseRequest, SessionQuery } from './base.dto'; @@ -15,6 +17,19 @@ export class ContactQuery extends SessionQuery { contactId: string; } +export class ContactProfilePictureQuery extends ContactQuery { + @Transform(BooleanString) + @IsBoolean() + @IsOptional() + @ApiProperty({ + example: false, + required: false, + description: + 'Refresh the picture from the server (24h cache by default). Do not refresh if not needed, you can get rate limit error', + }) + refresh?: boolean = false; +} + enum ContactSortField { ID = 'id', NAME = 'name',