remove webpack
This commit is contained in:
@@ -2,7 +2,6 @@ import { App } from '@kevisual/router';
|
||||
import { useConfig } from '@abearxiong/use-config';
|
||||
import { dynamicImport } from './lib/dynamic-import.ts';
|
||||
import { redisPublisher, redisSubscriber, redis } from './modules/redis.ts';
|
||||
import { neode, getSession } from './modules/neo4j.ts';
|
||||
import { minioClient } from './modules/minio.ts';
|
||||
import { sequelize } from './modules/sequelize.ts';
|
||||
|
||||
@@ -10,7 +9,7 @@ useConfig();
|
||||
export const emit = (channel: string, message?: any) => {
|
||||
redisPublisher.publish(channel, JSON.stringify(message));
|
||||
};
|
||||
export { neode, getSession, redis, minioClient, sequelize };
|
||||
export { redis, minioClient, sequelize };
|
||||
|
||||
export const app = new App<{ import: any; emit: typeof emit; sequelize: typeof sequelize }>({
|
||||
serverOptions: {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import path, { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
export const getRequire = () => {
|
||||
return eval('require') as NodeRequire;
|
||||
};
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
@@ -22,14 +19,15 @@ export const defaultImportModules = [
|
||||
export const dynamicImport = async (name: string) => {
|
||||
// const nodeModules = path.resolve(directoryPath, 'node_modules');
|
||||
// const nodeName = path.resolve(nodeModules, name);
|
||||
const require = getRequire();
|
||||
console.log(`Dynamic import module ${name}`);
|
||||
try {
|
||||
const nodeCache = require.cache[require.resolve(name)];
|
||||
if (nodeCache) {
|
||||
console.log(`${name} is cached`);
|
||||
}
|
||||
return require(name);
|
||||
return await import(name);
|
||||
// const require = getRequire();
|
||||
// const nodeCache = require.cache[require.resolve(name)];
|
||||
// if (nodeCache) {
|
||||
// console.log(`${name} is cached`);
|
||||
// }
|
||||
// return require(name);
|
||||
} catch (e) {
|
||||
console.error(`Failed to import module ${name}: ${e.message}`);
|
||||
throw `Failed to import module ${name}: ${e.message}`;
|
||||
|
||||
@@ -2,6 +2,11 @@ import { exec } from 'child_process';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
import { fileURLToPath } from 'url'
|
||||
import { dirname } from 'path'
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
export const directoryPath = path.resolve(__dirname);
|
||||
const packagePath = path.resolve(directoryPath, 'package.json');
|
||||
const exists = (filePath: string) => {
|
||||
|
||||
@@ -16,6 +16,7 @@ const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
||||
// -F "description=This is a test upload" \
|
||||
// -F "username=testuser"
|
||||
|
||||
let clients = [];
|
||||
export const uploadMiddleware = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
if (req.method === 'GET' && req.url === '/api/app/upload') {
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
@@ -104,8 +105,19 @@ export const uploadMiddleware = async (req: http.IncomingMessage, res: http.Serv
|
||||
allowEmptyFiles: true, // 允许空
|
||||
minFileSize: 0, // 最小文件大小
|
||||
createDirsFromUploads: false, // 根据上传的文件夹结构创建目录
|
||||
keepExtensions: true, // 保留文件
|
||||
hashAlgorithm: 'md5', // 文件哈希算法
|
||||
});
|
||||
form.on('progress', (bytesReceived, bytesExpected) => {
|
||||
const progress = (bytesReceived / bytesExpected) * 100;
|
||||
console.log(`Upload progress: ${progress.toFixed(2)}%`);
|
||||
const data = {
|
||||
progress: progress.toFixed(2),
|
||||
message: `Upload progress: ${progress.toFixed(2)}%`,
|
||||
};
|
||||
// 向所有连接的客户端推送进度信息
|
||||
clients.forEach((client) => client.write(`${JSON.stringify(data)}\n`));
|
||||
});
|
||||
|
||||
// 解析上传的文件
|
||||
form.parse(req, async (err, fields, files) => {
|
||||
if (err) {
|
||||
@@ -192,4 +204,17 @@ export const uploadMiddleware = async (req: http.IncomingMessage, res: http.Serv
|
||||
res.end(JSON.stringify(data));
|
||||
});
|
||||
}
|
||||
if (req.url === '/api/events') {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
Connection: 'keep-alive',
|
||||
});
|
||||
clients.push(res);
|
||||
|
||||
// 移除客户端连接
|
||||
req.on('close', () => {
|
||||
clients = clients.filter((client) => client !== res);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
import * as glob from 'glob';
|
||||
import * as path from 'path';
|
||||
import path from 'path'
|
||||
import * as glob from 'glob'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { dirname } from 'path'
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
const files = glob.sync(path.resolve(__dirname, './apps/**/index.cjs'));
|
||||
const files = glob.sync(path.resolve(__dirname, './apps/**/index.mjs'))
|
||||
|
||||
export const loadApps = async (app: any) => {
|
||||
const directory = files.map((file: string) => {
|
||||
const dirname = path.dirname(file)
|
||||
const lastDirectory = path.basename(dirname)
|
||||
return lastDirectory
|
||||
})
|
||||
console.log('directory', directory)
|
||||
for (const file of files) {
|
||||
const module = __non_webpack_require__(file);
|
||||
if (module.render) {
|
||||
module.render(app);
|
||||
try {
|
||||
const module = await import(file)
|
||||
|
||||
if (module.render) {
|
||||
module.render(app)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { neode } from '@/app.ts';
|
||||
import { neode } from '@/modules/neo4j.ts';
|
||||
import { getSession } from '@/modules/neo4j.ts';
|
||||
import Neode from 'neode';
|
||||
|
||||
|
||||
12
src/modules/bullmq.ts
Normal file
12
src/modules/bullmq.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Queue } from 'bullmq';
|
||||
import { useConfig } from '@abearxiong/use-config';
|
||||
const config = useConfig();
|
||||
|
||||
export const connection = {
|
||||
host: config.redis?.host || 'localhost',
|
||||
port: config.redis?.port || 6379,
|
||||
};
|
||||
|
||||
export const quene = new Queue('test', {
|
||||
connection: connection,
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import './page/index.ts';
|
||||
|
||||
import './resource/index.ts';
|
||||
|
||||
import './prompt-graph/index.ts';
|
||||
// import './prompt-graph/index.ts';
|
||||
|
||||
import './agent/index.ts';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user