@kaikybrofc/omnizap-system 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.env.example +13 -0
  2. package/README.md +29 -85
  3. package/app/controllers/messageController.js +133 -1
  4. package/app/modules/stickerPackModule/catalogHandlers/catalogAdminHttp.js +68 -0
  5. package/app/modules/stickerPackModule/catalogHandlers/catalogAuthHttp.js +34 -0
  6. package/app/modules/stickerPackModule/catalogHandlers/catalogPublicHttp.js +179 -0
  7. package/app/modules/stickerPackModule/catalogHandlers/catalogUploadHttp.js +92 -0
  8. package/app/modules/stickerPackModule/catalogRouter.js +79 -0
  9. package/app/modules/stickerPackModule/domainEventOutboxRepository.js +243 -0
  10. package/app/modules/stickerPackModule/domainEvents.js +61 -0
  11. package/app/modules/stickerPackModule/stickerAssetClassificationRepository.js +21 -0
  12. package/app/modules/stickerPackModule/stickerAssetRepository.js +19 -0
  13. package/app/modules/stickerPackModule/stickerClassificationBackgroundRuntime.js +55 -15
  14. package/app/modules/stickerPackModule/stickerDedicatedTaskWorkerRuntime.js +238 -0
  15. package/app/modules/stickerPackModule/stickerDomainEventBus.js +71 -0
  16. package/app/modules/stickerPackModule/stickerDomainEventConsumerRuntime.js +198 -0
  17. package/app/modules/stickerPackModule/stickerObjectStorageService.js +285 -0
  18. package/app/modules/stickerPackModule/stickerPackCatalogHttp.js +1090 -659
  19. package/app/modules/stickerPackModule/stickerPackCommandHandlers.js +19 -1
  20. package/app/modules/stickerPackModule/stickerPackEngagementRepository.js +44 -0
  21. package/app/modules/stickerPackModule/stickerPackItemRepository.js +18 -0
  22. package/app/modules/stickerPackModule/stickerPackRepository.js +51 -0
  23. package/app/modules/stickerPackModule/stickerPackScoreSnapshotRepository.js +191 -0
  24. package/app/modules/stickerPackModule/stickerPackScoreSnapshotRuntime.js +301 -0
  25. package/app/modules/stickerPackModule/stickerStorageService.js +111 -10
  26. package/app/modules/stickerPackModule/stickerWorkerPipelineRuntime.js +21 -0
  27. package/app/modules/stickerPackModule/stickerWorkerTaskQueueRepository.js +59 -7
  28. package/app/observability/metrics.js +169 -0
  29. package/app/services/featureFlagService.js +137 -0
  30. package/app/services/lidMapService.js +4 -1
  31. package/app/services/whatsappLoginLinkService.js +232 -0
  32. package/database/index.js +5 -0
  33. package/database/migrations/20260228_0021_sticker_web_google_owner_phone.sql +83 -0
  34. package/database/migrations/20260228_0022_sticker_scale_indexes.sql +16 -0
  35. package/database/migrations/20260228_0023_sticker_pack_score_snapshot.sql +25 -0
  36. package/database/migrations/20260228_0024_domain_event_outbox.sql +42 -0
  37. package/database/migrations/20260228_0025_sticker_worker_task_idempotency_dlq.sql +23 -0
  38. package/database/migrations/20260228_0026_feature_flags.sql +21 -0
  39. package/ecosystem.prod.config.cjs +70 -9
  40. package/index.js +26 -0
  41. package/package.json +5 -1
  42. package/public/index.html +128 -10
  43. package/public/js/apps/createPackApp.js +59 -272
  44. package/public/js/apps/homeApp.js +106 -0
  45. package/public/js/apps/loginApp.js +459 -0
  46. package/public/js/apps/stickersApp.js +34 -37
  47. package/public/js/apps/userApp.js +244 -0
  48. package/public/js/runtime/react-runtime.js +1 -0
  49. package/public/login/index.html +333 -0
  50. package/public/stickers/create/index.html +2 -1
  51. package/public/stickers/index.html +2 -1
  52. package/public/user/index.html +367 -0
  53. package/scripts/cache-bust.mjs +65 -11
  54. package/scripts/sticker-catalog-loadtest.mjs +208 -0
  55. package/scripts/sticker-worker-task.mjs +122 -0
