fix: canonical uri can't load chinese file name

fixes #610
This commit is contained in:
linonetwo 2025-02-01 13:39:21 +08:00
parent c649eddc5f
commit 7191fe57fa
2 changed files with 18 additions and 2 deletions

View file

@ -73,8 +73,22 @@ export function setupIpcServerRoutesHandlers(view: WebContentsView, workspaceID:
method: 'GET',
path: /^\/files\/(.+)$/,
name: 'getFile',
handler: async (_request: GlobalRequest, workspaceIDFromHost: string, parameters: RegExpMatchArray | null) =>
await wikiService.callWikiIpcServerRoute(workspaceIDFromHost, 'getFile', parameters?.[1] ?? ''),
handler: async (_request: GlobalRequest, workspaceIDFromHost: string, parameters: RegExpMatchArray | null) => {
/**
* ```
* parameters [
'/files/%E4%B8%9C%E5%90%B413%E5%B2%81%E7%99%BB%E9%95%BF%E5%9F%8E%E7%85%A7.JPG',
'%E4%B8%9C%E5%90%B413%E5%B2%81%E7%99%BB%E9%95%BF%E5%9F%8E%E7%85%A7.JPG',
index: 0,
input: '/files/%E4%B8%9C%E5%90%B413%E5%B2%81%E7%99%BB%E9%95%BF%E5%9F%8E%E7%85%A7.JPG',
groups: undefined
]
```
Decode Chinese similar to src/services/view/setupViewFileProtocol.ts
*/
return await wikiService.callWikiIpcServerRoute(workspaceIDFromHost, 'getFile', decodeURI(parameters?.[1] ?? ''));
},
},
{
method: 'GET',

View file

@ -53,6 +53,8 @@ export function handleOpenFileExternalLink(nextUrl: string, newWindowContext: IN
/* eslint-disable n/no-callback-literal */
/**
* Handle file protocol in webview to request file content and show in the view.
*
* Similar to src/services/view/setupIpcServerRoutesHandlers.ts where it is redirect and handled by tiddlywiki server.
*/
export function handleViewFileContentLoading(view: WebContentsView) {
view.webContents.session.webRequest.onBeforeRequest((details, callback) => {