fix(plugins): resolve UnifiedStorageProvider and ext-api imports dynamically for production dist
This commit is contained in:
@@ -9,8 +9,14 @@ import {
|
||||
} from '@aws-sdk/client-s3';
|
||||
import { Upload } from '@aws-sdk/lib-storage';
|
||||
import { PluginInstance, PluginContext } from '../../backend/src/core/types';
|
||||
import { storageProvider, StorageUploadPayload, StorageProviderInterface } from '../../backend/src/core/StorageProvider';
|
||||
import { pluginConfig } from '../../backend/src/core/plugin-config';
|
||||
import type { StorageUploadPayload, StorageProviderInterface } from '../../backend/src/core/StorageProvider';
|
||||
|
||||
let storageProvider: any;
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
storageProvider = require('../../dist/core/StorageProvider').storageProvider;
|
||||
} else {
|
||||
storageProvider = require('../../backend/src/core/StorageProvider').storageProvider;
|
||||
}
|
||||
import sharp from 'sharp';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -39,7 +45,7 @@ class UnifiedStorageProviderPlugin implements PluginInstance, StorageProviderInt
|
||||
|
||||
async activate(ctx: PluginContext): Promise<void> {
|
||||
this.ctx = ctx;
|
||||
const cfg = pluginConfig.get('UnifiedStorageProvider') || {};
|
||||
const cfg = ctx.config.get('UnifiedStorageProvider') || {};
|
||||
|
||||
if (!fs.existsSync(this.localFallbackDir)) {
|
||||
fs.mkdirSync(this.localFallbackDir, { recursive: true });
|
||||
|
||||
@@ -22,9 +22,19 @@ import type { Knex } from 'knex'
|
||||
import type { WhatsAppConnectionManager } from '../../../backend/src/modules/whatsapp/connection/WhatsAppConnectionManager'
|
||||
import type { PluginConfigStore } from '../../../backend/src/core/plugin-config'
|
||||
import type { HookBus } from '../../../backend/src/core/hook-bus'
|
||||
import { dragonfly } from '../../../backend/src/infra/cache/dragonfly'
|
||||
let dragonfly: any;
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
dragonfly = require('../../../dist/infra/cache/dragonfly').dragonfly;
|
||||
} else {
|
||||
dragonfly = require('../../../backend/src/infra/cache/dragonfly').dragonfly;
|
||||
}
|
||||
import { ProtocolEngine } from '../../secretaria/brain'
|
||||
import { sendRichMessage } from '../../../backend/dist/modules/whatsapp/rich-message'
|
||||
let sendRichMessage: any;
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
sendRichMessage = require('../../../dist/modules/whatsapp/rich-message').sendRichMessage;
|
||||
} else {
|
||||
sendRichMessage = require('../../../backend/dist/modules/whatsapp/rich-message').sendRichMessage;
|
||||
}
|
||||
|
||||
function uuid(): string {
|
||||
try { return (crypto as any).randomUUID() } catch { return `${Date.now()}-${Math.random().toString(36).slice(2)}` }
|
||||
|
||||
Reference in New Issue
Block a user