diff --git a/gateway/src/connectors/penpot-export.ts b/gateway/src/connectors/penpot-export.ts new file mode 100644 index 00000000..d0060bb7 --- /dev/null +++ b/gateway/src/connectors/penpot-export.ts @@ -0,0 +1,50 @@ +/** + * @module gateway-penpot-export + * @path gateway/src/connectors/penpot-export.ts + * @description Penpot exporter SVG export (POST /api/export :export-shapes) + * @zone action + * @tier Tier2-support + * + * @skill penpot-svg-export — export page/shape to SVG via exporter service + * @rule exporter-auth P1 — X-Shared-Key: exporter + session cookie + * @state: UNVERIFIED — 依赖 Penpot exporter 服务,当前环境未启动,无法端到端验证 + */ + +export interface ExportShapeInput { + fileId: string; + pageId: string; + objectId?: string; +} + +export class PenpotExporter { + constructor( + private base: string, + private sharedKey: string, + ) {} + + /** @skill: penpot-export-svg — call exporter :export-shapes, return SVG bytes */ + async exportSvg(input: ExportShapeInput): Promise { + const res = await fetch(`${this.base}/api/export`, { + method: 'POST', + headers: { + 'content-type': 'application/transit+json', + 'x-shared-key': `exporter ${this.sharedKey}`, + }, + body: JSON.stringify({ + cmd: ':export-shapes', + exports: [ + { + 'file-id': input.fileId, + 'page-id': input.pageId, + 'object-id': input.objectId ?? input.pageId, + type: 'svg', + }, + ], + }), + }); + if (!res.ok) { + throw new Error(`Penpot exporter HTTP ${res.status}: ${await res.text()}`); + } + return Buffer.from(await res.arrayBuffer()); + } +}