From 201594b5a19d7d5cf3518419314f670015ec64ad Mon Sep 17 00:00:00 2001 From: VPS 4 Deploy Agent Date: Mon, 11 May 2026 05:28:55 +0200 Subject: [PATCH] fix(plugins): resolve leads and nanobana runtime imports dynamically for production dist compatibility --- .../newwhats.local/plugins/leads/backend/routes.ts | 13 +++++++++++-- .../plugins/nanobana/backend/routes.ts | 9 ++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/clube67/newwhats.local/plugins/leads/backend/routes.ts b/clube67/newwhats.local/plugins/leads/backend/routes.ts index 2d6a54f..a248d8a 100644 --- a/clube67/newwhats.local/plugins/leads/backend/routes.ts +++ b/clube67/newwhats.local/plugins/leads/backend/routes.ts @@ -1,7 +1,16 @@ import { Router, Request, Response } from 'express'; import { PluginContext } from '../../../backend/src/core/types'; -import { authenticate } from '../../../backend/src/middleware/auth'; -import { authorize } from '../../../backend/src/middleware/rbac'; + +let authenticate: any; +let authorize: any; + +if (process.env.NODE_ENV === 'production') { + authenticate = require('../../../dist/middleware/auth').authMiddleware; + authorize = require('../../../dist/middleware/rbac').adminMiddleware; +} else { + authenticate = require('../../../backend/src/middleware/auth').authMiddleware; + authorize = require('../../../backend/src/middleware/rbac').adminMiddleware; +} const STATUS_VALUES = ['new', 'contacted', 'qualified', 'converted', 'lost']; const LEAD_TYPE_VALUES = ['cold', 'member']; diff --git a/clube67/newwhats.local/plugins/nanobana/backend/routes.ts b/clube67/newwhats.local/plugins/nanobana/backend/routes.ts index ec2d600..24a3f79 100644 --- a/clube67/newwhats.local/plugins/nanobana/backend/routes.ts +++ b/clube67/newwhats.local/plugins/nanobana/backend/routes.ts @@ -1,16 +1,15 @@ import { Router } from 'express'; import { PluginContext } from '../../../backend/src/core/types'; -import { pluginConfig } from '../../../backend/src/core/plugin-config'; import OpenAI from 'openai'; import fs from 'fs'; import path from 'path'; import https from 'https'; import { v4 as uuidv4 } from 'uuid'; -import { config } from '../../../backend/src/config'; export function createRoutes(ctx: PluginContext): Router { const router = Router(); + const uploadDir = process.env.UPLOAD_DIR || path.join(process.cwd(), 'uploads'); router.get('/', (req, res) => { res.json({ @@ -48,7 +47,7 @@ export function createRoutes(ctx: PluginContext): Router { } // Get Config - const nanobanaConfig = pluginConfig.get('nanobana'); + const nanobanaConfig = ctx.config.get('nanobana'); const apiKey = nanobanaConfig?.apiKey; if (!apiKey) { @@ -67,7 +66,7 @@ export function createRoutes(ctx: PluginContext): Router { // Resolve local path if (refUrl.includes('/uploads/')) { const filename = path.basename(refUrl); - imagePath = path.join(config.upload.dir, filename); + imagePath = path.join(uploadDir, filename); } if (imagePath && fs.existsSync(imagePath)) { @@ -133,7 +132,7 @@ export function createRoutes(ctx: PluginContext): Router { // Download Image to Local Storage const ext = '.png'; // DALL-E 3 usually png const filename = `${uuidv4()}${ext}`; - const localPath = path.join(config.upload.dir, filename); + const localPath = path.join(uploadDir, filename); const publicUrl = `/uploads/${filename}`; const file = fs.createWriteStream(localPath);