From 42819961b76c7becb85e9f5482df6d56a548c310 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 15 May 2018 21:22:39 -0400 Subject: [PATCH] get last sync --- src/commands/get.command.ts | 16 +++++++++++++++- src/program.ts | 9 ++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index 225bdccea1..b00da4fba7 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -5,6 +5,7 @@ import { CipherType } from 'jslib/enums/cipherType'; import { CipherService } from 'jslib/abstractions/cipher.service'; import { CollectionService } from 'jslib/abstractions/collection.service'; import { FolderService } from 'jslib/abstractions/folder.service'; +import { SyncService } from 'jslib/abstractions/sync.service'; import { TotpService } from 'jslib/abstractions/totp.service'; import { Response } from '../models/response'; @@ -26,9 +27,14 @@ import { SecureNote } from '../models/secureNote'; export class GetCommand { constructor(private cipherService: CipherService, private folderService: FolderService, - private collectionService: CollectionService, private totpService: TotpService) { } + private collectionService: CollectionService, private totpService: TotpService, + private syncService: SyncService) { } async run(object: string, id: string, cmd: program.Command): Promise { + if (id == null && object !== 'lastsync') { + return Response.badRequest('`id` argument is required.'); + } + switch (object.toLowerCase()) { case 'item': return await this.getCipher(id); @@ -40,6 +46,8 @@ export class GetCommand { return await this.getCollection(id); case 'template': return await this.getTemplate(id); + case 'lastsync': + return await this.getLastSync(); default: return Response.badRequest('Unknown object.'); } @@ -139,4 +147,10 @@ export class GetCommand { const res = new TemplateResponse(template); return Response.success(res); } + + private async getLastSync() { + const lastSyncDate = await this.syncService.getLastSync(); + const res = new StringResponse(lastSyncDate == null ? null : lastSyncDate.toISOString()); + return Response.success(res); + } } diff --git a/src/program.ts b/src/program.ts index 700a7dfc4b..9efe241aab 100644 --- a/src/program.ts +++ b/src/program.ts @@ -82,11 +82,11 @@ export class Program { }); program - .command('get ') + .command('get [id]') .description('Get an object.') .action(async (object, id, cmd) => { const command = new GetCommand(this.main.cipherService, this.main.folderService, - this.main.collectionService, this.main.totpService); + this.main.collectionService, this.main.totpService, this.main.syncService); const response = await command.run(object, id, cmd); this.processResponse(response, cmd); }); @@ -140,7 +140,10 @@ export class Program { if (response.data != null) { if (response.data.object === 'string') { - process.stdout.write((response.data as StringResponse).data); + const data = (response.data as StringResponse).data; + if (data != null) { + process.stdout.write(data); + } } else if (response.data.object === 'list') { this.printJson((response.data as ListResponse).data, cmd); } else if (response.data.object === 'template') {