@feng-vip/xxl 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/api.js +62 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feng-vip/xxl",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "XXL-JOB 分布式调度平台命令行:任务查询/触发、执行日志追踪、启停控制(无官方 CLI 故自研)",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api.js CHANGED
@@ -3,9 +3,15 @@
3
3
  // profile 解析统一走 @feng-vip/core 的 createProfileConfig。
4
4
  import fs from 'node:fs'
5
5
  import path from 'node:path'
6
- import { request } from 'undici'
6
+ import { request, Agent } from 'undici'
7
7
  import { fail, createProfileConfig, homeDirSafe } from '@feng-vip/core'
8
8
 
9
+ // 自签证书调度台(公司内网 https)TLS 校验可关:XXL_INSECURE=true 或 --insecure
10
+ const insecure = process.env.XXL_INSECURE === 'true' || process.env.XXL_INSECURE === '1'
11
+ const tlsDispatcher = insecure
12
+ ? new Agent({ connect: { rejectUnauthorized: false }, connectTimeout: 10000 })
13
+ : undefined
14
+
9
15
  const profileConfig = createProfileConfig({
10
16
  dir: path.join(homeDirSafe(), '.config', 'xxl'),
11
17
  envProfile: 'XXL_PROFILE',
@@ -89,6 +95,9 @@ export async function login(opts) {
89
95
  body,
90
96
  headersTimeout: 20000,
91
97
  bodyTimeout: 60000,
98
+ // DNS/connect 阶段单独限时:隔离网络下 NXDOMAIN 可能永不返回(容器实测踩坑)
99
+ connectTimeout: 10000,
100
+ ...(tlsDispatcher ? { dispatcher: tlsDispatcher } : {}),
92
101
  })
93
102
  } catch (err) {
94
103
  fail('网络错误: ' + ((err?.code || err?.cause?.code || err?.message) ?? String(err)))
@@ -136,6 +145,8 @@ async function post(pathAbs, fields, env, retried = false) {
136
145
  body: new URLSearchParams(Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, v == null ? '' : String(v)]))).toString(),
137
146
  headersTimeout: 20000,
138
147
  bodyTimeout: 60000,
148
+ connectTimeout: 10000,
149
+ ...(tlsDispatcher ? { dispatcher: tlsDispatcher } : {}),
139
150
  })
140
151
  } catch (err) {
141
152
  fail('网络错误: ' + ((err?.code || err?.cause?.code || err?.message) ?? String(err)))
@@ -165,8 +176,56 @@ export async function apiPost(pathAbs, fields, opts) {
165
176
 
166
177
  /** 查执行器组列表,并建立 appname/id 双向映射缓存 */
167
178
  export async function listGroups(opts) {
168
- const r = await apiPost('/jobgroup/pageList', { start: 0, length: 1000, appname: opts?.appname ?? '' }, opts)
169
- return r.data ?? []
179
+ // 新版(≥2.4):POST /jobgroup/pageList 返回 JSON。
180
+ // 老版(如公司 test 站 2.1.2):无该接口(404),执行器表内嵌在 /jobgroup 页面 HTML
181
+ // (编辑按钮属性 appName/id/addressList 携带数据)——页面解析兜底。
182
+ try {
183
+ const r = await apiPost('/jobgroup/pageList', { start: 0, length: 1000, appname: opts?.appname ?? '' }, opts)
184
+ return r.data ?? []
185
+ } catch (err) {
186
+ if (!/HTTP 404/.test(err?.message ?? '')) throw err
187
+ return listGroupsFromPage(opts)
188
+ }
189
+ }
190
+
191
+ /** 老版 xxl(2.1.x):解析 /jobgroup 页面内嵌的执行器表格 */
192
+ async function listGroupsFromPage(opts) {
193
+ const env = resolveEnv(opts)
194
+ const cookie = await ensureCookie(env)
195
+ let res
196
+ try {
197
+ res = await request(env.url + '/jobgroup', {
198
+ headers: { Cookie: cookie, 'User-Agent': 'agentkit-xxl/0.1' },
199
+ headersTimeout: 20000,
200
+ bodyTimeout: 60000,
201
+ connectTimeout: 10000,
202
+ ...(tlsDispatcher ? { dispatcher: tlsDispatcher } : {}),
203
+ })
204
+ } catch (err) {
205
+ fail('网络错误: ' + ((err?.code || err?.cause?.code || err?.message) ?? String(err)))
206
+ }
207
+ const html = await res.body.text()
208
+ const rows = []
209
+ // 每个"编辑"按钮携带一行完整数据:id / appName / title / order / addressType / addressList
210
+ const re = /<button[^>]*class="btn btn-warning btn-xs update"[^>]*>/g
211
+ for (const m of html.matchAll(re)) {
212
+ const tag = m[0]
213
+ const attr = (name) => {
214
+ const a = new RegExp(`${name}="([^"]*)"`).exec(tag)
215
+ return a ? a[1] : ''
216
+ }
217
+ rows.push({
218
+ id: attr('id'),
219
+ appname: attr('appName'),
220
+ title: attr('title'),
221
+ order: attr('order'),
222
+ addressType: attr('addressType'),
223
+ addressList: attr('addressList'),
224
+ registryList: attr('addressType') === '0' && attr('addressList') ? attr('addressList').split(',').filter(Boolean) : [],
225
+ })
226
+ }
227
+ if (opts?.appname) return rows.filter((g) => g.appname === opts.appname)
228
+ return rows
170
229
  }
171
230
 
172
231
  /** 解析 --group:数字即组 id,否则按 appname 匹配 */