fix(plugins): resolve leads and nanobana runtime imports dynamically for production dist compatibility
This commit is contained in:
@@ -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'];
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user