|
|
@@ -84,22 +84,34 @@ app.on('ready', () => {
|
|
|
const relativePath = filePath.replace(path.normalize(process.resourcesPath), '').replace(/\\/g, '/').replace('//', '');
|
|
|
|
|
|
if (memoryCache[relativePath]) {
|
|
|
- const tempFilePath = path.join(app.getPath('temp'), relativePath);
|
|
|
- fs.mkdirSync(path.dirname(tempFilePath), { recursive: true });
|
|
|
- fs.writeFileSync(tempFilePath, memoryCache[relativePath]);
|
|
|
-
|
|
|
- // console.log(`Intercepting request for: ${relativePath}, redirectURL: ${tempFilePath}`);
|
|
|
-
|
|
|
- let mimeType = 'text/plain';
|
|
|
- if (relativePath.endsWith('.js')) {
|
|
|
- mimeType = 'application/javascript';
|
|
|
- } else if (relativePath.endsWith('.css')) {
|
|
|
- mimeType = 'text/css';
|
|
|
- } else if (relativePath.endsWith('.html')) {
|
|
|
- mimeType = 'text/html';
|
|
|
+ let sanitizedRelativePath = relativePath.replace('app.asar', 'app_asar'); // 避免路径中包含 app.asar
|
|
|
+ const tempFilePath = path.join(app.getPath('temp'), sanitizedRelativePath);
|
|
|
+ console.log(`Temp File Path: ${tempFilePath}`);
|
|
|
+
|
|
|
+ const tempDir = path.dirname(tempFilePath);
|
|
|
+ console.log(`Temp Directory Path: ${tempDir}`);
|
|
|
+
|
|
|
+ // 确保临时目录路径存在
|
|
|
+ if (!fs.existsSync(tempDir)) {
|
|
|
+ console.log(`Creating directory: ${tempDir}`);
|
|
|
+ fs.mkdirSync(tempDir, { recursive: true });
|
|
|
+ console.log(`Directory created: ${tempDir}`);
|
|
|
+ } else {
|
|
|
+ console.log(`Directory already exists: ${tempDir}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保目录存在后再写入文件
|
|
|
+ if (fs.existsSync(tempDir)) {
|
|
|
+ console.log(`Writing file: ${tempFilePath}`);
|
|
|
+ fs.writeFileSync(tempFilePath, memoryCache[relativePath]);
|
|
|
+ console.log(`File written: ${tempFilePath}`);
|
|
|
+
|
|
|
+ console.log(`Intercepting request for: ${relativePath}, redirectURL: ${tempFilePath}`);
|
|
|
+ callback({ cancel: false, redirectURL: tempFilePath });
|
|
|
+ } else {
|
|
|
+ console.error(`Directory does not exist after creation attempt: ${tempDir}`);
|
|
|
+ callback({ cancel: false });
|
|
|
}
|
|
|
- // console.log(`Serving from memory: ${relativePath} as ${mimeType}`);
|
|
|
- callback({ cancel: false, redirectURL: tempFilePath });
|
|
|
} else {
|
|
|
callback({ cancel: false });
|
|
|
}
|