fix: "add to hfs" in context-menu wasn't working for files with single-quote in the name #563

Massimo Melina committed Apr 21, 2024 at 10:40 UTC 92ee143f192ca7094a21a2741b527cc021b10e41
1 file changed +8 -3
src/api.vfs.ts
+8 -3
@@ -230,9 +230,14 @@ const apis: ApiHandlers = {
230 for (const k of ['*', 'Directory']) {
231 await reg('add', WINDOWS_REG_KEY.replace('*', k), '/ve', '/f', '/d', 'Add to HFS (new)')
232 await reg('add', WINDOWS_REG_KEY.replace('*', k) + '\\command', '/ve', '/f', '/d', `powershell -Command "
233 - $j = '{ \\"parent\\": \\"${parent}\\", \\"source\\": "' + ('%1'|convertTo-json) + '" }'; $j = [System.Text.Encoding]::UTF8.GetBytes($j); $wsh = New-Object -ComObject Wscript.Shell;
234 - try { $res = Invoke-WebRequest -Uri '${url}/~/api/add_vfs' -Method POST -Headers @{ 'x-hfs-anti-csrf' = '1' } -ContentType 'application/json' -TimeoutSec 1 -Body $j;
235 - $json = $res.Content | ConvertFrom-Json; $link = $json.link; $link | Set-Clipboard; } catch { $wsh.Popup('Server is down', 0, 'Error', 16); }"`)
233 + $wsh = New-Object -ComObject Wscript.Shell;
234 + $j = @{parent=@'\n${parent}\n'@; source=@'\n%1\n'@} | ConvertTo-Json -Compress
235 + $j = [System.Text.Encoding]::UTF8.GetBytes($j);
236 + try {
237 + $res = Invoke-WebRequest -Uri '${url}/~/api/add_vfs' -Method POST -Headers @{ 'x-hfs-anti-csrf' = '1' } -ContentType 'application/json' -TimeoutSec 1 -Body $j;
238 + $json = $res.Content | ConvertFrom-Json; $link = $json.link; $link | Set-Clipboard;
239 + $wsh.Popup('The link is ready to be pasted');
240 + } catch { $wsh.Popup('Server is down', 0, 'Error', 16); }"`)
241 }
242 return {}
243 },