package/.env.example CHANGED
@@ -427,6 +427,19 @@ STICKER_DATA_LIST_LIMIT=50
427
427
  STICKER_DATA_LIST_MAX_LIMIT=200
428
428
  STICKER_DATA_SCAN_MAX_FILES=10000
429
429
 
430
+ # Login web via WhatsApp -> Google
431
+ WHATSAPP_LOGIN_TRIGGER=iniciar
432
+ WHATSAPP_LOGIN_BASE_URL=https://omnizap.shop
433
+ WHATSAPP_LOGIN_PATH=/login/
434
+ WHATSAPP_LOGIN_LINK_SECRET=troque_por_um_segredo_forte
435
+ WHATSAPP_LOGIN_LINK_TTL_SECONDS=900
436
+ WHATSAPP_LOGIN_REQUIRE_SIGNATURE=true
437
+ # Canonical/cookies do catalogo web (necessario para compartilhar sessao entre www e dominio raiz)
438
+ SITE_CANONICAL_HOST=omnizap.shop
439
+ SITE_CANONICAL_SCHEME=https
440
+ SITE_CANONICAL_REDIRECT_ENABLED=true
441
+ SITE_COOKIE_DOMAIN=omnizap.shop
442
+
430
443
  # Paths locais (legado/uso auxiliar)
431
444
  STORE_PATH=./temp
432
445
 
package/README.md CHANGED
@@ -51,91 +51,35 @@ Conteúdo incluído no snapshot:
51
51
  Atualização em cache: **30 minutos** por padrão (`README_SUMMARY_CACHE_SECONDS=1800`).
52
52
 
53
53
  <!-- README_SNAPSHOT:START -->
