Skip to content

Commit

Permalink
feat(service/storage): add keys route
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Nov 13, 2022
1 parent 93d9418 commit 46fb970
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/nanoservice/storage/src/route/keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {config, logger} from '../lib/config.js';
import {nanoServer} from '../lib/nano-server.js';
import {storageProvider} from '../lib/storage-provider.js';

import type {AlwatrConnection} from '@alwatr/nano-server';

nanoServer.route('GET', '/keys', getStorageKeys);

async function getStorageKeys(connection: AlwatrConnection): Promise<void> {
logger.logMethod('getStorageKeys');

const token = connection.requireToken(config.token);
if (token == null) return;

const params = connection.requireQueryParams<{storage: string, id: string}>(['storage']);
if (params == null) return;

const storage = storageProvider.get({name: params.storage});

connection.reply({
ok: true,
data: {keys: storage.keys},
});
}

0 comments on commit 46fb970

Please sign in to comment.