mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	in this case using "{}" allows all primitive values, which seems to be what is required here.
so let's disable the rule "@typescript-eslint/no-empty-object-type" for this line
		
	
			
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { ipcMain } from "electron";
 | 
						|
import type { Application } from "express";
 | 
						|
 | 
						|
interface Response {
 | 
						|
    statusCode: number;
 | 
						|
    getHeader: (name: string) => string;
 | 
						|
    setHeader: (name: string, value: string) => Response;
 | 
						|
    header: (name: string, value: string) => Response;
 | 
						|
    status: (statusCode: number) => Response;
 | 
						|
    send: (obj: {}) => void; // eslint-disable-line @typescript-eslint/no-empty-object-type
 | 
						|
}
 | 
						|
 | 
						|
function init(app: Application) {
 | 
						|
    ipcMain.on("server-request", (event, arg) => {
 | 
						|
        const req = {
 | 
						|
            url: arg.url,
 | 
						|
            method: arg.method,
 | 
						|
            body: arg.data,
 | 
						|
            headers: arg.headers,
 | 
						|
            session: {
 | 
						|
                loggedIn: true
 | 
						|
            }
 | 
						|
        };
 | 
						|
 | 
						|
        const respHeaders: Record<string, string> = {};
 | 
						|
 | 
						|
        const res: Response = {
 | 
						|
            statusCode: 200,
 | 
						|
            getHeader: (name) => respHeaders[name],
 | 
						|
            setHeader: (name, value) => {
 | 
						|
                respHeaders[name] = value.toString();
 | 
						|
                return res;
 | 
						|
            },
 | 
						|
            header: (name, value) => {
 | 
						|
                respHeaders[name] = value.toString();
 | 
						|
                return res;
 | 
						|
            },
 | 
						|
            status: (statusCode) => {
 | 
						|
                res.statusCode = statusCode;
 | 
						|
                return res;
 | 
						|
            },
 | 
						|
            send: (obj) => {
 | 
						|
                event.sender.send("server-response", {
 | 
						|
                    url: arg.url,
 | 
						|
                    method: arg.method,
 | 
						|
                    requestId: arg.requestId,
 | 
						|
                    statusCode: res.statusCode,
 | 
						|
                    headers: respHeaders,
 | 
						|
                    body: obj
 | 
						|
                });
 | 
						|
            }
 | 
						|
        };
 | 
						|
 | 
						|
        return app._router.handle(req, res, () => {});
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
export default init;
 |