@x-cmd/draw 0.4.1 → 0.4.2

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.
@@ -36,8 +36,9 @@ export async function resolveSrcSpec(url) {
36
36
  if (text.length > 1024 * 1024) {
37
37
  throw new ApiError(413, `upstream spec is ${text.length}B (max 1048576)`);
38
38
  }
39
+ let spec;
39
40
  try {
40
- JSON.parse(text);
41
+ spec = JSON.parse(text);
41
42
  }
42
43
  catch {
43
44
  throw new ApiError(400, `upstream spec is not valid JSON: ${raw}`);
@@ -45,5 +46,10 @@ export async function resolveSrcSpec(url) {
45
46
  const next = new URL(url);
46
47
  next.searchParams.delete('src');
47
48
  next.searchParams.set('d', text);
49
+ // 规格文件自己知道是什么图(JSON 里的 type ✓)—— URL 没带 type 就补上 ✓
50
+ // (只给一个文件链接就能画 ✓ —— 这就是 ?src= 的用法 ✓)
51
+ if (!next.searchParams.get('type') && spec && typeof spec === 'object' && typeof spec.type === 'string') {
52
+ next.searchParams.set('type', spec.type);
53
+ }
48
54
  return next;
49
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-cmd/draw",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "SVG chart rendering as a service, a library, and a CLI — pie/bar/hbar/line/area/radar/gauge/scatter/combo/sankey/qr, same params everywhere",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",