next-admin-svr 0.1.48 → 0.1.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -2740,21 +2740,24 @@ const ROBOT_NOTIFY_CONFIG = {
2740
2740
  * 2. 收到新邮件后,提取 markdown 内容
2741
2741
  * 3. 创建 iwiki 文档
2742
2742
  */
2743
- async function watchEmailAndSyncToIwiki() {
2744
- const password = process.env[EMAIL_CONFIG.passwordEnvName];
2743
+ async function watchEmailAndSyncToIwiki(options = {}) {
2744
+ const mergedEmailConfig = { ...EMAIL_CONFIG, ...options.emailConfig };
2745
+ const mergedIwikiConfig = { ...IWIKI_CONFIG, ...options.iwikiConfig };
2746
+ const mergedRobotNotifyConfig = { ...ROBOT_NOTIFY_CONFIG, ...options.robotNotifyConfig };
2747
+ const password = process.env[mergedEmailConfig.passwordEnvName];
2745
2748
  if (!password) {
2746
- console.error(`[EmailSync] 环境变量 ${EMAIL_CONFIG.passwordEnvName} 未设置,无法启动邮件监听`);
2749
+ console.error(`[EmailSync] 环境变量 ${mergedEmailConfig.passwordEnvName} 未设置,无法启动邮件监听`);
2747
2750
  return;
2748
2751
  }
2749
2752
  const watcher = await shared.watchEmails({
2750
- host: EMAIL_CONFIG.host,
2751
- user: EMAIL_CONFIG.user,
2753
+ host: mergedEmailConfig.host,
2754
+ user: mergedEmailConfig.user,
2752
2755
  password,
2753
2756
  onNewEmail: async (email) => {
2754
2757
  console.log(`[EmailSync] 📬 收到新邮件: "${email.subject}" from ${email.from}`);
2755
2758
  tComm.saveJsonToLog(email, 'new-email.json');
2756
2759
  try {
2757
- await syncEmailToIwiki(email);
2760
+ await syncEmailToIwiki(email, mergedIwikiConfig, mergedRobotNotifyConfig);
2758
2761
  }
2759
2762
  catch (err) {
2760
2763
  console.error('[EmailSync] 同步邮件到 iwiki 失败:', err);
@@ -2776,7 +2779,7 @@ async function watchEmailAndSyncToIwiki() {
2776
2779
  /**
2777
2780
  * 将单封邮件同步到 iwiki
2778
2781
  */
2779
- async function syncEmailToIwiki(email) {
2782
+ async function syncEmailToIwiki(email, iwikiConfig, robotNotifyConfig) {
2780
2783
  // 1. 构建邮件的完整 Markdown 内容
2781
2784
  let fullMarkdown = buildEmailMarkdown(email);
2782
2785
  if (!fullMarkdown.trim()) {
@@ -2792,10 +2795,10 @@ async function syncEmailToIwiki(email) {
2792
2795
  sender: email.from,
2793
2796
  };
2794
2797
  // 4. 创建 iwiki 文档
2795
- const iwikiUrl = await saveToIwiki(entry);
2798
+ const iwikiUrl = await saveToIwiki(entry, iwikiConfig);
2796
2799
  console.log(`[EmailSync] ✅ 邮件 "${email.subject}" 已同步到 iwiki: ${iwikiUrl}`);
2797
2800
  // 5. 发送企微机器人通知
2798
- await notifyRobot(entry, iwikiUrl);
2801
+ await notifyRobot(entry, iwikiUrl, robotNotifyConfig);
2799
2802
  }
2800
2803
  // ==================== 图片上传 ====================
2801
2804
  /** 匹配 Markdown 中的 base64 图片:![alt](data:image/xxx;base64,...) */
@@ -2936,7 +2939,11 @@ function buildEmailMarkdown(email) {
2936
2939
  /**
2937
2940
  * 通过企微机器人发送通知消息
2938
2941
  */
2939
- async function notifyRobot(entry, iwikiUrl) {
2942
+ async function notifyRobot(entry, iwikiUrl, robotNotifyConfig) {
2943
+ if (!robotNotifyConfig.webhookUrl) {
2944
+ console.warn('[EmailSync] 未配置机器人 webhookUrl,跳过通知');
2945
+ return;
2946
+ }
2940
2947
  const contentPreview = entry.content.length > 200
2941
2948
  ? `${entry.content.slice(0, 200)}...`
2942
2949
  : entry.content;
@@ -2951,8 +2958,8 @@ async function notifyRobot(entry, iwikiUrl) {
2951
2958
  try {
2952
2959
  await tComm.batchSendWxRobotMarkdown({
2953
2960
  content: message,
2954
- chatId: ROBOT_NOTIFY_CONFIG.chatId,
2955
- webhookUrl: ROBOT_NOTIFY_CONFIG.webhookUrl,
2961
+ chatId: robotNotifyConfig.chatId,
2962
+ webhookUrl: robotNotifyConfig.webhookUrl,
2956
2963
  isV2: true,
2957
2964
  });
2958
2965
  console.log('[EmailSync] 📤 机器人通知已发送');
@@ -2964,18 +2971,18 @@ async function notifyRobot(entry, iwikiUrl) {
2964
2971
  /**
2965
2972
  * 创建 iwiki 文档
2966
2973
  */
2967
- async function saveToIwiki(entry) {
2968
- const paasToken = process.env[IWIKI_CONFIG.paasTokenEnvName] || '';
2974
+ async function saveToIwiki(entry, iwikiConfig) {
2975
+ const paasToken = process.env[iwikiConfig.paasTokenEnvName] || '';
2969
2976
  if (!paasToken) {
2970
- throw new Error(`环境变量 ${IWIKI_CONFIG.paasTokenEnvName} 未设置`);
2977
+ throw new Error(`环境变量 ${iwikiConfig.paasTokenEnvName} 未设置`);
2971
2978
  }
2972
2979
  const docTitle = `${entry.title} - ${entry.sender}`;
2973
2980
  const res = await tComm.createIwikiDoc({
2974
- prefix: IWIKI_CONFIG.urlPrefixInOA,
2975
- paasId: IWIKI_CONFIG.paasid,
2981
+ prefix: iwikiConfig.urlPrefixInOA,
2982
+ paasId: iwikiConfig.paasid,
2976
2983
  paasToken,
2977
- parentid: IWIKI_CONFIG.parentDocId,
2978
- spacekey: IWIKI_CONFIG.spacekey,
2984
+ parentid: iwikiConfig.parentDocId,
2985
+ spacekey: iwikiConfig.spacekey,
2979
2986
  bodymode: 'md',
2980
2987
  title: docTitle,
2981
2988
  body: entry.content,
@@ -2984,7 +2991,7 @@ async function saveToIwiki(entry) {
2984
2991
  if (!res.data?.id) {
2985
2992
  throw new Error(`创建 iwiki 文档失败: ${res.msg}`);
2986
2993
  }
2987
- return `${IWIKI_CONFIG.iwikiUrlPrefix}${res.data.id}`;
2994
+ return `${iwikiConfig.iwikiUrlPrefix}${res.data.id}`;
2988
2995
  }
2989
2996
 
2990
2997
  exports.componentStatisticsOpenRouter = router$e;
package/lib/index.mjs CHANGED
@@ -2729,21 +2729,24 @@ const ROBOT_NOTIFY_CONFIG = {
2729
2729
  * 2. 收到新邮件后,提取 markdown 内容
2730
2730
  * 3. 创建 iwiki 文档
2731
2731
  */
2732
- async function watchEmailAndSyncToIwiki() {
2733
- const password = process.env[EMAIL_CONFIG.passwordEnvName];
2732
+ async function watchEmailAndSyncToIwiki(options = {}) {
2733
+ const mergedEmailConfig = { ...EMAIL_CONFIG, ...options.emailConfig };
2734
+ const mergedIwikiConfig = { ...IWIKI_CONFIG, ...options.iwikiConfig };
2735
+ const mergedRobotNotifyConfig = { ...ROBOT_NOTIFY_CONFIG, ...options.robotNotifyConfig };
2736
+ const password = process.env[mergedEmailConfig.passwordEnvName];
2734
2737
  if (!password) {
2735
- console.error(`[EmailSync] 环境变量 ${EMAIL_CONFIG.passwordEnvName} 未设置,无法启动邮件监听`);
2738
+ console.error(`[EmailSync] 环境变量 ${mergedEmailConfig.passwordEnvName} 未设置,无法启动邮件监听`);
2736
2739
  return;
2737
2740
  }
2738
2741
  const watcher = await watchEmails({
2739
- host: EMAIL_CONFIG.host,
2740
- user: EMAIL_CONFIG.user,
2742
+ host: mergedEmailConfig.host,
2743
+ user: mergedEmailConfig.user,
2741
2744
  password,
2742
2745
  onNewEmail: async (email) => {
2743
2746
  console.log(`[EmailSync] 📬 收到新邮件: "${email.subject}" from ${email.from}`);
2744
2747
  saveJsonToLog(email, 'new-email.json');
2745
2748
  try {
2746
- await syncEmailToIwiki(email);
2749
+ await syncEmailToIwiki(email, mergedIwikiConfig, mergedRobotNotifyConfig);
2747
2750
  }
2748
2751
  catch (err) {
2749
2752
  console.error('[EmailSync] 同步邮件到 iwiki 失败:', err);
@@ -2765,7 +2768,7 @@ async function watchEmailAndSyncToIwiki() {
2765
2768
  /**
2766
2769
  * 将单封邮件同步到 iwiki
2767
2770
  */
2768
- async function syncEmailToIwiki(email) {
2771
+ async function syncEmailToIwiki(email, iwikiConfig, robotNotifyConfig) {
2769
2772
  // 1. 构建邮件的完整 Markdown 内容
2770
2773
  let fullMarkdown = buildEmailMarkdown(email);
2771
2774
  if (!fullMarkdown.trim()) {
@@ -2781,10 +2784,10 @@ async function syncEmailToIwiki(email) {
2781
2784
  sender: email.from,
2782
2785
  };
2783
2786
  // 4. 创建 iwiki 文档
2784
- const iwikiUrl = await saveToIwiki(entry);
2787
+ const iwikiUrl = await saveToIwiki(entry, iwikiConfig);
2785
2788
  console.log(`[EmailSync] ✅ 邮件 "${email.subject}" 已同步到 iwiki: ${iwikiUrl}`);
2786
2789
  // 5. 发送企微机器人通知
2787
- await notifyRobot(entry, iwikiUrl);
2790
+ await notifyRobot(entry, iwikiUrl, robotNotifyConfig);
2788
2791
  }
2789
2792
  // ==================== 图片上传 ====================
2790
2793
  /** 匹配 Markdown 中的 base64 图片:![alt](data:image/xxx;base64,...) */
@@ -2925,7 +2928,11 @@ function buildEmailMarkdown(email) {
2925
2928
  /**
2926
2929
  * 通过企微机器人发送通知消息
2927
2930
  */
2928
- async function notifyRobot(entry, iwikiUrl) {
2931
+ async function notifyRobot(entry, iwikiUrl, robotNotifyConfig) {
2932
+ if (!robotNotifyConfig.webhookUrl) {
2933
+ console.warn('[EmailSync] 未配置机器人 webhookUrl,跳过通知');
2934
+ return;
2935
+ }
2929
2936
  const contentPreview = entry.content.length > 200
2930
2937
  ? `${entry.content.slice(0, 200)}...`
2931
2938
  : entry.content;
@@ -2940,8 +2947,8 @@ async function notifyRobot(entry, iwikiUrl) {
2940
2947
  try {
2941
2948
  await batchSendWxRobotMarkdown({
2942
2949
  content: message,
2943
- chatId: ROBOT_NOTIFY_CONFIG.chatId,
2944
- webhookUrl: ROBOT_NOTIFY_CONFIG.webhookUrl,
2950
+ chatId: robotNotifyConfig.chatId,
2951
+ webhookUrl: robotNotifyConfig.webhookUrl,
2945
2952
  isV2: true,
2946
2953
  });
2947
2954
  console.log('[EmailSync] 📤 机器人通知已发送');
@@ -2953,18 +2960,18 @@ async function notifyRobot(entry, iwikiUrl) {
2953
2960
  /**
2954
2961
  * 创建 iwiki 文档
2955
2962
  */
2956
- async function saveToIwiki(entry) {
2957
- const paasToken = process.env[IWIKI_CONFIG.paasTokenEnvName] || '';
2963
+ async function saveToIwiki(entry, iwikiConfig) {
2964
+ const paasToken = process.env[iwikiConfig.paasTokenEnvName] || '';
2958
2965
  if (!paasToken) {
2959
- throw new Error(`环境变量 ${IWIKI_CONFIG.paasTokenEnvName} 未设置`);
2966
+ throw new Error(`环境变量 ${iwikiConfig.paasTokenEnvName} 未设置`);
2960
2967
  }
2961
2968
  const docTitle = `${entry.title} - ${entry.sender}`;
2962
2969
  const res = await createIwikiDoc({
2963
- prefix: IWIKI_CONFIG.urlPrefixInOA,
2964
- paasId: IWIKI_CONFIG.paasid,
2970
+ prefix: iwikiConfig.urlPrefixInOA,
2971
+ paasId: iwikiConfig.paasid,
2965
2972
  paasToken,
2966
- parentid: IWIKI_CONFIG.parentDocId,
2967
- spacekey: IWIKI_CONFIG.spacekey,
2973
+ parentid: iwikiConfig.parentDocId,
2974
+ spacekey: iwikiConfig.spacekey,
2968
2975
  bodymode: 'md',
2969
2976
  title: docTitle,
2970
2977
  body: entry.content,
@@ -2973,7 +2980,7 @@ async function saveToIwiki(entry) {
2973
2980
  if (!res.data?.id) {
2974
2981
  throw new Error(`创建 iwiki 文档失败: ${res.msg}`);
2975
2982
  }
2976
- return `${IWIKI_CONFIG.iwikiUrlPrefix}${res.data.id}`;
2983
+ return `${iwikiConfig.iwikiUrlPrefix}${res.data.id}`;
2977
2984
  }
2978
2985
 
2979
2986
  export { router$e as componentStatisticsOpenRouter, router$d as componentStatisticsRouter, coreModule, createUpdateWhiteUserCosCron, router$b as cyclomaticComplexityOpenRouter, router$c as cyclomaticComplexityRouter, router$a as fontProjectRouter, router$9 as iconProjectRouter, router$7 as imageOpenRouter, router$8 as imageRouter, router$6 as mpCiOpenRouter, router$4 as pipelineOpenRouter, router$5 as pipelineRouter, router$2 as robotKnowledgeEntryRouter, router$3 as robotRouter, watchEmailAndSyncToIwiki, router as whiteUserOpenRouter, router$1 as whiteUserRouter };
@@ -1,3 +1,43 @@
1
+ /** 邮箱 IMAP 连接配置参数 */
2
+ interface EmailConfigOptions {
3
+ /** IMAP 服务器地址 */
4
+ host?: string;
5
+ /** 邮箱账号 */
6
+ user?: string;
7
+ /** 密码环境变量名 */
8
+ passwordEnvName?: string;
9
+ }
10
+ /** iwiki 配置参数 */
11
+ interface IwikiConfigOptions {
12
+ /** OA 环境的 iwiki API 前缀 */
13
+ urlPrefixInOA?: string;
14
+ /** iwiki 文档 URL 前缀 */
15
+ iwikiUrlPrefix?: string;
16
+ /** iwiki 空间 key */
17
+ spacekey?: string;
18
+ /** 邮件同步文档的父级文档 ID */
19
+ parentDocId?: number;
20
+ /** paas 认证 ID */
21
+ paasid?: string;
22
+ /** paas token 环境变量名 */
23
+ paasTokenEnvName?: string;
24
+ }
25
+ /** 企微机器人通知配置参数 */
26
+ interface RobotNotifyConfigOptions {
27
+ /** 机器人 webhook URL */
28
+ webhookUrl?: string;
29
+ /** 群聊 chatId */
30
+ chatId?: string;
31
+ }
32
+ /** watchEmailAndSyncToIwiki 的参数 */
33
+ interface WatchEmailAndSyncToIwikiOptions {
34
+ /** 邮箱 IMAP 连接配置 */
35
+ emailConfig?: EmailConfigOptions;
36
+ /** iwiki 配置 */
37
+ iwikiConfig?: IwikiConfigOptions;
38
+ /** 企微机器人通知配置 */
39
+ robotNotifyConfig?: RobotNotifyConfigOptions;
40
+ }
1
41
  /**
2
42
  * 启动邮件监听,自动将新邮件内容同步到 iwiki
3
43
  *
@@ -6,4 +46,5 @@
6
46
  * 2. 收到新邮件后,提取 markdown 内容
7
47
  * 3. 创建 iwiki 文档
8
48
  */
9
- export declare function watchEmailAndSyncToIwiki(): Promise<import("@plugin-light/shared").EmailWatcher | undefined>;
49
+ export declare function watchEmailAndSyncToIwiki(options?: WatchEmailAndSyncToIwikiOptions): Promise<import("@plugin-light/shared").EmailWatcher | undefined>;
50
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-admin-svr",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "description": "Next Admin 服务端",
5
5
  "keywords": [
6
6
  "vue3",
@@ -37,7 +37,7 @@
37
37
  "t-comm": "latest",
38
38
  "tinify": "^1.8.2",
39
39
  "tslib": "^2.8.1",
40
- "@plugin-light/shared": "^1.0.14"
40
+ "@plugin-light/shared": "^1.0.15"
41
41
  },
42
42
  "devDependencies": {
43
43
  "axios": "latest"