mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 18:05:55 +01:00 
			
		
		
		
	Compare commits
	
		
			8 Commits
		
	
	
		
			feat/rice-
			...
			fix/resolv
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | ac73d4c47a | ||
|  | e4006a83f2 | ||
|  | 5782f93824 | ||
|  | c76e265b67 | ||
|  | fefcd9457f | ||
|  | 72a779e695 | ||
|  | f6c27f458a | ||
|  | adfaa8b12c | 
| @@ -37,7 +37,10 @@ const config: ForgeConfig = { | |||||||
|         executableName: EXECUTABLE_NAME, |         executableName: EXECUTABLE_NAME, | ||||||
|         name: PRODUCT_NAME, |         name: PRODUCT_NAME, | ||||||
|         overwrite: true, |         overwrite: true, | ||||||
|         asar: true, |         asar: { | ||||||
|  |             unpack: "node_modules/swagger-ui-dist/**", | ||||||
|  |             unpackDir: "assets" | ||||||
|  |         }, | ||||||
|         icon: path.join(APP_ICON_PATH, "icon"), |         icon: path.join(APP_ICON_PATH, "icon"), | ||||||
|         ...macosSignConfiguration, |         ...macosSignConfiguration, | ||||||
|         windowsSign: windowsSignConfiguration, |         windowsSign: windowsSignConfiguration, | ||||||
|   | |||||||
| @@ -3,16 +3,102 @@ import swaggerUi from "swagger-ui-express"; | |||||||
| import { join } from "path"; | import { join } from "path"; | ||||||
| import yaml from "js-yaml"; | import yaml from "js-yaml"; | ||||||
| import type { JsonObject } from "swagger-ui-express"; | import type { JsonObject } from "swagger-ui-express"; | ||||||
| import { readFileSync } from "fs"; | import { readFileSync, existsSync, readdirSync } from "fs"; | ||||||
| import { RESOURCE_DIR } from "../services/resource_dir"; | import { RESOURCE_DIR } from "../services/resource_dir"; | ||||||
|  | import log from "../services/log"; | ||||||
|  |  | ||||||
|  | // Monkey patch fs.lstat to debug which files are causing the issue | ||||||
|  | const originalFs = require('fs'); | ||||||
|  | const originalLstat = originalFs.lstat; | ||||||
|  | originalFs.lstat = function(path: string, callback: any) { | ||||||
|  |     log.info(`[FS DEBUG] lstat called on: ${path}`); | ||||||
|  |     return originalLstat.call(this, path, (err: any, stats: any) => { | ||||||
|  |         if (err) { | ||||||
|  |             log.error(`[FS DEBUG] lstat error on ${path}: ${err.message}`); | ||||||
|  |         } | ||||||
|  |         callback(err, stats); | ||||||
|  |     }); | ||||||
|  | }; | ||||||
|  |  | ||||||
| export default function register(app: Application) { | export default function register(app: Application) { | ||||||
|     const etapiDocument = yaml.load(readFileSync(join(RESOURCE_DIR, "etapi.openapi.yaml"), "utf8")) as JsonObject; |     log.info(`[DEBUG] Starting API docs registration`); | ||||||
|     const apiDocument = JSON.parse(readFileSync(join(RESOURCE_DIR, "openapi.json"), "utf-8")); |     log.info(`[DEBUG] RESOURCE_DIR: ${RESOURCE_DIR}`); | ||||||
|  |      | ||||||
|  |     // Clean trailing slashes from RESOURCE_DIR to prevent path resolution issues in packaged Electron apps | ||||||
|  |     const cleanResourceDir = RESOURCE_DIR.replace(/[\\\/]+$/, ''); | ||||||
|  |     log.info(`[DEBUG] cleanResourceDir: ${cleanResourceDir}`); | ||||||
|  |      | ||||||
|  |     // Check what's in the resource directory | ||||||
|  |     try { | ||||||
|  |         if (existsSync(cleanResourceDir)) { | ||||||
|  |             const contents = readdirSync(cleanResourceDir); | ||||||
|  |             log.info(`[DEBUG] Contents of ${cleanResourceDir}: ${contents.join(', ')}`); | ||||||
|  |         } else { | ||||||
|  |             log.info(`[DEBUG] Resource directory doesn't exist: ${cleanResourceDir}`); | ||||||
|  |         } | ||||||
|  |     } catch (e) { | ||||||
|  |         log.error(`[DEBUG] Error reading resource directory: ${e}`); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     // In packaged Electron apps, check if we need to read from the unpacked directory | ||||||
|  |     let resourceDir = cleanResourceDir; | ||||||
|  |     if (resourceDir.includes('app.asar')) { | ||||||
|  |         log.info(`[DEBUG] Detected ASAR packaging`); | ||||||
|  |         const unpackedDir = cleanResourceDir.replace('app.asar', 'app.asar.unpacked'); | ||||||
|  |         log.info(`[DEBUG] Checking unpacked dir: ${unpackedDir}`); | ||||||
|  |          | ||||||
|  |         // Check what's in the unpacked directory | ||||||
|  |         try { | ||||||
|  |             if (existsSync(unpackedDir)) { | ||||||
|  |                 const unpackedContents = readdirSync(unpackedDir); | ||||||
|  |                 log.info(`[DEBUG] Contents of unpacked dir: ${unpackedContents.join(', ')}`); | ||||||
|  |                 if (existsSync(join(unpackedDir, "etapi.openapi.yaml"))) { | ||||||
|  |                     resourceDir = unpackedDir; | ||||||
|  |                     log.info(`[DEBUG] Using unpacked directory: ${resourceDir}`); | ||||||
|  |                 } | ||||||
|  |             } else { | ||||||
|  |                 log.info(`[DEBUG] Unpacked directory doesn't exist: ${unpackedDir}`); | ||||||
|  |             } | ||||||
|  |         } catch (e) { | ||||||
|  |             log.error(`[DEBUG] Error checking unpacked directory: ${e}`); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     log.info(`[DEBUG] Final resourceDir: ${resourceDir}`); | ||||||
|  |     log.info(`[DEBUG] About to load OpenAPI specs...`); | ||||||
|  |      | ||||||
|  |     const etapiDocument = yaml.load(readFileSync(join(resourceDir, "etapi.openapi.yaml"), "utf8")) as JsonObject; | ||||||
|  |     const apiDocument = JSON.parse(readFileSync(join(resourceDir, "openapi.json"), "utf-8")); | ||||||
|  |      | ||||||
|  |     log.info(`[DEBUG] Successfully loaded OpenAPI documents`); | ||||||
|  |     log.info(`[DEBUG] About to register swagger-ui endpoints...`); | ||||||
|  |      | ||||||
|  |     // Check swagger-ui-dist location | ||||||
|  |     try { | ||||||
|  |         const swaggerPath = require.resolve('swagger-ui-dist/package.json'); | ||||||
|  |         log.info(`[DEBUG] swagger-ui-dist package.json found at: ${swaggerPath}`); | ||||||
|  |         const swaggerDistPath = require.resolve('swagger-ui-dist'); | ||||||
|  |         log.info(`[DEBUG] swagger-ui-dist main module at: ${swaggerDistPath}`); | ||||||
|  |     } catch (e) { | ||||||
|  |         log.error(`[DEBUG] Error finding swagger-ui-dist: ${e}`); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     app.use( |     app.use( | ||||||
|         "/etapi/docs/", |         "/etapi/docs/", | ||||||
|         swaggerUi.serveFiles(etapiDocument), |         (req, res, next) => { | ||||||
|  |             log.info(`[DEBUG] Request to /etapi/docs/: ${req.method} ${req.url}`); | ||||||
|  |             // Temporarily disable ASAR for swagger-ui file access | ||||||
|  |             const originalNoAsar = process.noAsar; | ||||||
|  |             process.noAsar = true; | ||||||
|  |              | ||||||
|  |             // Restore ASAR setting after response | ||||||
|  |             res.on('finish', () => { | ||||||
|  |                 process.noAsar = originalNoAsar; | ||||||
|  |             }); | ||||||
|  |              | ||||||
|  |             next(); | ||||||
|  |         }, | ||||||
|  |         swaggerUi.serve, | ||||||
|         swaggerUi.setup(etapiDocument, { |         swaggerUi.setup(etapiDocument, { | ||||||
|             explorer: true, |             explorer: true, | ||||||
|             customSiteTitle: "TriliumNext ETAPI Documentation" |             customSiteTitle: "TriliumNext ETAPI Documentation" | ||||||
| @@ -21,7 +107,19 @@ export default function register(app: Application) { | |||||||
|  |  | ||||||
|     app.use( |     app.use( | ||||||
|         "/api/docs/", |         "/api/docs/", | ||||||
|         swaggerUi.serveFiles(apiDocument), |         (req, res, next) => { | ||||||
|  |             // Temporarily disable ASAR for swagger-ui file access | ||||||
|  |             const originalNoAsar = process.noAsar; | ||||||
|  |             process.noAsar = true; | ||||||
|  |              | ||||||
|  |             // Restore ASAR setting after response | ||||||
|  |             res.on('finish', () => { | ||||||
|  |                 process.noAsar = originalNoAsar; | ||||||
|  |             }); | ||||||
|  |              | ||||||
|  |             next(); | ||||||
|  |         }, | ||||||
|  |         swaggerUi.serve, | ||||||
|         swaggerUi.setup(apiDocument, { |         swaggerUi.setup(apiDocument, { | ||||||
|             explorer: true, |             explorer: true, | ||||||
|             customSiteTitle: "TriliumNext Internal API Documentation" |             customSiteTitle: "TriliumNext Internal API Documentation" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user