Skip to content

Commit 5499b7b

Browse files
committed
fix: resolve catalog pagination limits and add GHCR CI/CD
- Increase default catalog limit from 10 to 50 products - Increase pagination loops from 4 to 20 for larger catalogs - Remove arbitrary 20-item cap on getCollections (now default 100) - Add cursor parameter to validation schemas for manual pagination - Add cursor support to getCollectionsDto - Add GitHub Actions workflow for GHCR publishing Fixes #2589
1 parent fa09d37 commit 5499b7b

4 files changed

Lines changed: 78 additions & 4 deletions

File tree

.github/workflows/publish_ghcr.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build and Publish to GHCR
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'release/**'
8+
tags:
9+
- 'v*.*.*'
10+
pull_request:
11+
branches:
12+
- main
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
jobs:
19+
build:
20+
name: Build and Publish
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v5
28+
with:
29+
submodules: recursive
30+
31+
- name: Docker meta
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
36+
tags: |
37+
type=ref,event=branch
38+
type=ref,event=pr
39+
type=semver,pattern={{version}}
40+
type=semver,pattern={{major}}.{{minor}}
41+
type=sha,prefix=
42+
43+
- name: Set up QEMU
44+
uses: docker/setup-qemu-action@v3
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Login to GitHub Container Registry
50+
if: github.event_name != 'pull_request'
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ${{ env.REGISTRY }}
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Build and push
58+
id: docker_build
59+
uses: docker/build-push-action@v6
60+
with:
61+
context: .
62+
platforms: linux/amd64,linux/arm64
63+
push: ${{ github.event_name != 'pull_request' }}
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
69+
- name: Image digest
70+
if: github.event_name != 'pull_request'
71+
run: echo ${{ steps.docker_build.outputs.digest }}

src/api/dto/business.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export class getCatalogDto {
1111
export class getCollectionsDto {
1212
number?: string;
1313
limit?: number;
14+
cursor?: string;
1415
}

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4901,8 +4901,8 @@ export class BaileysStartupService extends ChannelStartupService {
49014901
//Business Controller
49024902
public async fetchCatalog(instanceName: string, data: getCollectionsDto) {
49034903
const jid = data.number ? createJid(data.number) : this.client?.user?.id;
4904-
const limit = data.limit || 10;
4905-
const cursor = null;
4904+
const limit = data.limit || 50;
4905+
const cursor = data.cursor || null;
49064906

49074907
const onWhatsapp = (await this.whatsappNumber({ numbers: [jid] }))?.shift();
49084908

@@ -4924,7 +4924,7 @@ export class BaileysStartupService extends ChannelStartupService {
49244924

49254925
let productsCatalog = catalog.products || [];
49264926
let countLoops = 0;
4927-
while (fetcherHasMore && countLoops < 4) {
4927+
while (fetcherHasMore && countLoops < 20) {
49284928
catalog = await this.getCatalog({ jid: info?.jid, limit, cursor: nextPageCursor });
49294929
nextPageCursor = catalog.nextPageCursor;
49304930
nextPageCursorJson = nextPageCursor ? JSON.parse(atob(nextPageCursor)) : null;
@@ -4971,7 +4971,7 @@ export class BaileysStartupService extends ChannelStartupService {
49714971

49724972
public async fetchCollections(instanceName: string, data: getCollectionsDto) {
49734973
const jid = data.number ? createJid(data.number) : this.client?.user?.id;
4974-
const limit = data.limit <= 20 ? data.limit : 20; //(tem esse limite, não sei porque)
4974+
const limit = data.limit || 100;
49754975

49764976
const onWhatsapp = (await this.whatsappNumber({ numbers: [jid] }))?.shift();
49774977

src/validate/business.schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const catalogSchema: JSONSchema7 = {
55
properties: {
66
number: { type: 'string' },
77
limit: { type: 'number' },
8+
cursor: { type: 'string' },
89
},
910
};
1011

@@ -13,5 +14,6 @@ export const collectionsSchema: JSONSchema7 = {
1314
properties: {
1415
number: { type: 'string' },
1516
limit: { type: 'number' },
17+
cursor: { type: 'string' },
1618
},
1719
};

0 commit comments

Comments
 (0)