mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
fix: infinite redirect when using file:// protocol to load image
This commit is contained in:
parent
e241ff3693
commit
5b3e03aac9
2 changed files with 8 additions and 2 deletions
|
|
@ -270,7 +270,7 @@ ${message.message}
|
|||
* hostname: `.`, pathname: `/files/xxx.png`
|
||||
*/
|
||||
let filePath = decodeURIComponent(`${hostname}${pathname}`);
|
||||
// get "/D:/" on windows
|
||||
// get "D:/" instead of "/D:/" on windows
|
||||
if (process.platform === 'win32' && filePath.startsWith('/')) {
|
||||
filePath = filePath.substring(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,13 @@ function handleFileLink(details: Electron.OnBeforeRequestListenerDetails, callba
|
|||
const nativeService = container.get<INativeService>(serviceIdentifier.NativeService);
|
||||
const absolutePath: string | undefined = nativeService.formatFileUrlToAbsolutePath(details.url);
|
||||
// When details.url is an absolute route, we just load it, don't need any redirect
|
||||
if (`file://${absolutePath}` === decodeURI(details.url) || absolutePath === decodeURI(details.url)) {
|
||||
if (
|
||||
`file://${absolutePath}` === decodeURI(details.url) ||
|
||||
absolutePath === decodeURI(details.url) ||
|
||||
// also allow malformed `file:///` on `details.url` on windows, prevent infinite redirect when this check failed.
|
||||
(process.platform === 'win32' && `file:///${absolutePath}` === decodeURI(details.url))
|
||||
) {
|
||||
logger.debug(`Open file protocol to ${String(absolutePath)}`, { function: 'handleFileLink' });
|
||||
callback({
|
||||
cancel: false,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue