@omnizap-system/omnizap 2.5.12
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.
- package/.clusterfuzzlite/Dockerfile +10 -0
- package/.env.example +907 -0
- package/.github/codeql/codeql-config.yml +10 -0
- package/.github/dependabot.yml +35 -0
- package/.github/workflows/ci.yml +73 -0
- package/.github/workflows/codeql.yml +106 -0
- package/.github/workflows/db-migration-check.yml +98 -0
- package/.github/workflows/dependency-review.yml +22 -0
- package/.github/workflows/deploy.yml +95 -0
- package/.github/workflows/release.yml +106 -0
- package/.github/workflows/security-attest-provenance.yml +51 -0
- package/.github/workflows/security-gitleaks.yml +34 -0
- package/.github/workflows/security-runner-hardening.yml +31 -0
- package/.github/workflows/security-scorecard.yml +44 -0
- package/.github/workflows/security-zap-baseline.yml +44 -0
- package/.github/workflows/security-zap-full-scan.yml +43 -0
- package/.github/workflows/security-zizmor.yml +36 -0
- package/.github/workflows/wiki-sync.yml +44 -0
- package/.gitleaks.toml +15 -0
- package/.prettierrc +34 -0
- package/CODE_OF_CONDUCT.md +114 -0
- package/LICENSE +56 -0
- package/README.md +110 -0
- package/SECURITY.md +110 -0
- package/app/config/index.js +4 -0
- package/app/configParts/adminIdentity.js +92 -0
- package/app/configParts/baileysConfig.js +1818 -0
- package/app/configParts/groupUtils.js +692 -0
- package/app/configParts/loggerConfig.js +394 -0
- package/app/configParts/messagePersistenceService.js +305 -0
- package/app/connection/baileysCompatibility.test.js +40 -0
- package/app/connection/baileysDbAuthState.js +344 -0
- package/app/connection/socketController.js +2243 -0
- package/app/controllers/messageController.js +7 -0
- package/app/controllers/messagePipeline/commandMiddleware.js +146 -0
- package/app/controllers/messagePipeline/conversationMiddleware.js +183 -0
- package/app/controllers/messagePipeline/messagePipelineMiddlewares.test.js +522 -0
- package/app/controllers/messagePipeline/postProcessingMiddleware.js +41 -0
- package/app/controllers/messagePipeline/preProcessingMiddlewares.js +166 -0
- package/app/controllers/messageProcessingPipeline.js +699 -0
- package/app/modules/adminModule/AGENT.md +4056 -0
- package/app/modules/adminModule/adminAiHelpService.js +56 -0
- package/app/modules/adminModule/adminConfigRuntime.js +177 -0
- package/app/modules/adminModule/commandConfig.json +7122 -0
- package/app/modules/adminModule/groupCommandHandlers.js +1823 -0
- package/app/modules/adminModule/groupCommandHandlers.test.js +350 -0
- package/app/modules/adminModule/groupEventHandlers.js +399 -0
- package/app/modules/aiModule/AGENT.md +547 -0
- package/app/modules/aiModule/aiAiHelpService.js +14 -0
- package/app/modules/aiModule/aiConfigRuntime.js +135 -0
- package/app/modules/aiModule/catCommand.js +967 -0
- package/app/modules/aiModule/commandConfig.json +981 -0
- package/app/modules/analyticsModule/messageAnalysisEventRepository.js +83 -0
- package/app/modules/gameModule/AGENT.md +196 -0
- package/app/modules/gameModule/commandConfig.json +366 -0
- package/app/modules/gameModule/diceCommand.js +42 -0
- package/app/modules/gameModule/gameAiHelpService.js +14 -0
- package/app/modules/gameModule/gameConfigRuntime.js +68 -0
- package/app/modules/menuModule/AGENT.md +205 -0
- package/app/modules/menuModule/commandConfig.json +366 -0
- package/app/modules/menuModule/common.js +316 -0
- package/app/modules/menuModule/menuAiHelpService.js +14 -0
- package/app/modules/menuModule/menuConfigRuntime.js +68 -0
- package/app/modules/menuModule/menus.js +66 -0
- package/app/modules/playModule/AGENT.md +321 -0
- package/app/modules/playModule/commandConfig.json +584 -0
- package/app/modules/playModule/playAiHelpService.js +14 -0
- package/app/modules/playModule/playCommand.js +1417 -0
- package/app/modules/playModule/playConfigRuntime.js +68 -0
- package/app/modules/quoteModule/AGENT.md +199 -0
- package/app/modules/quoteModule/commandConfig.json +366 -0
- package/app/modules/quoteModule/quoteAiHelpService.js +14 -0
- package/app/modules/quoteModule/quoteCommand.js +842 -0
- package/app/modules/quoteModule/quoteConfigRuntime.js +68 -0
- package/app/modules/rpgPokemonModule/AGENT.md +229 -0
- package/app/modules/rpgPokemonModule/commandConfig.json +386 -0
- package/app/modules/rpgPokemonModule/rpgBattleCanvasRenderer.js +795 -0
- package/app/modules/rpgPokemonModule/rpgBattleService.js +2110 -0
- package/app/modules/rpgPokemonModule/rpgBattleService.test.js +770 -0
- package/app/modules/rpgPokemonModule/rpgEvolutionUtils.js +22 -0
- package/app/modules/rpgPokemonModule/rpgPokemonAiHelpService.js +14 -0
- package/app/modules/rpgPokemonModule/rpgPokemonCommand.js +174 -0
- package/app/modules/rpgPokemonModule/rpgPokemonConfigRuntime.js +68 -0
- package/app/modules/rpgPokemonModule/rpgPokemonDomain.js +192 -0
- package/app/modules/rpgPokemonModule/rpgPokemonDomain.test.js +93 -0
- package/app/modules/rpgPokemonModule/rpgPokemonEvolution.test.js +46 -0
- package/app/modules/rpgPokemonModule/rpgPokemonMessages.js +746 -0
- package/app/modules/rpgPokemonModule/rpgPokemonRepository.js +1847 -0
- package/app/modules/rpgPokemonModule/rpgPokemonService.js +6839 -0
- package/app/modules/rpgPokemonModule/rpgProfileCanvasRenderer.js +354 -0
- package/app/modules/statsModule/AGENT.md +320 -0
- package/app/modules/statsModule/commandConfig.json +540 -0
- package/app/modules/statsModule/globalRankingCommand.js +64 -0
- package/app/modules/statsModule/rankingCommand.js +41 -0
- package/app/modules/statsModule/rankingCommon.js +1305 -0
- package/app/modules/statsModule/statsAiHelpService.js +14 -0
- package/app/modules/statsModule/statsConfigRuntime.js +68 -0
- package/app/modules/stickerModule/AGENT.md +692 -0
- package/app/modules/stickerModule/addStickerMetadata.js +239 -0
- package/app/modules/stickerModule/commandConfig.json +1216 -0
- package/app/modules/stickerModule/convertToWebp.js +367 -0
- package/app/modules/stickerModule/stickerAiHelpService.js +14 -0
- package/app/modules/stickerModule/stickerCommand.js +446 -0
- package/app/modules/stickerModule/stickerConfigRuntime.js +68 -0
- package/app/modules/stickerModule/stickerConvertCommand.js +159 -0
- package/app/modules/stickerModule/stickerTextCommand.js +653 -0
- package/app/modules/stickerPackModule/AGENT.md +215 -0
- package/app/modules/stickerPackModule/autoPackCollectorRuntime.js +20 -0
- package/app/modules/stickerPackModule/autoPackCollectorService.js +357 -0
- package/app/modules/stickerPackModule/commandConfig.json +387 -0
- package/app/modules/stickerPackModule/domainEventOutboxRepository.js +227 -0
- package/app/modules/stickerPackModule/domainEvents.js +52 -0
- package/app/modules/stickerPackModule/semanticReclassificationEngine.js +429 -0
- package/app/modules/stickerPackModule/semanticReclassificationEngine.test.js +75 -0
- package/app/modules/stickerPackModule/semanticThemeClusterService.js +544 -0
- package/app/modules/stickerPackModule/stickerAssetClassificationRepository.js +400 -0
- package/app/modules/stickerPackModule/stickerAssetRepository.js +400 -0
- package/app/modules/stickerPackModule/stickerAssetReprocessQueueRepository.js +175 -0
- package/app/modules/stickerPackModule/stickerAutoPackByTagsRuntime.js +3702 -0
- package/app/modules/stickerPackModule/stickerClassificationBackgroundRuntime.js +559 -0
- package/app/modules/stickerPackModule/stickerClassificationService.js +557 -0
- package/app/modules/stickerPackModule/stickerDedicatedTaskWorkerRuntime.js +249 -0
- package/app/modules/stickerPackModule/stickerDomainEventBus.js +65 -0
- package/app/modules/stickerPackModule/stickerDomainEventConsumerRuntime.js +208 -0
- package/app/modules/stickerPackModule/stickerMarketplaceDriftService.js +99 -0
- package/app/modules/stickerPackModule/stickerObjectStorageService.js +285 -0
- package/app/modules/stickerPackModule/stickerPackAiHelpService.js +14 -0
- package/app/modules/stickerPackModule/stickerPackCommandHandlers.js +1148 -0
- package/app/modules/stickerPackModule/stickerPackConfigRuntime.js +68 -0
- package/app/modules/stickerPackModule/stickerPackEngagementRepository.js +152 -0
- package/app/modules/stickerPackModule/stickerPackErrors.js +30 -0
- package/app/modules/stickerPackModule/stickerPackInteractionEventRepository.js +101 -0
- package/app/modules/stickerPackModule/stickerPackItemRepository.js +432 -0
- package/app/modules/stickerPackModule/stickerPackMarketplaceService.js +313 -0
- package/app/modules/stickerPackModule/stickerPackMessageService.js +268 -0
- package/app/modules/stickerPackModule/stickerPackRepository.js +450 -0
- package/app/modules/stickerPackModule/stickerPackScoreSnapshotRepository.js +179 -0
- package/app/modules/stickerPackModule/stickerPackScoreSnapshotRuntime.js +271 -0
- package/app/modules/stickerPackModule/stickerPackService.js +733 -0
- package/app/modules/stickerPackModule/stickerPackServiceRuntime.js +32 -0
- package/app/modules/stickerPackModule/stickerPackUtils.js +107 -0
- package/app/modules/stickerPackModule/stickerStorageService.js +559 -0
- package/app/modules/stickerPackModule/stickerWorkerPipelineRuntime.js +242 -0
- package/app/modules/stickerPackModule/stickerWorkerTaskQueueRepository.js +242 -0
- package/app/modules/systemMetricsModule/AGENT.md +193 -0
- package/app/modules/systemMetricsModule/commandConfig.json +344 -0
- package/app/modules/systemMetricsModule/pingCommand.js +399 -0
- package/app/modules/systemMetricsModule/systemMetricsAiHelpService.js +14 -0
- package/app/modules/systemMetricsModule/systemMetricsConfigRuntime.js +68 -0
- package/app/modules/tiktokModule/AGENT.md +196 -0
- package/app/modules/tiktokModule/commandConfig.json +366 -0
- package/app/modules/tiktokModule/tiktokAiHelpService.js +14 -0
- package/app/modules/tiktokModule/tiktokCommand.js +716 -0
- package/app/modules/tiktokModule/tiktokConfigRuntime.js +68 -0
- package/app/modules/userModule/AGENT.md +200 -0
- package/app/modules/userModule/commandConfig.json +386 -0
- package/app/modules/userModule/userAiHelpService.js +14 -0
- package/app/modules/userModule/userCommand.js +1155 -0
- package/app/modules/userModule/userConfigRuntime.js +68 -0
- package/app/modules/waifuPicsModule/AGENT.md +431 -0
- package/app/modules/waifuPicsModule/commandConfig.json +780 -0
- package/app/modules/waifuPicsModule/waifuPicsAiHelpService.js +14 -0
- package/app/modules/waifuPicsModule/waifuPicsCommand.js +586 -0
- package/app/modules/waifuPicsModule/waifuPicsConfigRuntime.js +68 -0
- package/app/observability/metrics.js +766 -0
- package/app/services/ai/aiHelpResponseCacheRepository.js +280 -0
- package/app/services/ai/aiLearningRepository.js +400 -0
- package/app/services/ai/commandConfigEnrichmentRepository.js +769 -0
- package/app/services/ai/commandConfigEnrichmentService.js +452 -0
- package/app/services/ai/commandConfigValidationService.js +443 -0
- package/app/services/ai/commandToolBuilderService.js +192 -0
- package/app/services/ai/conversationRouterService.js +516 -0
- package/app/services/ai/geminiService.js +115 -0
- package/app/services/ai/geminiService.test.js +87 -0
- package/app/services/ai/globalModuleAiHelpService.js +1412 -0
- package/app/services/ai/globalToolCallingService.js +203 -0
- package/app/services/ai/messageCommandExecutionService.js +391 -0
- package/app/services/ai/moduleAiHelpCoreService.js +1099 -0
- package/app/services/ai/moduleAiHelpWrapperFactory.js +65 -0
- package/app/services/ai/moduleCommandConfigRuntimeService.js +113 -0
- package/app/services/ai/moduleToolExecutorService.js +464 -0
- package/app/services/ai/moduleToolRegistryService.js +178 -0
- package/app/services/ai/toolCandidateSelectorService.js +781 -0
- package/app/services/auth/googleWebLinkService.js +80 -0
- package/app/services/auth/whatsappLoginLinkService.js +230 -0
- package/app/services/external/pokeApiService.js +398 -0
- package/app/services/group/groupMetadataService.js +311 -0
- package/app/services/infra/dbWriteQueue.js +874 -0
- package/app/services/infra/featureFlagService.js +131 -0
- package/app/services/infra/queueUtils.js +55 -0
- package/app/services/messaging/captchaService.js +491 -0
- package/app/services/messaging/messagePersistenceService.js +1 -0
- package/app/services/messaging/newsBroadcastService.js +347 -0
- package/app/services/sticker/stickerFocusService.js +347 -0
- package/app/services/sticker/stickerFocusService.test.js +43 -0
- package/app/store/aiPromptStore.js +38 -0
- package/app/store/conversationSessionStore.js +131 -0
- package/app/store/groupConfigStore.js +58 -0
- package/app/store/premiumUserStore.js +54 -0
- package/app/utils/antiLink/antiLinkModule.js +700 -0
- package/app/utils/http/getImageBufferModule.js +18 -0
- package/app/utils/json/jsonSanitizer.js +113 -0
- package/app/utils/json/jsonSanitizer.test.js +40 -0
- package/app/utils/systemMetrics/systemMetricsModule.js +88 -0
- package/app/workers/aiLearningWorker.js +605 -0
- package/app/workers/commandConfigEnrichmentWorker.js +242 -0
- package/database/index.js +2075 -0
- package/database/init.js +151 -0
- package/database/migrations/.gitkeep +0 -0
- package/database/migrations/20260307_d0_hardening_down.sql +64 -0
- package/database/migrations/20260307_d0_hardening_up.sql +79 -0
- package/database/migrations/20260307_d1_terms_acceptance_down.sql +11 -0
- package/database/migrations/20260307_d1_terms_acceptance_up.sql +37 -0
- package/database/migrations/20260307_d2_auth_hardening_down.sql +75 -0
- package/database/migrations/20260307_d2_auth_hardening_up.sql +100 -0
- package/database/migrations/20260314_d7_canonical_sender_down.sql +53 -0
- package/database/migrations/20260314_d7_canonical_sender_up.sql +114 -0
- package/database/migrations/20260406_d30_security_analytics_down.sql +95 -0
- package/database/migrations/20260406_d30_security_analytics_up.sql +292 -0
- package/database/migrations/20260407_d31_web_google_session_token_hardening_down.sql +2 -0
- package/database/migrations/20260407_d31_web_google_session_token_hardening_up.sql +17 -0
- package/database/migrations/20260408_d32_ai_help_response_cache_down.sql +1 -0
- package/database/migrations/20260408_d32_ai_help_response_cache_up.sql +22 -0
- package/database/migrations/20260409_d33_ai_learning_tables_down.sql +4 -0
- package/database/migrations/20260409_d33_ai_learning_tables_up.sql +52 -0
- package/database/migrations/20260410_d34_command_config_enrichment_down.sql +3 -0
- package/database/migrations/20260410_d34_command_config_enrichment_up.sql +48 -0
- package/database/schema.sql +1186 -0
- package/docker-compose.yml +104 -0
- package/docs/audits/stickerCatalogController-out-of-scope.md +103 -0
- package/docs/audits/stickerCatalogController-symbols.md +58 -0
- package/docs/compliance/acceptable-use-policy-2026-03-07.md +35 -0
- package/docs/compliance/dpa-b2b-standard-2026-03-07.md +80 -0
- package/docs/compliance/monthly-compliance-checklist-2026-03-07.md +88 -0
- package/docs/compliance/notice-and-takedown-policy-2026-03-07.md +34 -0
- package/docs/compliance/privacy-policy-2026-03-07.md +75 -0
- package/docs/compliance/subprocessors-inventory-2026-03-07.md +16 -0
- package/docs/database/production-db-evolution-runbook-2026q1.md +365 -0
- package/docs/security/dsar-lgpd-runbook-2026-03-07.md +86 -0
- package/docs/security/incident-response-lgpd-anpd-runbook-2026-03-07.md +77 -0
- package/docs/security/network-hardening-runbook-2026-03-07.md +137 -0
- package/docs/seo/omnizap-seo-playbook-br-2026-02-28.md +238 -0
- package/docs/seo/satellite-page-template.md +116 -0
- package/docs/seo/satellite-pages-phase1.json +364 -0
- package/docs/wiki/Home.md +120 -0
- package/docs/wiki/pair-extraordinaire-2026-03-08.md +3 -0
- package/docs/wiki/recent-changes-2026-03-08.md +47 -0
- package/ecosystem.prod.config.cjs +135 -0
- package/eslint.config.js +89 -0
- package/index.js +488 -0
- package/ml/clip_classifier/Dockerfile +18 -0
- package/ml/clip_classifier/README.md +118 -0
- package/ml/clip_classifier/adaptive_scoring.py +40 -0
- package/ml/clip_classifier/classifier.py +654 -0
- package/ml/clip_classifier/embedding_store.py +481 -0
- package/ml/clip_classifier/env_loader.py +15 -0
- package/ml/clip_classifier/llm_label_expander.py +144 -0
- package/ml/clip_classifier/main.py +213 -0
- package/ml/clip_classifier/requirements.txt +10 -0
- package/ml/clip_classifier/similarity_engine.py +74 -0
- package/new-logo.png +0 -0
- package/observability/alert-rules.yml +60 -0
- package/observability/grafana/dashboards/omnizap-mysql.json +136 -0
- package/observability/grafana/dashboards/omnizap-overview.json +170 -0
- package/observability/grafana/provisioning/dashboards/dashboards.yml +11 -0
- package/observability/grafana/provisioning/datasources/datasources.yml +15 -0
- package/observability/loki-config.yml +38 -0
- package/observability/mysql-setup.sql +46 -0
- package/observability/prometheus.yml +35 -0
- package/observability/promtail-config.yml +84 -0
- package/observability/sticker-catalog-slo.md +83 -0
- package/observability/sticker-scale-hardening-rollout.md +128 -0
- package/package.json +144 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/assets/css/commands-react.input.css +71 -0
- package/public/assets/css/create-pack-react.input.css +31 -0
- package/public/assets/css/home-react.input.css +106 -0
- package/public/assets/css/login-react.input.css +58 -0
- package/public/assets/css/stickers-react.input.css +18 -0
- package/public/assets/css/terms-react.input.css +115 -0
- package/public/assets/css/user-react.input.css +57 -0
- package/public/assets/images/brand-icon-192.png +0 -0
- package/public/assets/images/brand-logo-128.webp +0 -0
- package/public/assets/images/hero-banner-1280.jpg +0 -0
- package/public/comandos/commands-catalog.json +4517 -0
- package/public/css/api-docs.css +161 -0
- package/public/css/stickers-admin.css +1288 -0
- package/public/css/styles.css +679 -0
- package/public/css/systemadm/admin.css +474 -0
- package/public/css/systemadm/base.css +73 -0
- package/public/css/systemadm/components.css +662 -0
- package/public/css/systemadm/layout.css +229 -0
- package/public/css/systemadm/tokens.css +56 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/js/apps/apiDocsApp.js +235 -0
- package/public/js/apps/commandsReactApp.js +528 -0
- package/public/js/apps/createPackApp.js +1646 -0
- package/public/js/apps/homeReactApp.js +942 -0
- package/public/js/apps/loginReactApp.js +496 -0
- package/public/js/apps/stickersAdminApp.js +1753 -0
- package/public/js/apps/stickersApp.js +3797 -0
- package/public/js/apps/termsReactApp.js +528 -0
- package/public/js/apps/userApp.js +2540 -0
- package/public/js/apps/userProfile/actions.js +66 -0
- package/public/js/apps/userReactApp.js +547 -0
- package/public/js/catalog.js +950 -0
- package/public/pages/api-docs.html +40 -0
- package/public/pages/aup.html +158 -0
- package/public/pages/comandos.html +41 -0
- package/public/pages/dpa.html +227 -0
- package/public/pages/home.html +45 -0
- package/public/pages/licenca.html +182 -0
- package/public/pages/login.html +40 -0
- package/public/pages/notice-and-takedown.html +234 -0
- package/public/pages/politica-de-privacidade.html +251 -0
- package/public/pages/seo-bot-whatsapp-para-grupo.html +350 -0
- package/public/pages/seo-bot-whatsapp-sem-programar.html +350 -0
- package/public/pages/seo-como-automatizar-avisos-no-whatsapp.html +350 -0
- package/public/pages/seo-como-criar-comandos-whatsapp.html +350 -0
- package/public/pages/seo-como-evitar-spam-no-whatsapp.html +350 -0
- package/public/pages/seo-como-moderar-grupo-whatsapp.html +350 -0
- package/public/pages/seo-como-organizar-comunidade-whatsapp.html +350 -0
- package/public/pages/seo-melhor-bot-whatsapp-para-grupos.html +350 -0
- package/public/pages/stickers-admin.html +31 -0
- package/public/pages/stickers-create.html +41 -0
- package/public/pages/stickers.html +45 -0
- package/public/pages/suboperadores.html +237 -0
- package/public/pages/termos-de-uso-texto-integral.html +241 -0
- package/public/pages/termos-de-uso.html +41 -0
- package/public/pages/user-password-reset.html +32 -0
- package/public/pages/user-systemadm.html +508 -0
- package/public/pages/user.html +39 -0
- package/public/robots.txt +9 -0
- package/public/site.webmanifest +24 -0
- package/public/sitemap.xml +98 -0
- package/schemas/command-config.schema.json +582 -0
- package/scripts/baileys-compat-smoke.mjs +12 -0
- package/scripts/cache-bust.mjs +142 -0
- package/scripts/deploy.sh +916 -0
- package/scripts/email-broadcast-terms-update.mjs +170 -0
- package/scripts/enrich-command-discovery-fields.mjs +286 -0
- package/scripts/generate-command-config-schema.mjs +273 -0
- package/scripts/generate-commands-catalog.mjs +308 -0
- package/scripts/generate-module-agents.mjs +631 -0
- package/scripts/generate-seo-satellite-pages.mjs +400 -0
- package/scripts/github-deploy-notify.mjs +174 -0
- package/scripts/github-release-notify.mjs +219 -0
- package/scripts/release.sh +599 -0
- package/scripts/run-codeql-local.sh +116 -0
- package/scripts/run-prettier-all.mjs +25 -0
- package/scripts/security-smoketest.mjs +581 -0
- package/scripts/sticker-catalog-loadtest.mjs +210 -0
- package/scripts/sticker-worker-task.mjs +119 -0
- package/scripts/sync-readme-snapshot.mjs +133 -0
- package/scripts/validate-command-config-schema.mjs +130 -0
- package/scripts/validate-command-configs.mjs +15 -0
- package/scripts/wiki-sync.sh +191 -0
- package/server/auth/googleWebAuth/googleWebAuthRuntime.js +62 -0
- package/server/auth/googleWebAuth/googleWebAuthService.js +807 -0
- package/server/auth/jwt/webJwtService.js +147 -0
- package/server/auth/stickerCatalogAuthContext.js +165 -0
- package/server/auth/termsAcceptance/termsAcceptanceHandler.js +189 -0
- package/server/auth/userPassword/index.js +14 -0
- package/server/auth/userPassword/userPasswordAuthService.js +422 -0
- package/server/auth/userPassword/userPasswordCrypto.js +199 -0
- package/server/auth/userPassword/userPasswordCrypto.test.js +76 -0
- package/server/auth/userPassword/userPasswordRecoveryService.js +728 -0
- package/server/auth/validation/authSchemas.js +236 -0
- package/server/auth/webAccount/webAccountHandlers.js +1434 -0
- package/server/controllers/admin/adminBanService.js +138 -0
- package/server/controllers/admin/adminPanelHandlers.js +2083 -0
- package/server/controllers/admin/stickerCatalogAdminContext.js +17 -0
- package/server/controllers/admin/systemAdminController.js +201 -0
- package/server/controllers/email/emailAutomationController.js +239 -0
- package/server/controllers/metricsController.js +21 -0
- package/server/controllers/seo/stickerCatalogSeoContext.js +514 -0
- package/server/controllers/sticker/nonCatalogHandlers.js +303 -0
- package/server/controllers/sticker/stickerCatalogController.js +4700 -0
- package/server/controllers/system/contactController.js +115 -0
- package/server/controllers/system/githubController.js +137 -0
- package/server/controllers/system/stickerCatalogSystemContext.js +758 -0
- package/server/controllers/system/storageController.js +154 -0
- package/server/controllers/system/systemController.js +135 -0
- package/server/controllers/system/systemMetricsController.js +156 -0
- package/server/controllers/system/visitController.js +90 -0
- package/server/controllers/userController.js +145 -0
- package/server/email/emailAutomationRuntime.js +225 -0
- package/server/email/emailAutomationService.js +125 -0
- package/server/email/emailOutboxRepository.js +282 -0
- package/server/email/emailTemplateService.js +480 -0
- package/server/email/emailTransportService.js +156 -0
- package/server/http/clientIp.js +95 -0
- package/server/http/httpRequestUtils.js +262 -0
- package/server/http/httpRequestUtils.test.js +80 -0
- package/server/http/httpServer.js +180 -0
- package/server/http/requestContext.js +20 -0
- package/server/http/siteRoutingUtils.js +87 -0
- package/server/index.js +1 -0
- package/server/middleware/cachePolicy.js +26 -0
- package/server/middleware/cachePolicyHelpers.js +1 -0
- package/server/middleware/endpointRateLimit.js +181 -0
- package/server/middleware/rateLimit.js +70 -0
- package/server/middleware/requireAdminAuth.js +48 -0
- package/server/middleware/securityHeaders.js +97 -0
- package/server/routes/admin/systemAdminRouter.js +64 -0
- package/server/routes/email/emailAutomationRouter.js +46 -0
- package/server/routes/health/healthRouter.js +41 -0
- package/server/routes/indexRouter.js +234 -0
- package/server/routes/metrics/metricsRouter.js +58 -0
- package/server/routes/static/staticPageRouter.js +134 -0
- package/server/routes/sticker/catalogHandlers/catalogAdminHttp.js +105 -0
- package/server/routes/sticker/catalogHandlers/catalogAuthHttp.js +77 -0
- package/server/routes/sticker/catalogHandlers/catalogPublicHttp.js +120 -0
- package/server/routes/sticker/catalogHandlers/catalogUploadHttp.js +83 -0
- package/server/routes/sticker/catalogRouter.js +77 -0
- package/server/routes/sticker/stickerApiRouter.js +84 -0
- package/server/routes/sticker/stickerDataRouter.js +145 -0
- package/server/routes/sticker/stickerSiteRouter.js +43 -0
- package/server/routes/user/userApiPaths.js +66 -0
- package/server/routes/user/userRouter.js +65 -0
- package/server/utils/safePath.js +26 -0
- package/utils/logger/loggerModule.js +35 -0
- package/vite.config.mjs +38 -0
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const root = document.getElementById('catalog-root');
|
|
3
|
+
if (!root) return;
|
|
4
|
+
|
|
5
|
+
const parseIntSafe = (value, fallback) => {
|
|
6
|
+
const parsed = Number.parseInt(String(value || ''), 10);
|
|
7
|
+
if (!Number.isFinite(parsed) || parsed <= 0) return fallback;
|
|
8
|
+
return parsed;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const CONFIG = {
|
|
12
|
+
apiBasePath: root.dataset.apiBasePath || '/api/sticker-packs',
|
|
13
|
+
orphanApiPath: root.dataset.orphanApiPath || '/api/sticker-packs/orphan-stickers',
|
|
14
|
+
webPath: root.dataset.webPath || '/stickers',
|
|
15
|
+
dataPublicPath: root.dataset.dataPublicPath || '/data',
|
|
16
|
+
initialPackKey: String(root.dataset.initialPackKey || '').trim() || null,
|
|
17
|
+
defaultLimit: parseIntSafe(root.dataset.defaultLimit, 24),
|
|
18
|
+
defaultOrphanLimit: parseIntSafe(root.dataset.defaultOrphanLimit, 120),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const state = {
|
|
22
|
+
q: '',
|
|
23
|
+
catalogLoaded: false,
|
|
24
|
+
visibility: 'public',
|
|
25
|
+
categories: [],
|
|
26
|
+
packs: {
|
|
27
|
+
offset: 0,
|
|
28
|
+
limit: CONFIG.defaultLimit,
|
|
29
|
+
hasMore: true,
|
|
30
|
+
loading: false,
|
|
31
|
+
items: [],
|
|
32
|
+
},
|
|
33
|
+
orphan: {
|
|
34
|
+
page: 1,
|
|
35
|
+
limit: CONFIG.defaultOrphanLimit,
|
|
36
|
+
totalPages: 1,
|
|
37
|
+
totalItems: 0,
|
|
38
|
+
loading: false,
|
|
39
|
+
items: [],
|
|
40
|
+
},
|
|
41
|
+
panelPagination: {
|
|
42
|
+
page: 1,
|
|
43
|
+
perPage: 100,
|
|
44
|
+
totalPages: 1,
|
|
45
|
+
},
|
|
46
|
+
selectedPack: null,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const els = {
|
|
50
|
+
hero: document.getElementById('catalog-hero'),
|
|
51
|
+
form: document.getElementById('search-form'),
|
|
52
|
+
search: document.getElementById('search-input'),
|
|
53
|
+
visibility: document.getElementById('visibility-input'),
|
|
54
|
+
categories: document.getElementById('categories-input'),
|
|
55
|
+
categoriesPicker: document.getElementById('categories-picker'),
|
|
56
|
+
categoriesSearch: document.getElementById('categories-search'),
|
|
57
|
+
categoriesChips: document.getElementById('categories-chips'),
|
|
58
|
+
categoriesOptions: document.getElementById('categories-options'),
|
|
59
|
+
status: document.getElementById('status'),
|
|
60
|
+
grid: document.getElementById('grid'),
|
|
61
|
+
more: document.getElementById('load-more'),
|
|
62
|
+
orphanStatus: document.getElementById('orphan-status'),
|
|
63
|
+
orphanGrid: document.getElementById('orphan-grid'),
|
|
64
|
+
orphanPagination: document.getElementById('orphan-pagination'),
|
|
65
|
+
orphanPrev: document.getElementById('orphan-prev'),
|
|
66
|
+
orphanNext: document.getElementById('orphan-next'),
|
|
67
|
+
orphanPageInfo: document.getElementById('orphan-page-info'),
|
|
68
|
+
orphanMore: document.getElementById('orphan-load-more'),
|
|
69
|
+
panelPagination: document.getElementById('panel-pagination'),
|
|
70
|
+
panelPrev: document.getElementById('panel-prev'),
|
|
71
|
+
panelNext: document.getElementById('panel-next'),
|
|
72
|
+
panelPageInfo: document.getElementById('panel-page-info'),
|
|
73
|
+
panel: document.getElementById('panel'),
|
|
74
|
+
panelTitle: document.getElementById('panel-title'),
|
|
75
|
+
panelSub: document.getElementById('panel-subtitle'),
|
|
76
|
+
panelChip: document.getElementById('panel-chip'),
|
|
77
|
+
panelError: document.getElementById('panel-error'),
|
|
78
|
+
panelClose: document.getElementById('panel-close'),
|
|
79
|
+
copy: document.getElementById('copy-link'),
|
|
80
|
+
useWhatsAppLink: document.getElementById('use-whatsapp-link'),
|
|
81
|
+
stickers: document.getElementById('stickers'),
|
|
82
|
+
packPage: document.getElementById('pack-page'),
|
|
83
|
+
packPageTitle: document.getElementById('pack-page-title'),
|
|
84
|
+
packPageSub: document.getElementById('pack-page-subtitle'),
|
|
85
|
+
packPageChip: document.getElementById('pack-page-chip'),
|
|
86
|
+
packPageStatus: document.getElementById('pack-page-status'),
|
|
87
|
+
packPageGrid: document.getElementById('pack-page-stickers'),
|
|
88
|
+
packPageBack: document.getElementById('pack-page-back'),
|
|
89
|
+
packPageCopy: document.getElementById('pack-page-copy'),
|
|
90
|
+
packPageWhatsApp: document.getElementById('pack-page-whatsapp'),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (!els.hero || !els.form || !els.search || !els.visibility || !els.categories || !els.categoriesPicker || !els.categoriesSearch || !els.categoriesChips || !els.categoriesOptions || !els.status || !els.grid || !els.more || !els.orphanStatus || !els.orphanGrid || !els.orphanPrev || !els.orphanNext || !els.orphanPageInfo || !els.panel || !els.panelTitle || !els.panelSub || !els.panelChip || !els.panelError || !els.panelPrev || !els.panelNext || !els.panelPageInfo || !els.copy || !els.useWhatsAppLink || !els.stickers || !els.packPage || !els.packPageTitle || !els.packPageSub || !els.packPageChip || !els.packPageStatus || !els.packPageGrid || !els.packPageBack || !els.packPageCopy || !els.packPageWhatsApp) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const panelModal = window.bootstrap?.Modal ? window.bootstrap.Modal.getOrCreateInstance(els.panel) : null;
|
|
98
|
+
|
|
99
|
+
let shouldReplaceStateOnHide = false;
|
|
100
|
+
|
|
101
|
+
els.panelPrev.disabled = true;
|
|
102
|
+
els.panelNext.disabled = true;
|
|
103
|
+
els.orphanPrev.disabled = true;
|
|
104
|
+
els.orphanNext.disabled = true;
|
|
105
|
+
if (els.orphanMore) els.orphanMore.hidden = true;
|
|
106
|
+
|
|
107
|
+
const toApi = (path, searchParams) => {
|
|
108
|
+
const url = new URL(path, window.location.origin);
|
|
109
|
+
if (searchParams) {
|
|
110
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
111
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
112
|
+
url.searchParams.set(key, String(value));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return url.toString();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const extractPackKeyFromPath = () => {
|
|
120
|
+
const path = window.location.pathname;
|
|
121
|
+
if (!path.startsWith(CONFIG.webPath + '/')) return '';
|
|
122
|
+
try {
|
|
123
|
+
return decodeURIComponent(path.slice((CONFIG.webPath + '/').length).split('/')[0] || '');
|
|
124
|
+
} catch {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const getSelectedCategories = () =>
|
|
130
|
+
Array.from(els.categories.selectedOptions || [])
|
|
131
|
+
.map((option) => String(option.value || '').trim())
|
|
132
|
+
.filter(Boolean);
|
|
133
|
+
|
|
134
|
+
const normalizeCategorySearch = (value) =>
|
|
135
|
+
String(value || '')
|
|
136
|
+
.toLowerCase()
|
|
137
|
+
.normalize('NFD')
|
|
138
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
139
|
+
.trim();
|
|
140
|
+
|
|
141
|
+
const categoryCatalog = Array.from(els.categories.options || []).map((option) => ({
|
|
142
|
+
value: String(option.value || '').trim(),
|
|
143
|
+
label: String(option.textContent || option.value || '').trim(),
|
|
144
|
+
}));
|
|
145
|
+
|
|
146
|
+
const syncCategorySelect = (selectedValues) => {
|
|
147
|
+
const selected = new Set((selectedValues || []).map((value) => String(value || '').trim()).filter(Boolean));
|
|
148
|
+
Array.from(els.categories.options || []).forEach((option) => {
|
|
149
|
+
option.selected = selected.has(String(option.value || '').trim());
|
|
150
|
+
});
|
|
151
|
+
state.categories = getSelectedCategories();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const renderCategoryChips = () => {
|
|
155
|
+
els.categoriesChips.innerHTML = '';
|
|
156
|
+
if (!state.categories.length) {
|
|
157
|
+
const empty = document.createElement('span');
|
|
158
|
+
empty.className = 'categories-empty';
|
|
159
|
+
empty.textContent = 'Nenhuma categoria selecionada';
|
|
160
|
+
els.categoriesChips.appendChild(empty);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
state.categories.forEach((value) => {
|
|
165
|
+
const entry = categoryCatalog.find((item) => item.value === value);
|
|
166
|
+
const chip = document.createElement('button');
|
|
167
|
+
chip.type = 'button';
|
|
168
|
+
chip.className = 'category-chip';
|
|
169
|
+
chip.dataset.value = value;
|
|
170
|
+
chip.setAttribute('aria-label', 'Remover categoria ' + (entry?.label || value));
|
|
171
|
+
const label = document.createElement('span');
|
|
172
|
+
label.className = 'category-chip-label';
|
|
173
|
+
label.textContent = entry?.label || value;
|
|
174
|
+
|
|
175
|
+
const removeIcon = document.createElement('i');
|
|
176
|
+
removeIcon.className = 'fa-solid fa-xmark category-chip-remove';
|
|
177
|
+
removeIcon.setAttribute('aria-hidden', 'true');
|
|
178
|
+
|
|
179
|
+
chip.append(label, removeIcon);
|
|
180
|
+
els.categoriesChips.appendChild(chip);
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const renderCategoryOptions = () => {
|
|
185
|
+
const query = normalizeCategorySearch(els.categoriesSearch.value);
|
|
186
|
+
const selected = new Set(state.categories);
|
|
187
|
+
const filtered = categoryCatalog.filter((entry) => {
|
|
188
|
+
if (!entry.value) return false;
|
|
189
|
+
if (!query) return true;
|
|
190
|
+
return normalizeCategorySearch(entry.label).includes(query) || normalizeCategorySearch(entry.value).includes(query);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
els.categoriesOptions.innerHTML = '';
|
|
194
|
+
|
|
195
|
+
if (!filtered.length) {
|
|
196
|
+
const empty = document.createElement('div');
|
|
197
|
+
empty.className = 'categories-options-empty';
|
|
198
|
+
empty.textContent = 'Nenhuma categoria encontrada';
|
|
199
|
+
els.categoriesOptions.appendChild(empty);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
filtered.forEach((entry) => {
|
|
204
|
+
const button = document.createElement('button');
|
|
205
|
+
button.type = 'button';
|
|
206
|
+
button.className = 'category-option' + (selected.has(entry.value) ? ' selected' : '');
|
|
207
|
+
button.dataset.value = entry.value;
|
|
208
|
+
|
|
209
|
+
const label = document.createElement('span');
|
|
210
|
+
label.className = 'category-option-label';
|
|
211
|
+
label.textContent = entry.label;
|
|
212
|
+
|
|
213
|
+
const checkIcon = document.createElement('i');
|
|
214
|
+
checkIcon.className = 'fa-solid fa-check category-option-check';
|
|
215
|
+
checkIcon.setAttribute('aria-hidden', 'true');
|
|
216
|
+
|
|
217
|
+
button.append(label, checkIcon);
|
|
218
|
+
els.categoriesOptions.appendChild(button);
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const applyFilters = async () => {
|
|
223
|
+
state.q = els.search.value.trim();
|
|
224
|
+
state.visibility = els.visibility.value;
|
|
225
|
+
state.categories = getSelectedCategories();
|
|
226
|
+
await Promise.all([listPacks({ reset: true }), listOrphanStickers({ reset: true })]);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
let filterRefreshTimer = null;
|
|
230
|
+
const scheduleFilterRefresh = () => {
|
|
231
|
+
if (filterRefreshTimer) {
|
|
232
|
+
clearTimeout(filterRefreshTimer);
|
|
233
|
+
}
|
|
234
|
+
filterRefreshTimer = setTimeout(() => {
|
|
235
|
+
filterRefreshTimer = null;
|
|
236
|
+
void applyFilters();
|
|
237
|
+
}, 120);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const toggleCategory = (value) => {
|
|
241
|
+
const normalized = String(value || '').trim();
|
|
242
|
+
if (!normalized) return;
|
|
243
|
+
const selected = new Set(state.categories);
|
|
244
|
+
if (selected.has(normalized)) {
|
|
245
|
+
selected.delete(normalized);
|
|
246
|
+
} else {
|
|
247
|
+
selected.add(normalized);
|
|
248
|
+
}
|
|
249
|
+
syncCategorySelect(Array.from(selected));
|
|
250
|
+
renderCategoryChips();
|
|
251
|
+
renderCategoryOptions();
|
|
252
|
+
scheduleFilterRefresh();
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const initCategoriesPicker = () => {
|
|
256
|
+
syncCategorySelect(getSelectedCategories());
|
|
257
|
+
renderCategoryChips();
|
|
258
|
+
renderCategoryOptions();
|
|
259
|
+
|
|
260
|
+
els.categoriesSearch.addEventListener('input', () => {
|
|
261
|
+
renderCategoryOptions();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
els.categoriesOptions.addEventListener('click', (event) => {
|
|
265
|
+
const option = event.target.closest('.category-option');
|
|
266
|
+
if (!option) return;
|
|
267
|
+
toggleCategory(option.dataset.value);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
els.categoriesChips.addEventListener('click', (event) => {
|
|
271
|
+
const chip = event.target.closest('.category-chip');
|
|
272
|
+
if (!chip) return;
|
|
273
|
+
toggleCategory(chip.dataset.value);
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
initCategoriesPicker();
|
|
278
|
+
|
|
279
|
+
const showCatalogView = () => {
|
|
280
|
+
els.packPage.hidden = true;
|
|
281
|
+
els.hero.hidden = false;
|
|
282
|
+
document.getElementById('packs-section').hidden = false;
|
|
283
|
+
document.getElementById('orphan-section').hidden = false;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const showPackPageView = () => {
|
|
287
|
+
els.packPage.hidden = false;
|
|
288
|
+
els.hero.hidden = true;
|
|
289
|
+
document.getElementById('packs-section').hidden = true;
|
|
290
|
+
document.getElementById('orphan-section').hidden = true;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const setStatus = (text) => {
|
|
294
|
+
els.status.textContent = text || '';
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const setOrphanStatus = (text) => {
|
|
298
|
+
els.orphanStatus.textContent = text || '';
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const applyWhatsAppLink = (element, url) => {
|
|
302
|
+
if (!element) return;
|
|
303
|
+
const value = String(url || '').trim();
|
|
304
|
+
if (!value) {
|
|
305
|
+
element.hidden = true;
|
|
306
|
+
element.removeAttribute('href');
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
element.hidden = false;
|
|
310
|
+
element.setAttribute('href', value);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const fetchJson = async (url) => {
|
|
314
|
+
const response = await fetch(url);
|
|
315
|
+
const data = await response.json().catch(() => ({}));
|
|
316
|
+
if (!response.ok) {
|
|
317
|
+
const message = (data && data.error) || 'Falha ao carregar dados.';
|
|
318
|
+
throw new Error(message);
|
|
319
|
+
}
|
|
320
|
+
return data;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const clearPanelError = () => {
|
|
324
|
+
els.panelError.hidden = true;
|
|
325
|
+
els.panelError.textContent = '';
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const setThumbFallback = (thumbWrap) => {
|
|
329
|
+
thumbWrap.textContent = '';
|
|
330
|
+
const fallback = document.createElement('div');
|
|
331
|
+
fallback.className = 'pack-thumb-fallback';
|
|
332
|
+
fallback.textContent = 'Sem capa disponível';
|
|
333
|
+
thumbWrap.appendChild(fallback);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const shortStickerId = (value) => {
|
|
337
|
+
const normalized = String(value || '').replace(/[^a-zA-Z0-9]/g, '');
|
|
338
|
+
return normalized.slice(0, 5) || '-----';
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const toTagToken = (value) => {
|
|
342
|
+
const normalized = String(value || '')
|
|
343
|
+
.trim()
|
|
344
|
+
.toLowerCase();
|
|
345
|
+
if (!normalized) return '';
|
|
346
|
+
|
|
347
|
+
const mapped = {
|
|
348
|
+
'video game screenshot': 'game',
|
|
349
|
+
'real life photo': 'foto-real',
|
|
350
|
+
'anime illustration': 'anime',
|
|
351
|
+
'nsfw content': 'nsfw',
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
if (mapped[normalized]) return mapped[normalized];
|
|
355
|
+
|
|
356
|
+
return normalized
|
|
357
|
+
.normalize('NFD')
|
|
358
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
359
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
360
|
+
.replace(/^-+|-+$/g, '')
|
|
361
|
+
.slice(0, 18);
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const resolveTopStickerTags = (entity) => {
|
|
365
|
+
const classification = entity?.asset?.classification || entity?.classification || null;
|
|
366
|
+
const explicitTags = Array.isArray(entity?.tags) ? entity.tags : [];
|
|
367
|
+
const classificationTags = Array.isArray(classification?.tags) ? classification.tags : [];
|
|
368
|
+
|
|
369
|
+
const rankedFromScores = Object.entries(classification?.all_scores || {})
|
|
370
|
+
.filter(([, score]) => Number.isFinite(Number(score)))
|
|
371
|
+
.sort((left, right) => Number(right[1]) - Number(left[1]))
|
|
372
|
+
.map(([label]) => toTagToken(label))
|
|
373
|
+
.filter(Boolean);
|
|
374
|
+
|
|
375
|
+
const merged = [...rankedFromScores, ...classificationTags, ...explicitTags].map((tag) => toTagToken(tag)).filter(Boolean);
|
|
376
|
+
|
|
377
|
+
return Array.from(new Set(merged)).slice(0, 3);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const buildStickerTagsOverlay = (entity) => {
|
|
381
|
+
const tags = resolveTopStickerTags(entity);
|
|
382
|
+
if (!tags.length) return null;
|
|
383
|
+
|
|
384
|
+
const overlay = document.createElement('div');
|
|
385
|
+
overlay.className = 'sticker-tags';
|
|
386
|
+
overlay.setAttribute('aria-label', 'Tags da figurinha: ' + tags.join(', '));
|
|
387
|
+
|
|
388
|
+
tags.forEach((tag) => {
|
|
389
|
+
const chip = document.createElement('span');
|
|
390
|
+
chip.className = 'sticker-tag';
|
|
391
|
+
chip.textContent = tag;
|
|
392
|
+
overlay.appendChild(chip);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
return overlay;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const resolveTopPackTags = (pack) => {
|
|
399
|
+
const explicitTags = Array.isArray(pack?.tags) ? pack.tags : [];
|
|
400
|
+
const classificationTags = Array.isArray(pack?.classification?.tags) ? pack.classification.tags : [];
|
|
401
|
+
|
|
402
|
+
const merged = [...classificationTags, ...explicitTags].map((tag) => toTagToken(tag)).filter(Boolean);
|
|
403
|
+
|
|
404
|
+
return Array.from(new Set(merged)).slice(0, 3);
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const buildPackTagsRow = (pack) => {
|
|
408
|
+
const tags = resolveTopPackTags(pack);
|
|
409
|
+
if (!tags.length) return null;
|
|
410
|
+
|
|
411
|
+
const row = document.createElement('div');
|
|
412
|
+
row.className = 'pack-tags';
|
|
413
|
+
row.setAttribute('aria-label', 'Categorias do pack: ' + tags.join(', '));
|
|
414
|
+
|
|
415
|
+
tags.forEach((tag) => {
|
|
416
|
+
const chip = document.createElement('span');
|
|
417
|
+
chip.className = 'pack-tag';
|
|
418
|
+
chip.textContent = tag;
|
|
419
|
+
row.appendChild(chip);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
return row;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const renderCard = (pack) => {
|
|
426
|
+
const col = document.createElement('div');
|
|
427
|
+
col.className = 'col-4 col-sm-6 col-md-4 col-lg-3';
|
|
428
|
+
|
|
429
|
+
const card = document.createElement('button');
|
|
430
|
+
card.type = 'button';
|
|
431
|
+
card.className = 'card h-100 text-start bg-dark text-light shadow-sm pack-card';
|
|
432
|
+
card.setAttribute('aria-label', 'Abrir pack ' + pack.name);
|
|
433
|
+
|
|
434
|
+
const cardBody = document.createElement('div');
|
|
435
|
+
cardBody.className = 'card-body d-flex flex-column gap-2';
|
|
436
|
+
|
|
437
|
+
const thumbWrap = document.createElement('div');
|
|
438
|
+
thumbWrap.className = 'pack-thumb';
|
|
439
|
+
|
|
440
|
+
const visibilityBadge = document.createElement('span');
|
|
441
|
+
visibilityBadge.className = 'pack-visibility-badge';
|
|
442
|
+
const visibility = String(pack.visibility || '').toLowerCase();
|
|
443
|
+
visibilityBadge.textContent = visibility === 'public' ? 'Público' : visibility === 'unlisted' ? 'Não listado' : 'Privado';
|
|
444
|
+
|
|
445
|
+
const countBadge = document.createElement('span');
|
|
446
|
+
countBadge.className = 'pack-count-badge';
|
|
447
|
+
countBadge.textContent = String(Number(pack.sticker_count || 0)) + ' itens';
|
|
448
|
+
|
|
449
|
+
if (pack.cover_url) {
|
|
450
|
+
const image = document.createElement('img');
|
|
451
|
+
image.loading = 'lazy';
|
|
452
|
+
image.alt = 'Capa do pack ' + pack.name;
|
|
453
|
+
image.src = pack.cover_url;
|
|
454
|
+
image.addEventListener('error', () => setThumbFallback(thumbWrap));
|
|
455
|
+
thumbWrap.appendChild(image);
|
|
456
|
+
} else {
|
|
457
|
+
setThumbFallback(thumbWrap);
|
|
458
|
+
}
|
|
459
|
+
thumbWrap.append(visibilityBadge, countBadge);
|
|
460
|
+
|
|
461
|
+
const title = document.createElement('h3');
|
|
462
|
+
title.className = 'card-title h6 mb-0';
|
|
463
|
+
title.textContent = pack.name;
|
|
464
|
+
|
|
465
|
+
const quantity = document.createElement('p');
|
|
466
|
+
quantity.className = 'pack-meta pack-count mb-0';
|
|
467
|
+
quantity.textContent = String(Number(pack.sticker_count || 0)) + ' itens';
|
|
468
|
+
|
|
469
|
+
const author = document.createElement('p');
|
|
470
|
+
author.className = 'pack-meta pack-author mb-0';
|
|
471
|
+
author.textContent = pack.publisher || 'Autor não informado';
|
|
472
|
+
|
|
473
|
+
const tagsRow = buildPackTagsRow(pack);
|
|
474
|
+
cardBody.append(thumbWrap, title, quantity, author);
|
|
475
|
+
if (tagsRow) {
|
|
476
|
+
cardBody.appendChild(tagsRow);
|
|
477
|
+
}
|
|
478
|
+
card.appendChild(cardBody);
|
|
479
|
+
card.addEventListener('click', () => openPack(pack.pack_key, { pushState: true }));
|
|
480
|
+
|
|
481
|
+
col.appendChild(card);
|
|
482
|
+
return col;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
const renderGrid = () => {
|
|
486
|
+
els.grid.innerHTML = '';
|
|
487
|
+
state.packs.items.forEach((pack) => {
|
|
488
|
+
els.grid.appendChild(renderCard(pack));
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const rankPacksByCompleteness = (packs) => {
|
|
493
|
+
if (!Array.isArray(packs)) return [];
|
|
494
|
+
return [...packs].sort((left, right) => {
|
|
495
|
+
const leftCount = Number(left?.sticker_count) || 0;
|
|
496
|
+
const rightCount = Number(right?.sticker_count) || 0;
|
|
497
|
+
const leftHasCover = left?.cover_url ? 1 : 0;
|
|
498
|
+
const rightHasCover = right?.cover_url ? 1 : 0;
|
|
499
|
+
const leftIsComplete = leftCount >= 30 ? 1 : 0;
|
|
500
|
+
const rightIsComplete = rightCount >= 30 ? 1 : 0;
|
|
501
|
+
|
|
502
|
+
if (rightIsComplete !== leftIsComplete) return rightIsComplete - leftIsComplete;
|
|
503
|
+
|
|
504
|
+
if (rightCount !== leftCount) return rightCount - leftCount;
|
|
505
|
+
if (rightHasCover !== leftHasCover) return rightHasCover - leftHasCover;
|
|
506
|
+
return String(left?.name || '').localeCompare(String(right?.name || ''), 'pt-BR');
|
|
507
|
+
});
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
const renderPackSkeletons = (count) => {
|
|
511
|
+
els.grid.innerHTML = '';
|
|
512
|
+
for (let index = 0; index < count; index += 1) {
|
|
513
|
+
const col = document.createElement('div');
|
|
514
|
+
col.className = 'col-4 col-sm-6 col-md-4 col-lg-3';
|
|
515
|
+
col.innerHTML = '<div class="card h-100 bg-dark text-light shadow-sm pack-card">' + '<div class="card-body d-flex flex-column gap-2">' + '<div class="skeleton skeleton-thumb"></div>' + '<div class="skeleton skeleton-line"></div>' + '<div class="skeleton skeleton-line short"></div>' + '</div></div>';
|
|
516
|
+
els.grid.appendChild(col);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
const renderOrphanSticker = (sticker) => {
|
|
521
|
+
const col = document.createElement('div');
|
|
522
|
+
col.className = 'col-6 col-md-3 col-lg-2';
|
|
523
|
+
|
|
524
|
+
const wrapper = document.createElement('article');
|
|
525
|
+
wrapper.className = 'orphan-card card h-100';
|
|
526
|
+
|
|
527
|
+
const body = document.createElement('div');
|
|
528
|
+
body.className = 'card-body p-2';
|
|
529
|
+
|
|
530
|
+
if (sticker.url) {
|
|
531
|
+
const image = document.createElement('img');
|
|
532
|
+
image.loading = 'lazy';
|
|
533
|
+
image.alt = 'Sticker sem pack ' + sticker.id;
|
|
534
|
+
image.src = sticker.url;
|
|
535
|
+
body.appendChild(image);
|
|
536
|
+
} else {
|
|
537
|
+
const fallback = document.createElement('div');
|
|
538
|
+
fallback.className = 'pack-thumb-fallback';
|
|
539
|
+
fallback.textContent = 'Arquivo não acessível';
|
|
540
|
+
body.appendChild(fallback);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const tagsOverlay = buildStickerTagsOverlay(sticker);
|
|
544
|
+
if (tagsOverlay) body.appendChild(tagsOverlay);
|
|
545
|
+
|
|
546
|
+
const meta = document.createElement('p');
|
|
547
|
+
meta.className = 'orphan-meta mb-0 mt-2';
|
|
548
|
+
meta.textContent = 'ID: ' + shortStickerId(sticker.id);
|
|
549
|
+
meta.title = sticker.id || '';
|
|
550
|
+
body.appendChild(meta);
|
|
551
|
+
|
|
552
|
+
wrapper.appendChild(body);
|
|
553
|
+
col.appendChild(wrapper);
|
|
554
|
+
return col;
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const renderOrphanGrid = () => {
|
|
558
|
+
els.orphanGrid.innerHTML = '';
|
|
559
|
+
state.orphan.items.forEach((sticker) => {
|
|
560
|
+
els.orphanGrid.appendChild(renderOrphanSticker(sticker));
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
const renderPackPage = (pack) => {
|
|
565
|
+
const items = Array.isArray(pack?.items) ? pack.items : [];
|
|
566
|
+
state.selectedPack = pack || null;
|
|
567
|
+
|
|
568
|
+
els.packPageTitle.textContent = pack?.name || 'Pack';
|
|
569
|
+
els.packPageSub.textContent = (pack?.publisher || '-') + ' | ' + (pack?.description || 'Sem descrição');
|
|
570
|
+
els.packPageChip.textContent = String(pack?.sticker_count || items.length || 0) + ' itens | ' + (pack?.visibility || '-') + ' | ' + (pack?.pack_key || '-');
|
|
571
|
+
applyWhatsAppLink(els.packPageWhatsApp, pack?.whatsapp?.url);
|
|
572
|
+
|
|
573
|
+
els.packPageGrid.innerHTML = '';
|
|
574
|
+
if (!items.length) {
|
|
575
|
+
els.packPageStatus.textContent = 'Este pack não possui stickers disponíveis.';
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
els.packPageStatus.textContent = 'Exibindo ' + items.length + ' sticker(s).';
|
|
580
|
+
items.forEach((item) => {
|
|
581
|
+
const col = document.createElement('div');
|
|
582
|
+
col.className = 'col-6 col-sm-4 col-md-3 col-lg-2';
|
|
583
|
+
|
|
584
|
+
const wrapper = document.createElement('div');
|
|
585
|
+
wrapper.className = 'sticker-tile';
|
|
586
|
+
|
|
587
|
+
const image = document.createElement('img');
|
|
588
|
+
image.loading = 'lazy';
|
|
589
|
+
image.alt = item.accessibility_label || 'Sticker #' + item.position;
|
|
590
|
+
image.src = item.asset_url;
|
|
591
|
+
|
|
592
|
+
wrapper.appendChild(image);
|
|
593
|
+
const tagsOverlay = buildStickerTagsOverlay(item);
|
|
594
|
+
if (tagsOverlay) wrapper.appendChild(tagsOverlay);
|
|
595
|
+
col.appendChild(wrapper);
|
|
596
|
+
els.packPageGrid.appendChild(col);
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
const renderOrphanSkeletons = (count) => {
|
|
601
|
+
els.orphanGrid.innerHTML = '';
|
|
602
|
+
for (let index = 0; index < count; index += 1) {
|
|
603
|
+
const col = document.createElement('div');
|
|
604
|
+
col.className = 'col-6 col-md-3 col-lg-2';
|
|
605
|
+
col.innerHTML = '<article class="orphan-card card h-100"><div class="card-body p-2">' + '<div class="skeleton skeleton-orphan"></div>' + '<div class="skeleton skeleton-line short mt-2"></div>' + '</div></article>';
|
|
606
|
+
els.orphanGrid.appendChild(col);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
const updateMoreButton = () => {
|
|
611
|
+
els.more.hidden = !state.packs.hasMore;
|
|
612
|
+
els.more.disabled = state.packs.loading;
|
|
613
|
+
els.more.textContent = state.packs.loading ? 'Carregando...' : 'Carregar mais';
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
const updateOrphanPaginationControls = () => {
|
|
617
|
+
const totalPages = Math.max(1, Number(state.orphan.totalPages) || 1);
|
|
618
|
+
const totalItems = Math.max(0, Number(state.orphan.totalItems) || 0);
|
|
619
|
+
const page = Math.max(1, Math.min(totalPages, Number(state.orphan.page) || 1));
|
|
620
|
+
state.orphan.page = page;
|
|
621
|
+
|
|
622
|
+
els.orphanPrev.disabled = page <= 1 || state.orphan.loading;
|
|
623
|
+
els.orphanNext.disabled = page >= totalPages || state.orphan.loading;
|
|
624
|
+
els.orphanPageInfo.textContent = 'Página ' + page + ' de ' + totalPages + ' - ' + totalItems + ' figurinhas';
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
const listPacks = async ({ reset = false } = {}) => {
|
|
628
|
+
if (state.packs.loading) return;
|
|
629
|
+
state.packs.loading = true;
|
|
630
|
+
updateMoreButton();
|
|
631
|
+
setStatus(reset ? 'Buscando packs...' : 'Carregando mais packs...');
|
|
632
|
+
if (reset) renderPackSkeletons(Math.min(state.packs.limit, 12));
|
|
633
|
+
|
|
634
|
+
if (reset) {
|
|
635
|
+
state.packs.offset = 0;
|
|
636
|
+
state.packs.items = [];
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
try {
|
|
640
|
+
const payload = await fetchJson(
|
|
641
|
+
toApi(CONFIG.apiBasePath, {
|
|
642
|
+
q: state.q,
|
|
643
|
+
visibility: state.visibility,
|
|
644
|
+
categories: state.categories.join(','),
|
|
645
|
+
limit: state.packs.limit,
|
|
646
|
+
offset: state.packs.offset,
|
|
647
|
+
}),
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
const packs = Array.isArray(payload.data) ? payload.data : [];
|
|
651
|
+
state.packs.items = reset ? packs : state.packs.items.concat(packs);
|
|
652
|
+
state.packs.items = rankPacksByCompleteness(state.packs.items);
|
|
653
|
+
state.packs.offset = (payload.pagination && payload.pagination.next_offset) || state.packs.items.length;
|
|
654
|
+
state.packs.hasMore = Boolean(payload.pagination && payload.pagination.has_more);
|
|
655
|
+
|
|
656
|
+
renderGrid();
|
|
657
|
+
|
|
658
|
+
if (!state.packs.items.length) {
|
|
659
|
+
setStatus('Nenhum pack encontrado com os filtros atuais.');
|
|
660
|
+
} else {
|
|
661
|
+
setStatus(state.packs.items.length + ' pack(s) carregado(s).');
|
|
662
|
+
}
|
|
663
|
+
} catch (error) {
|
|
664
|
+
setStatus(error.message || 'Não foi possível listar os packs agora.');
|
|
665
|
+
} finally {
|
|
666
|
+
state.packs.loading = false;
|
|
667
|
+
updateMoreButton();
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
const listOrphanStickers = async ({ reset = false } = {}) => {
|
|
672
|
+
if (state.orphan.loading) return;
|
|
673
|
+
state.orphan.loading = true;
|
|
674
|
+
updateOrphanPaginationControls();
|
|
675
|
+
setOrphanStatus('Buscando figurinhas sem pack...');
|
|
676
|
+
if (reset) renderOrphanSkeletons(Math.min(state.orphan.limit, 12));
|
|
677
|
+
|
|
678
|
+
if (reset) {
|
|
679
|
+
state.orphan.page = 1;
|
|
680
|
+
state.orphan.items = [];
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
try {
|
|
684
|
+
const currentPage = Math.max(1, Number(state.orphan.page) || 1);
|
|
685
|
+
const currentLimit = Math.max(1, Number(state.orphan.limit) || 1);
|
|
686
|
+
const offset = (currentPage - 1) * currentLimit;
|
|
687
|
+
|
|
688
|
+
const payload = await fetchJson(
|
|
689
|
+
toApi(CONFIG.orphanApiPath, {
|
|
690
|
+
q: state.q,
|
|
691
|
+
categories: state.categories.join(','),
|
|
692
|
+
limit: currentLimit,
|
|
693
|
+
offset,
|
|
694
|
+
}),
|
|
695
|
+
);
|
|
696
|
+
|
|
697
|
+
const stickers = Array.isArray(payload.data) ? payload.data : [];
|
|
698
|
+
const totalItems = Math.max(0, Number(payload?.pagination?.total || 0));
|
|
699
|
+
const totalPages = Math.max(1, Number(payload?.pagination?.total_pages || Math.ceil(totalItems / currentLimit) || 1));
|
|
700
|
+
|
|
701
|
+
state.orphan.items = stickers;
|
|
702
|
+
state.orphan.totalItems = totalItems;
|
|
703
|
+
state.orphan.totalPages = totalPages;
|
|
704
|
+
state.orphan.page = Math.max(1, Math.min(totalPages, currentPage));
|
|
705
|
+
|
|
706
|
+
renderOrphanGrid();
|
|
707
|
+
|
|
708
|
+
if (!state.orphan.items.length) {
|
|
709
|
+
setOrphanStatus('Nenhuma figurinha sem pack encontrada.');
|
|
710
|
+
} else {
|
|
711
|
+
const from = offset + 1;
|
|
712
|
+
const to = offset + state.orphan.items.length;
|
|
713
|
+
setOrphanStatus('Mostrando ' + from + '-' + to + ' de ' + state.orphan.totalItems + ' figurinha(s) sem pack.');
|
|
714
|
+
}
|
|
715
|
+
} catch (error) {
|
|
716
|
+
setOrphanStatus(error.message || 'Não foi possível listar figurinhas sem pack.');
|
|
717
|
+
} finally {
|
|
718
|
+
state.orphan.loading = false;
|
|
719
|
+
updateOrphanPaginationControls();
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
const updatePanelPaginationControls = (totalItems) => {
|
|
724
|
+
const safeTotal = Math.max(0, Number(totalItems) || 0);
|
|
725
|
+
const totalPages = Math.max(1, Math.ceil(safeTotal / state.panelPagination.perPage));
|
|
726
|
+
state.panelPagination.totalPages = totalPages;
|
|
727
|
+
|
|
728
|
+
if (state.panelPagination.page > totalPages) {
|
|
729
|
+
state.panelPagination.page = totalPages;
|
|
730
|
+
}
|
|
731
|
+
if (state.panelPagination.page < 1) {
|
|
732
|
+
state.panelPagination.page = 1;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
els.panelPrev.disabled = state.panelPagination.page <= 1;
|
|
736
|
+
els.panelNext.disabled = state.panelPagination.page >= totalPages;
|
|
737
|
+
els.panelPageInfo.textContent = 'Página ' + state.panelPagination.page + ' de ' + totalPages + ' - ' + safeTotal + ' stickers';
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
const renderPanelStickersPage = () => {
|
|
741
|
+
const pack = state.selectedPack;
|
|
742
|
+
const items = Array.isArray(pack?.items) ? pack.items : [];
|
|
743
|
+
const perPage = state.panelPagination.perPage;
|
|
744
|
+
|
|
745
|
+
updatePanelPaginationControls(items.length);
|
|
746
|
+
|
|
747
|
+
const start = (state.panelPagination.page - 1) * perPage;
|
|
748
|
+
const end = start + perPage;
|
|
749
|
+
const pageItems = items.slice(start, end);
|
|
750
|
+
|
|
751
|
+
els.stickers.innerHTML = '';
|
|
752
|
+
|
|
753
|
+
if (!items.length) {
|
|
754
|
+
const empty = document.createElement('p');
|
|
755
|
+
empty.className = 'text-secondary mb-0';
|
|
756
|
+
empty.textContent = 'Este pack não possui stickers disponíveis.';
|
|
757
|
+
els.stickers.appendChild(empty);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
pageItems.forEach((item) => {
|
|
762
|
+
const col = document.createElement('div');
|
|
763
|
+
col.className = 'col-6 col-sm-4 col-md-3 col-lg-2';
|
|
764
|
+
|
|
765
|
+
const wrapper = document.createElement('div');
|
|
766
|
+
wrapper.className = 'sticker-tile';
|
|
767
|
+
|
|
768
|
+
const image = document.createElement('img');
|
|
769
|
+
image.loading = 'lazy';
|
|
770
|
+
image.alt = item.accessibility_label || 'Sticker #' + item.position;
|
|
771
|
+
image.src = item.asset_url;
|
|
772
|
+
|
|
773
|
+
wrapper.appendChild(image);
|
|
774
|
+
const tagsOverlay = buildStickerTagsOverlay(item);
|
|
775
|
+
if (tagsOverlay) wrapper.appendChild(tagsOverlay);
|
|
776
|
+
col.appendChild(wrapper);
|
|
777
|
+
els.stickers.appendChild(col);
|
|
778
|
+
});
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
const resetPanel = () => {
|
|
782
|
+
state.selectedPack = null;
|
|
783
|
+
state.panelPagination.page = 1;
|
|
784
|
+
state.panelPagination.totalPages = 1;
|
|
785
|
+
els.panelTitle.textContent = 'Pack';
|
|
786
|
+
els.panelSub.textContent = '';
|
|
787
|
+
els.panelChip.textContent = '';
|
|
788
|
+
els.stickers.innerHTML = '';
|
|
789
|
+
els.panelPageInfo.textContent = 'Página 1 de 1 - 0 stickers';
|
|
790
|
+
els.panelPrev.disabled = true;
|
|
791
|
+
els.panelNext.disabled = true;
|
|
792
|
+
clearPanelError();
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
const closePanel = ({ replaceState = false } = {}) => {
|
|
796
|
+
shouldReplaceStateOnHide = replaceState;
|
|
797
|
+
if (panelModal) {
|
|
798
|
+
panelModal.hide();
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
els.panel.classList.remove('show');
|
|
803
|
+
els.panel.style.display = 'none';
|
|
804
|
+
els.panel.setAttribute('aria-hidden', 'true');
|
|
805
|
+
resetPanel();
|
|
806
|
+
if (replaceState) {
|
|
807
|
+
history.replaceState({}, '', CONFIG.webPath);
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const openPack = async (packKey, { pushState = false } = {}) => {
|
|
812
|
+
const sanitizedKey = String(packKey || '').trim();
|
|
813
|
+
if (!sanitizedKey) return;
|
|
814
|
+
showPackPageView();
|
|
815
|
+
els.packPageTitle.textContent = 'Carregando...';
|
|
816
|
+
els.packPageSub.textContent = '';
|
|
817
|
+
els.packPageChip.textContent = '';
|
|
818
|
+
els.packPageGrid.innerHTML = '';
|
|
819
|
+
els.packPageStatus.textContent = 'Buscando informações do pack...';
|
|
820
|
+
applyWhatsAppLink(els.packPageWhatsApp, '');
|
|
821
|
+
applyWhatsAppLink(els.useWhatsAppLink, '');
|
|
822
|
+
|
|
823
|
+
try {
|
|
824
|
+
const payload = await fetchJson(
|
|
825
|
+
toApi(CONFIG.apiBasePath + '/' + encodeURIComponent(sanitizedKey), {
|
|
826
|
+
categories: state.categories.join(','),
|
|
827
|
+
}),
|
|
828
|
+
);
|
|
829
|
+
state.selectedPack = payload.data || null;
|
|
830
|
+
if (!state.selectedPack) {
|
|
831
|
+
throw new Error('Pack não encontrado.');
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
renderPackPage(state.selectedPack);
|
|
835
|
+
if (pushState) {
|
|
836
|
+
history.pushState({}, '', CONFIG.webPath + '/' + encodeURIComponent(sanitizedKey));
|
|
837
|
+
}
|
|
838
|
+
} catch (error) {
|
|
839
|
+
els.packPageStatus.textContent = error.message || 'Não foi possível abrir este pack.';
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
els.form.addEventListener('submit', async (event) => {
|
|
844
|
+
event.preventDefault();
|
|
845
|
+
await applyFilters();
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
els.more.addEventListener('click', async () => {
|
|
849
|
+
await listPacks({ reset: false });
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
els.orphanPrev.addEventListener('click', async () => {
|
|
853
|
+
if (state.orphan.page <= 1) return;
|
|
854
|
+
state.orphan.page -= 1;
|
|
855
|
+
await listOrphanStickers();
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
els.orphanNext.addEventListener('click', async () => {
|
|
859
|
+
if (state.orphan.page >= state.orphan.totalPages) return;
|
|
860
|
+
state.orphan.page += 1;
|
|
861
|
+
await listOrphanStickers();
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
els.panelPrev.addEventListener('click', () => {
|
|
865
|
+
if (state.panelPagination.page <= 1) return;
|
|
866
|
+
state.panelPagination.page -= 1;
|
|
867
|
+
renderPanelStickersPage();
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
els.panelNext.addEventListener('click', () => {
|
|
871
|
+
if (state.panelPagination.page >= state.panelPagination.totalPages) return;
|
|
872
|
+
state.panelPagination.page += 1;
|
|
873
|
+
renderPanelStickersPage();
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
els.panelClose.addEventListener('click', () => {
|
|
877
|
+
closePanel({ replaceState: true });
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
els.copy.addEventListener('click', async () => {
|
|
881
|
+
if (!state.selectedPack) return;
|
|
882
|
+
|
|
883
|
+
const url = window.location.origin + CONFIG.webPath + '/' + encodeURIComponent(state.selectedPack.pack_key);
|
|
884
|
+
try {
|
|
885
|
+
await navigator.clipboard.writeText(url);
|
|
886
|
+
els.copy.textContent = 'Link copiado';
|
|
887
|
+
setTimeout(() => {
|
|
888
|
+
els.copy.textContent = 'Copiar link do pack';
|
|
889
|
+
}, 1800);
|
|
890
|
+
} catch {
|
|
891
|
+
els.copy.textContent = 'Falha ao copiar';
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
els.packPageCopy.addEventListener('click', async () => {
|
|
896
|
+
if (!state.selectedPack) return;
|
|
897
|
+
const url = window.location.origin + CONFIG.webPath + '/' + encodeURIComponent(state.selectedPack.pack_key);
|
|
898
|
+
try {
|
|
899
|
+
await navigator.clipboard.writeText(url);
|
|
900
|
+
els.packPageCopy.textContent = 'Link copiado';
|
|
901
|
+
setTimeout(() => {
|
|
902
|
+
els.packPageCopy.textContent = 'Copiar link do pack';
|
|
903
|
+
}, 1800);
|
|
904
|
+
} catch {
|
|
905
|
+
els.packPageCopy.textContent = 'Falha ao copiar';
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
els.packPageBack.addEventListener('click', async () => {
|
|
910
|
+
history.pushState({}, '', CONFIG.webPath);
|
|
911
|
+
showCatalogView();
|
|
912
|
+
if (!state.catalogLoaded) {
|
|
913
|
+
await Promise.all([listPacks({ reset: true }), listOrphanStickers({ reset: true })]);
|
|
914
|
+
state.catalogLoaded = true;
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
if (panelModal) {
|
|
919
|
+
els.panel.addEventListener('hidden.bs.modal', () => {
|
|
920
|
+
resetPanel();
|
|
921
|
+
|
|
922
|
+
if (shouldReplaceStateOnHide || window.location.pathname.startsWith(CONFIG.webPath + '/')) {
|
|
923
|
+
history.replaceState({}, '', CONFIG.webPath);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
shouldReplaceStateOnHide = false;
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
window.addEventListener('popstate', () => {
|
|
931
|
+
const key = extractPackKeyFromPath();
|
|
932
|
+
if (!key) {
|
|
933
|
+
showCatalogView();
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
openPack(key, { pushState: false });
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
(async () => {
|
|
940
|
+
const pathPackKey = extractPackKeyFromPath();
|
|
941
|
+
const initialPackKey = pathPackKey || CONFIG.initialPackKey;
|
|
942
|
+
if (initialPackKey) {
|
|
943
|
+
await openPack(initialPackKey, { pushState: false });
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
showCatalogView();
|
|
947
|
+
await Promise.all([listPacks({ reset: true }), listOrphanStickers({ reset: true })]);
|
|
948
|
+
state.catalogLoaded = true;
|
|
949
|
+
})();
|
|
950
|
+
})();
|