@qihoo/tuitui-openclaw-channel 1.0.32 → 1.0.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qihoo/tuitui-openclaw-channel",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "maintainers": [
5
5
  {
6
6
  "name": "huzunjie",
package/src/filespace.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CHANNEL_ID } from "./const";
2
- import { tuituiRobotApi, downloadUrl, tuituiRobotUpload} from "./robot_api"
2
+ import { tuituiRobotApi, tuituiRobotUpload} from "./robot_api"
3
3
  import {CHAT_TYPE_CHANNEL, parseSessionKey} from "./chat_base"
4
4
  import {getChannelInfoByChannelId} from "./robot_helper"
5
5
 
package/src/robot_api.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { readFileSync, existsSync, statSync } from 'node:fs';
2
2
  import { basename } from 'node:path';
3
- import { fetchWithSsrFGuard } from 'openclaw/plugin-sdk/tlon';
4
3
  import { CHANNEL_ID } from "./const";
5
4
  import { TUITUI_SSRF_POLICY, getTuituiApiHost } from "./env"
6
5
 
@@ -34,8 +33,8 @@ export async function tuituiRobotApi(account: any, api: string, payload: any, lo
34
33
  fetch_fun = _fetchForm;
35
34
  }
36
35
 
37
- const { response, release } = await fetch_fun(url, payload);
38
36
  try {
37
+ const response = await fetch_fun(url, payload);
39
38
  const bodyText = await response.text();
40
39
 
41
40
  if (!response.ok) {
@@ -52,41 +51,26 @@ export async function tuituiRobotApi(account: any, api: string, payload: any, lo
52
51
  console.error(`[${CHANNEL_ID}] ${api} error:`, err);
53
52
  throw err;
54
53
  } finally {
55
- await release();
56
54
  if (log) {
57
- const endTime = Date.now(); // 记录结束时间
58
- const duration = endTime - startTime; // 计算耗时
55
+ const endTime = Date.now();
56
+ const duration = endTime - startTime;
59
57
  console.log(`[${CHANNEL_ID}] ${api} response took ${duration}ms`);
60
58
  }
61
59
  }
62
60
  }
63
61
 
64
- function _fetch(opts: any): Promise<any> {
65
- return fetchWithSsrFGuard({
66
- policy: TUITUI_SSRF_POLICY,
67
- ...opts,
68
- })
69
- }
70
- function _fetchJson(url: string, json: any, auditCtx: string = "tuitui.api.call"): Promise<any> {
71
- return _fetch({
72
- url,
73
- init: {
74
- method: 'POST',
75
- headers: { 'Content-Type': 'application/json' },
76
- body: JSON.stringify(json),
77
- },
78
- auditCtx
62
+ function _fetchJson(url: string, json: any): Promise<Response> {
63
+ return fetch(url, {
64
+ method: 'POST',
65
+ headers: { 'Content-Type': 'application/json' },
66
+ body: JSON.stringify(json),
79
67
  });
80
68
  }
81
69
 
82
- function _fetchForm(url: string, form: any, auditCtx: string = "tuitui.api.call"): Promise<any> {
83
- return _fetch({
84
- url,
85
- init: {
86
- method: 'POST',
87
- body: form,
88
- },
89
- auditCtx
70
+ function _fetchForm(url: string, form: any): Promise<Response> {
71
+ return fetch(url, {
72
+ method: 'POST',
73
+ body: form,
90
74
  });
91
75
  }
92
76
 
@@ -96,10 +80,26 @@ function _fetchForm(url: string, form: any, auditCtx: string = "tuitui.api.call"
96
80
  * @returns Object with buffer, filename and content type
97
81
  */
98
82
  export async function downloadUrl(url: string): Promise<{ buffer: ArrayBuffer; filename: string; contentType: string }> {
99
- const { response, release } = await _fetch({
83
+ console.log(`[${CHANNEL_ID}] downloadUrl prepair`);
84
+
85
+ let fetchWithSsrFGuard: any;
86
+ try {
87
+ fetchWithSsrFGuard = (await import('openclaw/plugin-sdk/ssrf-runtime')).fetchWithSsrFGuard;
88
+ } catch {
89
+ try {
90
+ fetchWithSsrFGuard = (await import('openclaw/plugin-sdk/tlon')).fetchWithSsrFGuard;
91
+ } catch {
92
+ throw new Error(`[${CHANNEL_ID}] fetchWithSsrFGuard() API import failed`);
93
+ }
94
+ }
95
+
96
+ console.log(`[${CHANNEL_ID}] downloadUrl start ${url}`);
97
+
98
+ const { response, release } = await fetchWithSsrFGuard({
99
+ policy: TUITUI_SSRF_POLICY,
100
100
  url,
101
101
  init: { method: 'GET' },
102
- auditCtx: "tuitui.download"
102
+ auditContext: "tuitui.download",
103
103
  });
104
104
 
105
105
  try {
@@ -127,6 +127,8 @@ export async function downloadUrl(url: string): Promise<{ buffer: ArrayBuffer; f
127
127
  if (match) filename = decodeURIComponent(match[1]);
128
128
  }
129
129
 
130
+ console.log(`[${CHANNEL_ID}] downloadUrl ok`);
131
+
130
132
  return { buffer, filename, contentType };
131
133
  } finally {
132
134
  await release();