electron app: send filename in query filename= param, instead of as part of url path, more robust and should work on windows
This commit is contained in:
+7
-1
@@ -33,7 +33,13 @@ class Chooser extends LitElement
|
||||
if (this.file) {
|
||||
loadInfo.isFile = true;
|
||||
// file.path only available in electron app
|
||||
loadInfo.loadUrl = this.file.path ? __APP_FILE_SERVE_PREFIX__ + this.file.path : URL.createObjectURL(this.file);
|
||||
if (this.file.path) {
|
||||
const url = new URL(__APP_FILE_SERVE_PREFIX__);
|
||||
url.searchParams.set("filename", this.file.path);
|
||||
loadInfo.loadUrl = url.href;
|
||||
} else {
|
||||
loadInfo.loadUrl = URL.createObjectURL(this.file);
|
||||
}
|
||||
loadInfo.noCache = this.file.path !== undefined;
|
||||
loadInfo.name = this.fileDisplayName;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import {app, session, BrowserWindow, ipcMain} from 'electron';
|
||||
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import qs from 'querystring';
|
||||
|
||||
import { ArchiveResponse, Rewriter } from 'wabac/src/rewrite';
|
||||
|
||||
@@ -133,7 +132,8 @@ async function doIntercept(request, callback) {
|
||||
}
|
||||
|
||||
if (request.url.startsWith(__APP_FILE_SERVE_PREFIX__)) {
|
||||
const filename = qs.unescape(request.url.slice(__APP_FILE_SERVE_PREFIX__.length));
|
||||
const parsedUrl = new URL(request.url);
|
||||
const filename = parsedUrl.searchParams.get("filename");
|
||||
console.log("file serve:", filename);
|
||||
|
||||
const stat = await fs.promises.lstat(filename);
|
||||
|
||||
Reference in New Issue
Block a user