54
- ## OmniZap System Snapshot
55
-
56
- Atualizado em: **2026-02-28T01:11:03.592Z**
57
- Janela de atualização: **1800 segundos**
58
-
59
- ### Totais do sistema
60
- - Usuários (lid_map): **5.502**
61
- - Grupos: **116**
62
- - Packs: **295**
63
- - Stickers: **6.313**
64
- - Mensagens registradas: **438.964**
65
-
66
- ### Tipos de mensagem mais usados (amostra de 25.000 mensagens)
67
- 1. `texto` - **16.530**
68
- 2. `figurinha` - **4.262**
69
- 3. `reacao` - **1.619**
70
- 4. `imagem` - **1.326**
71
- 5. `outros` - **799**
72
- 6. `video` - **245**
73
- 7. `audio` - **213**
74
- 8. `documento` - **6**
75
-
76
- ### Comandos disponíveis
77
- - `/add @user`
78
- - `/addmode`
79
- - `/autorequests`
80
- - `/autosticker`
81
- - `/ban @user`
82
- - `/captcha`
83
- - `/cat`
84
- - `/catimg`
85
- - `/catprompt`
86
- - `/catprompt reset`
87
- - `/dado`
88
- - `/down @user`
89
- - `/farewell`
90
- - `/groups`
91
- - `/info`
92
- - `/invite`
93
- - `/join`
94
- - `/leave`
95
- - `/menu anime`
96
- - `/menu figurinhas`
97
- - `/menu ia`
98
- - `/menu midia`
99
- - `/menu quote`
100
- - `/menu stats`
101
- - `/menuadm`
102
- - `/metadata`
103
- - `/newgroup`
104
- - `/noticias`
105
- - `/nsfw`
106
- - `/pack add`
107
- - `/pack create "Meu Pack"`
108
- - `/pack list`
109
- - `/pack send`
110
- - `/ping`
111
- - `/play`
112
- - `/playvid`
113
- - `/prefix`
114
- - `/premium`
115
- - `/quote`
116
- - `/ranking`
117
- - `/rankingglobal`
118
- - `/requests`
119
- - `/revoke`
120
- - `/s`
121
- - `/semmsg`
122
- - `/setdesc`
123
- - `/setgroup`
124
- - `/setsubject`
125
- - `/st`
126
- - `/stb`
127
- - `/sticker`
128
- - `/stickertext`
129
- - `/stickertextblink`
130
- - `/stickertextwhite`
131
- - `/stw`
132
- - `/temp`
133
- - `/tiktok`
134
- - `/toimg`
135
- - `/up @user`
136
- - `/updaterequests`
137
- - `/user perfil`
138
- - `/welcome`
54
+ ### Snapshot do Sistema
55
+
56
+ > Atualizado em `2026-02-28T04:28:50.529Z` | cache `1800s`
57
+
58
+ | Métrica | Valor |
59
+ | --- | ---: |
60
+ | Usuários (lid_map) | 5.504 |
61
+ | Grupos | 116 |
62
+ | Packs | 294 |
63
+ | Stickers | 6.796 |
64
+ | Mensagens registradas | 440.582 |
65
+
66
+ #### Tipos de mensagem mais usados (amostra: 25.000)
67
+ | Tipo | Total |
68
+ | --- | ---: |
69
+ | `texto` | 16.293 |
70
+ | `figurinha` | 4.718 |
71
+ | `reacao` | 1.506 |
72
+ | `imagem` | 1.286 |
73
+ | `outros` | 744 |
74
+ | `video` | 232 |
75
+ | `audio` | 216 |
76
+ | `documento` | 5 |
77
+
78
+ <details><summary>Comandos disponíveis (62)</summary>
79
+
80
+ `/add` · `/addmode` · `/autorequests` · `/autosticker` · `/ban` · `/captcha` · `/cat` · `/catimg` · `/catprompt` · `/catprompt reset` · `/dado` · `/down` · `/farewell` · `/groups` · `/info` · `/invite` · `/join` · `/leave` · `/menu anime` · `/menu figurinhas` · `/menu ia` · `/menu midia` · `/menu quote` · `/menu stats` · `/menuadm` · `/metadata` · `/newgroup` · `/noticias` · `/nsfw` · `/pack add` · `/pack create` · `/pack list` · `/pack send` · `/ping` · `/play` · `/playvid` · `/prefix` · `/premium` · `/quote` · `/ranking` · `/rankingglobal` · `/requests` · `/revoke` · `/s` · `/semmsg` · `/setdesc` · `/setgroup` · `/setsubject` · `/st` · `/stb` · `/sticker` · `/stickertext` · `/stickertextblink` · `/stickertextwhite` · `/stw` · `/temp` · `/tiktok` · `/toimg` · `/up` · `/updaterequests` · `/user perfil` · `/welcome`
81
+
82
+ </details>
139
83
  <!-- README_SNAPSHOT:END -->
140
84
 
141
85
  ## Recursos principais
@@ -9,7 +9,7 @@ import { handleRankingCommand } from '../modules/statsModule/rankingCommand.js';
9
9
  import { handleGlobalRankingCommand } from '../modules/statsModule/globalRankingCommand.js';
10
10
  import { handleNoMessageCommand } from '../modules/statsModule/noMessageCommand.js';
11
11
  import { handlePingCommand } from '../modules/systemMetricsModule/pingCommand.js';
12
- import { extractMessageContent, getExpiration, isGroupJid, isSameJidUser, resolveBotJid } from '../config/baileysConfig.js';
12
+ import { extractMessageContent, getExpiration, getJidServer, getJidUser, isGroupJid, isSameJidUser, normalizeJid, resolveBotJid } from '../config/baileysConfig.js';
13
13
  import logger from '../utils/logger/loggerModule.js';
14
14
  import { handleAntiLink } from '../utils/antiLink/antiLinkModule.js';
15
15
  import { handleCatCommand, handleCatImageCommand, handleCatPromptCommand } from '../modules/aiModule/catCommand.js';
@@ -25,9 +25,125 @@ import { handleRpgPokemonCommand } from '../modules/rpgPokemonModule/rpgPokemonC
25
25
  import groupConfigStore from '../store/groupConfigStore.js';
