Skip to content

Commit 28c618d

Browse files
committed
修复安全漏洞和构建问题:添加依赖overrides,修复PPTDatabase懒加载,解决CI/CD构建失败
1 parent 49cd11c commit 28c618d

4 files changed

Lines changed: 47 additions & 755 deletions

File tree

lib/ppt-db.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ export interface PPTChatMessage {
8080
}
8181

8282
export class PPTDatabase {
83-
private pool = getPool();
83+
private _pool: any = null;
84+
85+
private get pool() {
86+
if (!this._pool) {
87+
this._pool = getPool();
88+
}
89+
return this._pool;
90+
}
8491

8592
// 创建PPT项目
8693
async createProject(data: {
@@ -916,4 +923,25 @@ export class PPTDatabase {
916923
}
917924

918925
// 导出单例实例
919-
export const pptDb = new PPTDatabase();
926+
// 懒加载的 PPTDatabase 实例
927+
let _pptDb: PPTDatabase | null = null;
928+
929+
function getPptDbInstance(): PPTDatabase {
930+
if (!_pptDb) {
931+
_pptDb = new PPTDatabase();
932+
}
933+
return _pptDb;
934+
}
935+
936+
// 创建一个代理对象,将所有方法调用转发到懒加载的实例
937+
export const pptDb = new Proxy({} as PPTDatabase, {
938+
get(target, prop) {
939+
const instance = getPptDbInstance();
940+
const value = (instance as any)[prop];
941+
942+
if (typeof value === 'function') {
943+
return value.bind(instance);
944+
}
945+
return value;
946+
}
947+
});

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const nextConfig = {
1818
},
1919

2020
// 将过时的配置移到新位置
21-
serverExternalPackages: ['@prisma/client', 'mysql2', 'canvas'],
21+
serverExternalPackages: ['@prisma/client', 'mysql2', 'canvas', 'vm2', 'degenerator', 'pac-resolver'],
2222

2323
// 配置图片处理
2424
images: {

0 commit comments

Comments
 (0)