diff --git a/src/client/handlers/VaultsSecretsList.ts b/src/client/handlers/VaultsSecretsList.ts index c1e1dfbfa..5d4318c08 100644 --- a/src/client/handlers/VaultsSecretsList.ts +++ b/src/client/handlers/VaultsSecretsList.ts @@ -2,32 +2,29 @@ import type { DB } from '@matrixai/db'; import type { ClientRPCRequestParams, ClientRPCResponseResult, - SecretNameMessage, + SecretFilesList, VaultIdentifierMessage, } from '../types'; import type VaultManager from '../../vaults/VaultManager'; -import { ServerHandler } from '@matrixai/rpc'; +import { UnaryHandler } from '@matrixai/rpc'; import * as vaultsUtils from '../../vaults/utils'; import * as vaultsErrors from '../../vaults/errors'; -import * as vaultOps from '../../vaults/VaultOps'; +import { fileTree } from '@/vaults'; +import { ContentNode, TreeNode } from '@/vaults/types'; -class VaultsSecretsList extends ServerHandler< +class VaultsSecretsList extends UnaryHandler< { vaultManager: VaultManager; db: DB; }, ClientRPCRequestParams, - ClientRPCResponseResult + ClientRPCResponseResult > { - public async *handle( + public handle = async ( input: ClientRPCRequestParams, - _cancel, - _meta, - ctx, - ): AsyncGenerator> { - if (ctx.signal.aborted) throw ctx.signal.reason; + ): Promise> => { const { vaultManager, db } = this.container; - const secrets = await db.withTransactionF(async (tran) => { + return await db.withTransactionF(async (tran) => { const vaultIdFromName = await vaultManager.getVaultId( input.nameOrId, tran, @@ -40,18 +37,41 @@ class VaultsSecretsList extends ServerHandler< return await vaultManager.withVaults( [vaultId], async (vault) => { - return await vaultOps.listSecrets(vault); + const data = await vault.readF(async (fs) => { + const fileTreeGen = fileTree.globWalk({ + fs, + basePath: vault.vaultDataDir, // NOTE: check if this is correct + yieldStats: true, + yieldRoot: false, + yieldFiles: true, + yieldParents: true, + yieldDirectories: true, + }); + const data: Array = [] + const parserTransform = fileTree.parserTransformStreamFactory(); + const serializedStream = fileTree.serializerStreamFactory( + fs, + fileTreeGen, + false, + ) + const outputStream = serializedStream.pipeThrough(parserTransform); + for await (const output of outputStream) { + data.push(output) + } + return data + }); + + const files = data + .filter((v) => v instanceof Uint8Array) + .map((v) => Buffer.from(v as Uint8Array).toString()); + return { + secretFilesList: files, + }; }, tran, ); }); - for (const secret of secrets) { - if (ctx.signal.aborted) throw ctx.signal.reason; - yield { - secretName: secret, - }; - } - } + }; } export default VaultsSecretsList; diff --git a/src/client/types.ts b/src/client/types.ts index ee4055057..7fececd5a 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -301,6 +301,12 @@ type VaultsLatestVersionMessage = { // Secrets +type SecretFilesList = { + secretFilesList: Array; +} + +// NOTE: we used to use SecretNameMessage before. do we need to keep it? look into this. + type SecretNameMessage = { secretName: string; }; @@ -410,6 +416,7 @@ export type { VaultsScanMessage, VaultsVersionMessage, VaultsLatestVersionMessage, + SecretFilesList, SecretNameMessage, SecretIdentifierMessage, ContentMessage,