26
26
  import { sendAndStore } from '../services/messagePersistenceService.js';
27
27
  import { resolveCaptchaByMessage } from '../services/captchaService.js';
28
+ import { extractSenderInfoFromMessage, resolveUserId } from '../services/lidMapService.js';
29
+ import { buildWhatsAppGoogleLoginUrl } from '../services/whatsappLoginLinkService.js';
28
30
 
29
31
  const DEFAULT_COMMAND_PREFIX = process.env.COMMAND_PREFIX || '/';
30
32
  const COMMAND_REACT_EMOJI = process.env.COMMAND_REACT_EMOJI || '🤖';
33
+ const START_LOGIN_TRIGGER = String(process.env.WHATSAPP_LOGIN_TRIGGER || 'iniciar')
34
+ .trim()
35
+ .toLowerCase() || 'iniciar';
36
+ const WHATSAPP_USER_SERVERS = new Set(['s.whatsapp.net', 'c.us', 'hosted']);
37
+ const WHATSAPP_LID_SERVERS = new Set(['lid', 'hosted.lid']);
38
+
39
+ const normalizeTriggerText = (value) =>
40
+ String(value || '')
41
+ .trim()
42
+ .toLowerCase()
43
+ .normalize('NFD')
44
+ .replace(/[\u0300-\u036f]/g, '');
45
+
46
+ const isStartLoginTrigger = (text) => normalizeTriggerText(text) === START_LOGIN_TRIGGER;
47
+
48
+ const resolveCanonicalWhatsAppJid = (...candidates) => {
49
+ for (const candidate of candidates) {
50
+ const normalized = normalizeJid(String(candidate || '').trim());
51
+ if (!normalized) continue;
52
+ const server = getJidServer(normalized);
53
+ if (!WHATSAPP_USER_SERVERS.has(server) && !WHATSAPP_LID_SERVERS.has(server)) continue;
54
+ const user = String(getJidUser(normalized) || '')
55
+ .split(':')[0]
56
+ .replace(/\D+/g, '');
57
+ if (!user) continue;
58
+ if (user.length < 10 || user.length > 15) continue;
59
+ return normalizeJid(`${user}@s.whatsapp.net`) || normalized;
60
+ }
61
+ return '';
62
+ };
63
+
64
+ const maybeHandleStartLoginMessage = async ({
65
+ sock,
66
+ messageInfo,
67
+ extractedText,
68
+ senderName,
69
+ senderJid,
70
+ remoteJid,
71
+ expirationMessage,
72
+ isMessageFromBot,
73
+ isGroupMessage,
74
+ }) => {
75
+ if (isMessageFromBot || !isStartLoginTrigger(extractedText)) return false;
76
+
77
+ if (isGroupMessage) {
78
+ await sendAndStore(
79
+ sock,
80
+ remoteJid,
81
+ {
82
+ text: 'Por seguranca, envie *iniciar* no privado do bot para receber seu link de login.',
83
+ },
84
+ { quoted: messageInfo, ephemeralExpiration: expirationMessage },
85
+ );
86
+ return true;
87
+ }
88
+
89
+ const key = messageInfo?.key || {};
90
+ const senderInfo = extractSenderInfoFromMessage(messageInfo);
91
+ let canonicalUserId = resolveCanonicalWhatsAppJid(
92
+ senderInfo?.jid,
93
+ senderInfo?.lid,
94
+ senderInfo?.participantAlt,
95
+ key.participantAlt,
96
+ key.participant,
97
+ key.remoteJid,
98
+ senderJid,
99
+ );
100
+ try {
101
+ const resolvedUserId = await resolveUserId(senderInfo);
102
+ canonicalUserId = resolveCanonicalWhatsAppJid(resolvedUserId, canonicalUserId, senderInfo?.jid, senderInfo?.lid);
103
+ } catch (error) {
104
+ logger.warn('Falha ao resolver ID canonico para fluxo de login do WhatsApp.', {
105
+ error: error?.message,
106
+ });
107
+ }
108
+
109
+ const loginUrl = buildWhatsAppGoogleLoginUrl({ userId: canonicalUserId });
110
+ if (!loginUrl) {
111
+ logger.warn('Nao foi possivel montar link de login para mensagem "iniciar".', {
112
+ action: 'login_link_missing_user_phone',
113
+ remoteServer: getJidServer(key.remoteJid || ''),
114
+ participantServer: getJidServer(key.participant || ''),
115
+ participantAltServer: getJidServer(key.participantAlt || ''),
116
+ hasLid: Boolean(senderInfo?.lid),
117
+ hasJid: Boolean(senderInfo?.jid),
118
+ });
119
+ await sendAndStore(
120
+ sock,
121
+ remoteJid,
122
+ {
123
+ text: 'Nao consegui identificar seu numero de WhatsApp para o login. Tente novamente em alguns segundos.',
124
+ },
125
+ { quoted: messageInfo, ephemeralExpiration: expirationMessage },
126
+ );
127
+ return true;
128
+ }
129
+
130
+ const safeName = String(senderName || '').trim();
131
+ const greeting = safeName ? `Oi, *${safeName}*!` : 'Oi!';
132
+ await sendAndStore(
133
+ sock,
134
+ remoteJid,
135
+ {
136
+ text:
137
+ `${greeting}\n\n` +
138
+ 'Para continuar no OmniZap, faca login com Google neste link:\n' +
139
+ `${loginUrl}\n\n` +
140
+ 'Seu numero do WhatsApp sera vinculado automaticamente a conta logada.',
141
+ },
142
+ { quoted: messageInfo, ephemeralExpiration: expirationMessage },
143
+ );
144
+
145
+ return true;
146
+ };
31
147
 
