@vibe-x/dsh-html-workbench 0.1.1 → 0.2.0

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/src/host.js CHANGED
@@ -148,11 +148,28 @@ return {
148
148
  }
149
149
  }
150
150
 
151
+ const resolvePath = async (file) => {
152
+ if (typeof file !== 'string') return { ok: false, error: 'file is required' }
153
+ const trimmed = file.trim()
154
+ if (!trimmed) return { ok: true, empty: true, isHtml: false, exists: false }
155
+ if (!/\.html?$/i.test(trimmed)) return { ok: true, isHtml: false, exists: false }
156
+ if (!shell) return { ok: true, isHtml: true, exists: null }
157
+ const arg = JSON.stringify(trimmed)
158
+ const spec = shell.resolve({ command: 'python3 -c "import os,sys; sys.exit(0 if os.path.isfile(sys.argv[1]) else 1)" ' + arg, timeoutMs: 5000, stdoutMaxBytes: 1024 })
159
+ try {
160
+ const r = await shell.run(spec)
161
+ return { ok: true, isHtml: true, exists: !!(r && r.exitCode === 0) }
162
+ } catch (e) {
163
+ return { ok: true, isHtml: true, exists: null }
164
+ }
165
+ }
166
+
151
167
  // 动态传输:Package-private RPC(仅动态运行时存在 harness)。
152
168
  if (typeof harness !== 'undefined') {
153
169
  harness.handle('list', () => ({ ok: true, running: serviceRunning, owned: !!ownedProcess, port: PORT, assets: snapshot() }))
154
170
  harness.handle('status', async () => { const h = await health(); return { ok: !!h, running: !!h, owned: !!ownedProcess, port: PORT, info: h || null } })
155
171
  harness.handle('open', async (args) => openFile(args && args.file))
172
+ harness.handle('resolve', async (args) => resolvePath(args && args.file))
156
173
  }
157
174
 
158
175
  // 静态传输:HTTP 路由,供静态 client bundle(fetch)与直接浏览器访问使用。
@@ -193,6 +210,14 @@ return {
193
210
  sendJson(res, out.ok ? 200 : 400, out)
194
211
  },
195
212
  }), 'html-workbench: open route')
213
+ ctx.effect(() => webServer.register({
214
+ kind: 'exact',
215
+ path: '/html-workbench/resolve',
216
+ handler: async (req, res) => {
217
+ const out = await resolvePath(parseQuery(req).file)
218
+ sendJson(res, out.ok ? 200 : 400, out)
219
+ },
220
+ }), 'html-workbench: resolve route')
196
221
  }
197
222
 
198
223
  // 注册时主动拉起服务(异步,不阻塞 apply)。