From c83d114a731570f3d9eb059a21713e1e948bb977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Liu=20=E5=AE=9D=E7=8E=89?= Date: Tue, 10 Feb 2026 16:05:09 -0600 Subject: [PATCH] fix(baoyu-post-to-x): fix Windows clipboard and path handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Embed file path directly in PowerShell script with single-quote escaping instead of using param()/−Path which fails with -Command parameter. - Use fileURLToPath() for getScriptDir() to handle Windows drive-letter paths. --- skills/baoyu-post-to-x/scripts/copy-to-clipboard.ts | 12 ++++++------ skills/baoyu-post-to-x/scripts/x-utils.ts | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/skills/baoyu-post-to-x/scripts/copy-to-clipboard.ts b/skills/baoyu-post-to-x/scripts/copy-to-clipboard.ts index d27e955..e990f03 100644 --- a/skills/baoyu-post-to-x/scripts/copy-to-clipboard.ts +++ b/skills/baoyu-post-to-x/scripts/copy-to-clipboard.ts @@ -228,25 +228,25 @@ async function copyHtmlLinux(htmlFilePath: string): Promise { } async function copyImageWindows(imagePath: string): Promise { + const escaped = imagePath.replace(/'/g, "''"); const ps = [ - 'param([string]$Path)', 'Add-Type -AssemblyName System.Windows.Forms', 'Add-Type -AssemblyName System.Drawing', - '$img = [System.Drawing.Image]::FromFile($Path)', + `$img = [System.Drawing.Image]::FromFile('${escaped}')`, '[System.Windows.Forms.Clipboard]::SetImage($img)', '$img.Dispose()', ].join('; '); - await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps, '-Path', imagePath]); + await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps]); } async function copyHtmlWindows(htmlFilePath: string): Promise { + const escaped = htmlFilePath.replace(/'/g, "''"); const ps = [ - 'param([string]$Path)', 'Add-Type -AssemblyName System.Windows.Forms', - '$html = Get-Content -Raw -LiteralPath $Path', + `$html = Get-Content -Raw -LiteralPath '${escaped}'`, '[System.Windows.Forms.Clipboard]::SetText($html, [System.Windows.Forms.TextDataFormat]::Html)', ].join('; '); - await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps, '-Path', htmlFilePath]); + await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps]); } async function copyImageToClipboard(imagePathInput: string): Promise { diff --git a/skills/baoyu-post-to-x/scripts/x-utils.ts b/skills/baoyu-post-to-x/scripts/x-utils.ts index 3a2c4fe..4ad305d 100644 --- a/skills/baoyu-post-to-x/scripts/x-utils.ts +++ b/skills/baoyu-post-to-x/scripts/x-utils.ts @@ -4,6 +4,7 @@ import net from 'node:net'; import os from 'node:os'; import path from 'node:path'; import process from 'node:process'; +import { fileURLToPath } from 'node:url'; export type PlatformCandidates = { darwin?: string[]; @@ -216,7 +217,7 @@ export class CdpConnection { } export function getScriptDir(): string { - return path.dirname(new URL(import.meta.url).pathname); + return path.dirname(fileURLToPath(import.meta.url)); } function runBunScript(scriptPath: string, args: string[]): boolean {