fix(plugins): resolve leads and nanobana runtime imports dynamically for production dist compatibility

This commit is contained in:
VPS 4 Deploy Agent
2026-05-11 05:28:55 +02:00
parent f95ac82558
commit 201594b5a1
2 changed files with 15 additions and 7 deletions
@@ -1,7 +1,16 @@
import { Router, Request, Response } from 'express'; import { Router, Request, Response } from 'express';
import { PluginContext } from '../../../backend/src/core/types'; 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 STATUS_VALUES = ['new', 'contacted', 'qualified', 'converted', 'lost'];
const LEAD_TYPE_VALUES = ['cold', 'member']; const LEAD_TYPE_VALUES = ['cold', 'member'];
@@ -1,16 +1,15 @@
import { Router } from 'express'; import { Router } from 'express';
import { PluginContext } from '../../../backend/src/core/types'; import { PluginContext } from '../../../backend/src/core/types';
import { pluginConfig } from '../../../backend/src/core/plugin-config';
import OpenAI from 'openai'; import OpenAI from 'openai';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import https from 'https'; import https from 'https';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { config } from '../../../backend/src/config';
export function createRoutes(ctx: PluginContext): Router { export function createRoutes(ctx: PluginContext): Router {
const router = Router(); const router = Router();
const uploadDir = process.env.UPLOAD_DIR || path.join(process.cwd(), 'uploads');
router.get('/', (req, res) => { router.get('/', (req, res) => {
res.json({ res.json({
@@ -48,7 +47,7 @@ export function createRoutes(ctx: PluginContext): Router {
} }
// Get Config // Get Config
const nanobanaConfig = pluginConfig.get('nanobana'); const nanobanaConfig = ctx.config.get('nanobana');
const apiKey = nanobanaConfig?.apiKey; const apiKey = nanobanaConfig?.apiKey;
if (!apiKey) { if (!apiKey) {
@@ -67,7 +66,7 @@ export function createRoutes(ctx: PluginContext): Router {
// Resolve local path // Resolve local path
if (refUrl.includes('/uploads/')) { if (refUrl.includes('/uploads/')) {
const filename = path.basename(refUrl); const filename = path.basename(refUrl);
imagePath = path.join(config.upload.dir, filename); imagePath = path.join(uploadDir, filename);
} }
if (imagePath && fs.existsSync(imagePath)) { if (imagePath && fs.existsSync(imagePath)) {
@@ -133,7 +132,7 @@ export function createRoutes(ctx: PluginContext): Router {
// Download Image to Local Storage // Download Image to Local Storage
const ext = '.png'; // DALL-E 3 usually png const ext = '.png'; // DALL-E 3 usually png
const filename = `${uuidv4()}${ext}`; const filename = `${uuidv4()}${ext}`;
const localPath = path.join(config.upload.dir, filename); const localPath = path.join(uploadDir, filename);
const publicUrl = `/uploads/${filename}`; const publicUrl = `/uploads/${filename}`;
const file = fs.createWriteStream(localPath); const file = fs.createWriteStream(localPath);