32
148
  /**
33
149
  * Resolve o prefixo de comandos.
@@ -111,6 +227,22 @@ export const handleMessages = async (update, sock) => {
111
227
  });
112
228
  }
113
229
 
230
+ const handledStartLogin = await maybeHandleStartLoginMessage({
231
+ sock,
232
+ messageInfo,
233
+ extractedText,
234
+ senderName,
235
+ senderJid,
236
+ remoteJid,
237
+ expirationMessage,
238
+ isMessageFromBot,
239
+ isGroupMessage,
240
+ });
241
+
242
+ if (handledStartLogin) {
243
+ continue;
244
+ }
245
+
114
246
  /**
115
247
  * Envia uma reação automática quando a mensagem começa com o prefixo de comando.
116
248
  * A falha no envio da reação não interrompe o processamento do comando.
@@ -0,0 +1,68 @@
1
+ export const handleCatalogAdminRoutes = async ({
2
+ req,
3
+ res,
4
+ url,
5
+ segments,
6
+ handlers,
7
+ sendJson,
8
+ }) => {
9
+ if (segments[0] !== 'admin') return false;
10
+
11
+ if (segments.length === 2 && segments[1] === 'overview') {
12
+ await handlers.handleAdminOverviewRequest(req, res);
13
+ return true;
14
+ }
15
+
16
+ if (segments.length === 2 && segments[1] === 'users') {
17
+ await handlers.handleAdminUsersRequest(req, res, url);
18
+ return true;
19
+ }
20
+
21
+ if (segments.length === 2 && segments[1] === 'moderators') {
22
+ await handlers.handleAdminModeratorsRequest(req, res);
23
+ return true;
24
+ }
25
+
26
+ if (segments.length === 3 && segments[1] === 'moderators') {
27
+ await handlers.handleAdminModeratorDeleteRequest(req, res, segments[2]);
28
+ return true;
29
+ }
30
+
31
+ if (segments.length === 2 && segments[1] === 'packs') {
32
+ await handlers.handleAdminPacksRequest(req, res, url);
33
+ return true;
34
+ }
35
+
36
+ if (segments.length === 3 && segments[1] === 'packs') {
37
+ await handlers.handleAdminPackDetailsRequest(req, res, segments[2]);
38
+ return true;
39
+ }
40
+
41
+ if (segments.length === 4 && segments[1] === 'packs' && segments[3] === 'delete') {
42
+ await handlers.handleAdminPackDeleteRequest(req, res, segments[2]);
43
+ return true;
44
+ }
45
+
46
+ if (segments.length === 6 && segments[1] === 'packs' && segments[3] === 'stickers' && segments[5] === 'delete') {
47
+ await handlers.handleAdminPackStickerDeleteRequest(req, res, segments[2], segments[4]);
48
+ return true;
49
+ }
50
+
51
+ if (segments.length === 4 && segments[1] === 'stickers' && segments[3] === 'delete') {
52
+ await handlers.handleAdminGlobalStickerDeleteRequest(req, res, segments[2]);
53
+ return true;
54
+ }
55
+
56
+ if (segments.length === 2 && segments[1] === 'bans') {
57
+ await handlers.handleAdminBansRequest(req, res);
58
+ return true;
59
+ }
60
+
61
+ if (segments.length === 4 && segments[1] === 'bans' && segments[3] === 'revoke') {
62
+ await handlers.handleAdminBanRevokeRequest(req, res, segments[2]);
63
+ return true;
64
+ }
65
+
66
+ sendJson(req, res, 404, { error: 'Rota admin nao encontrada.' });
67
+ return true;
68
+ };
@@ -0,0 +1,34 @@
1
+ const METHOD_NOT_ALLOWED_BODY = { error: 'Metodo nao permitido.' };
2
+
3
+ const isReadMethod = (method) => method === 'GET' || method === 'HEAD';
4
+
5
+ export const handleCatalogAuthRoutes = async ({
6
+ req,
7
+ res,
8
+ pathname,
9
+ url,
10
+ apiBasePath,
11
+ handlers,
12
+ sendJson,
13
+ }) => {
14
+ if (pathname === `${apiBasePath}/auth/google/session`) {
15
+ await handlers.handleGoogleAuthSessionRequest(req, res);
16
+ return true;
17
+ }
18
+
19
+ if (pathname === `${apiBasePath}/me`) {
20
+ if (!isReadMethod(req.method || '')) {
21
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
22
+ return true;
23
+ }
24
+ await handlers.handleMyProfileRequest(req, res, url);
25
+ return true;
26
+ }
27
+
28
+ if (pathname === `${apiBasePath}/admin/session`) {
29
+ await handlers.handleAdminPanelSessionRequest(req, res);
30
+ return true;
31
+ }
32
+
33
+ return false;
34
+ };
@@ -0,0 +1,179 @@
1
+ const METHOD_NOT_ALLOWED_BODY = { error: 'Metodo nao permitido.' };
2
+
3
+ const isReadMethod = (method) => method === 'GET' || method === 'HEAD';
4
+
5
+ export const handleCatalogPublicRoutes = async ({
6
+ req,
7
+ res,
8
+ pathname,
9
+ url,
10
+ segments,
11
+ apiBasePath,
12
+ orphanApiPath,
13
+ handlers,
14
+ sendJson,
15
+ }) => {
16
+ if (pathname === apiBasePath) {
17
+ if (!isReadMethod(req.method || '')) {
18
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
19
+ return true;
20
+ }
21
+ await handlers.handleListRequest(req, res, url);
22
+ return true;
23
+ }
24
+
25
+ if (pathname === `${apiBasePath}/intents`) {
26
+ if (!isReadMethod(req.method || '')) {
27
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
28
+ return true;
29
+ }
30
+ await handlers.handleIntentCollectionsRequest(req, res, url);
31
+ return true;
32
+ }
33
+
34
+ if (pathname === `${apiBasePath}/creators`) {
35
+ if (!isReadMethod(req.method || '')) {
36
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
37
+ return true;
38
+ }
39
+ await handlers.handleCreatorRankingRequest(req, res, url);
40
+ return true;
41
+ }
42
+
43
+ if (pathname === `${apiBasePath}/recommendations`) {
44
+ if (!isReadMethod(req.method || '')) {
45
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
46
+ return true;
47
+ }
48
+ await handlers.handleRecommendationsRequest(req, res, url);
49
+ return true;
50
+ }
51
+
52
+ if (pathname === `${apiBasePath}/stats`) {
53
+ if (!isReadMethod(req.method || '')) {
54
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
55
+ return true;
56
+ }
57
+ await handlers.handleMarketplaceStatsRequest(req, res, url);
58
+ return true;
59
+ }
60
+
61
+ if (pathname === `${apiBasePath}/create-config`) {
62
+ if (!isReadMethod(req.method || '')) {
63
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
64
+ return true;
65
+ }
66
+ await handlers.handleCreatePackConfigRequest(req, res);
67
+ return true;
68
+ }
69
+
70
+ if (pathname === orphanApiPath) {
71
+ if (!isReadMethod(req.method || '')) {
72
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
73
+ return true;
74
+ }
75
+ await handlers.handleOrphanStickerListRequest(req, res, url);
76
+ return true;
77
+ }
78
+
79
+ if (segments.length === 1 && segments[0] === 'data-files') {
80
+ if (!isReadMethod(req.method || '')) {
81
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
82
+ return true;
83
+ }
84
+ await handlers.handleDataFileListRequest(req, res, url);
85
+ return true;
86
+ }
87
+
88
+ if (segments.length === 1 && segments[0] === 'system-summary') {
89
+ if (!isReadMethod(req.method || '')) {
90
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
91
+ return true;
92
+ }
93
+ await handlers.handleSystemSummaryRequest(req, res);
94
+ return true;
95
+ }
96
+
97
+ if (segments.length === 1 && segments[0] === 'project-summary') {
98
+ if (!isReadMethod(req.method || '')) {
99
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
100
+ return true;
101
+ }
102
+ await handlers.handleGitHubProjectSummaryRequest(req, res);
103
+ return true;
104
+ }
105
+
106
+ if (segments.length === 1 && segments[0] === 'global-ranking-summary') {
107
+ if (!isReadMethod(req.method || '')) {
108
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
109
+ return true;
110
+ }
111
+ await handlers.handleGlobalRankingSummaryRequest(req, res);
112
+ return true;
113
+ }
114
+
115
+ if (segments.length === 1 && segments[0] === 'readme-summary') {
116
+ if (!isReadMethod(req.method || '')) {
117
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
118
+ return true;
119
+ }
120
+ await handlers.handleReadmeSummaryRequest(req, res);
121
+ return true;
122
+ }
123
+
124
+ if (segments.length === 1 && segments[0] === 'readme-markdown') {
125
+ if (!isReadMethod(req.method || '')) {
126
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
127
+ return true;
128
+ }
129
+ await handlers.handleReadmeMarkdownRequest(req, res);
130
+ return true;
131
+ }
132
+
133
+ if (segments.length === 1 && segments[0] === 'support') {
134
+ if (!isReadMethod(req.method || '')) {
135
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
136
+ return true;
137
+ }
138
+ await handlers.handleSupportInfoRequest(req, res);
139
+ return true;
140
+ }
141
+
142
+ if (segments.length === 1 && segments[0] === 'bot-contact') {
143
+ if (!isReadMethod(req.method || '')) {
144
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
145
+ return true;
146
+ }
147
+ await handlers.handleBotContactInfoRequest(req, res);
148
+ return true;
149
+ }
150
+
151
+ if (segments.length === 1) {
152
+ if (!isReadMethod(req.method || '')) {
153
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
154
+ return true;
155
+ }
156
+ await handlers.handleDetailsRequest(req, res, segments[0], url);
157
+ return true;
158
+ }
159
+
160
+ if (segments.length === 2 && ['open', 'like', 'dislike'].includes(segments[1])) {
161
+ if (req.method !== 'POST') {
162
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
163
+ return true;
164
+ }
165
+ await handlers.handlePackInteractionRequest(req, res, segments[0], segments[1], url);
166
+ return true;
167
+ }
168
+
169
+ if (segments.length === 3 && segments[1] === 'stickers') {
170
+ if (!isReadMethod(req.method || '')) {
171
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
172
+ return true;
173
+ }
174
+ await handlers.handleAssetRequest(req, res, segments[0], segments[2]);
175
+ return true;
176
+ }
177
+
178
+ return false;
179
+ };
@@ -0,0 +1,92 @@
1
+ const METHOD_NOT_ALLOWED_BODY = { error: 'Metodo nao permitido.' };
2
+
3
+ const isPublishStateMethod = (method) => method === 'GET' || method === 'HEAD' || method === 'POST';
4
+
5
+ export const handleCatalogUploadRoutes = async ({
6
+ req,
7
+ res,
8
+ pathname,
9
+ url,
10
+ segments,
11
+ apiBasePath,
12
+ handlers,
13
+ sendJson,
14
+ }) => {
15
+ if (pathname === `${apiBasePath}/create`) {
16
+ if (req.method !== 'POST') {
17
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
18
+ return true;
19
+ }
20
+ await handlers.handleCreatePackRequest(req, res);
21
+ return true;
22
+ }
23
+
24
+ if (segments.length === 2 && segments[1] === 'manage') {
25
+ await handlers.handleManagedPackRequest(req, res, segments[0]);
26
+ return true;
27
+ }
28
+
29
+ if (segments.length === 3 && segments[1] === 'manage' && segments[2] === 'clone') {
30
+ await handlers.handleManagedPackCloneRequest(req, res, segments[0]);
31
+ return true;
32
+ }
33
+
34
+ if (segments.length === 3 && segments[1] === 'manage' && segments[2] === 'cover') {
35
+ await handlers.handleManagedPackCoverRequest(req, res, segments[0]);
36
+ return true;
37
+ }
38
+
39
+ if (segments.length === 3 && segments[1] === 'manage' && segments[2] === 'reorder') {
40
+ await handlers.handleManagedPackReorderRequest(req, res, segments[0]);
41
+ return true;
42
+ }
43
+
44
+ if (segments.length === 3 && segments[1] === 'manage' && segments[2] === 'analytics') {
45
+ await handlers.handleManagedPackAnalyticsRequest(req, res, segments[0]);
46
+ return true;
47
+ }
48
+
49
+ if (segments.length === 3 && segments[1] === 'manage' && segments[2] === 'stickers') {
50
+ await handlers.handleManagedPackStickerCreateRequest(req, res, segments[0]);
51
+ return true;
52
+ }
53
+
54
+ if (segments.length === 4 && segments[1] === 'manage' && segments[2] === 'stickers') {
55
+ await handlers.handleManagedPackStickerDeleteRequest(req, res, segments[0], segments[3]);
56
+ return true;
57
+ }
58
+
59
+ if (segments.length === 5 && segments[1] === 'manage' && segments[2] === 'stickers' && segments[4] === 'replace') {
60
+ await handlers.handleManagedPackStickerReplaceRequest(req, res, segments[0], segments[3]);
61
+ return true;
62
+ }
63
+
64
+ if (segments.length === 2 && segments[1] === 'publish-state') {
65
+ if (!isPublishStateMethod(req.method || '')) {
66
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
67
+ return true;
68
+ }
69
+ await handlers.handlePackPublishStateRequest(req, res, segments[0], url);
70
+ return true;
71
+ }
72
+
73
+ if (segments.length === 2 && segments[1] === 'finalize') {
74
+ if (req.method !== 'POST') {
75
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
76
+ return true;
77
+ }
78
+ await handlers.handleFinalizePackRequest(req, res, segments[0]);
79
+ return true;
80
+ }
81
+
82
+ if (segments.length === 2 && segments[1] === 'stickers-upload') {
83
+ if (req.method !== 'POST') {
84
+ sendJson(req, res, 405, METHOD_NOT_ALLOWED_BODY);
85
+ return true;
86
+ }
87
+ await handlers.handleUploadStickerToPackRequest(req, res, segments[0]);
88
+ return true;
89
+ }
90
+
91
+ return false;
92
+ };