@@ -2,7 +2,6 @@ import { BrowserWindow, clipboard } from "electron";
22import { IpcHandler } from "../@core/decorators/ipc-handler.js" ;
33import { getWindow as getWindows } from "../@core/control-window/receive.js" ;
44import { TParamOnInit } from "../@core/types/ipc-handler.js" ;
5- import { ResourcesService } from "../resources/services/resources.js" ;
65import { CryptoService } from "../crypto/service.js" ;
76import {
87 ipcMainHandle ,
@@ -14,15 +13,13 @@ import {
1413 getElectronStorage ,
1514 deleteFromElectronStorage ,
1615} from "../$shared/store.js" ;
16+ import { restApi } from "../config.js" ;
1717
1818@IpcHandler ( )
1919export class MasterKeyIpc {
2020 masterKeyWindow : BrowserWindow | undefined ;
2121
22- constructor (
23- private resourcesService : ResourcesService ,
24- private cryptoService : CryptoService
25- ) { }
22+ constructor ( private cryptoService : CryptoService ) { }
2623
2724 onInit ( { getWindow } : TParamOnInit < TWindows [ "masterKey" ] > ) : void {
2825 const masterKeyWindow = getWindow ( "window:master-key" ) ;
@@ -50,21 +47,43 @@ export class MasterKeyIpc {
5047 } ) ;
5148 }
5249
50+ private cacheResources ( ) : TResource [ ] | undefined {
51+ let resources : TResource [ ] | undefined = undefined ;
52+ const cacheResponse = getElectronStorage ( "response" ) ;
53+
54+ if ( cacheResponse !== undefined ) {
55+ resources =
56+ cacheResponse [
57+ `${ restApi . urls . base } ${ restApi . urls . baseApi } ${ restApi . urls . resources . base } `
58+ ] ;
59+ }
60+
61+ if ( resources !== undefined ) {
62+ return resources ;
63+ }
64+
65+ return undefined ;
66+ }
67+
5368 private ipcCopyMasterKey ( ) : void {
5469 ipcMainHandle ( "copyMasterKey" , async ( payload ) => {
5570 if ( payload !== undefined ) {
56- const resource = await this . resourcesService . byId ( payload . id ) ;
71+ const cacheResources = this . cacheResources ( ) ;
72+ const foundUser =
73+ cacheResources !== undefined
74+ ? cacheResources . find ( ( res ) => res . id + "" === payload . id )
75+ : undefined ;
5776 const masterKey = getElectronStorage ( "masterKey" ) ;
5877
5978 if (
6079 masterKey !== undefined &&
61- resource !== undefined &&
62- resource . salt !== null
80+ foundUser !== undefined &&
81+ foundUser . salt !== null
6382 ) {
6483 const encryptedVault = await this . cryptoService . decrypt ( masterKey , {
65- iv : resource . iv ,
66- salt : resource . salt ,
67- encryptedData : resource . key ,
84+ iv : foundUser . iv ,
85+ salt : foundUser . salt ,
86+ encryptedData : foundUser . key ,
6887 } ) ;
6988 clipboard . writeText ( encryptedVault ) ;
7089
0 commit comments