get last sync
This commit is contained in:
parent
807cca2bd2
commit
42819961b7
|
@ -5,6 +5,7 @@ import { CipherType } from 'jslib/enums/cipherType';
|
||||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
import { CollectionService } from 'jslib/abstractions/collection.service';
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||||
|
import { SyncService } from 'jslib/abstractions/sync.service';
|
||||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||||
|
|
||||||
import { Response } from '../models/response';
|
import { Response } from '../models/response';
|
||||||
|
@ -26,9 +27,14 @@ import { SecureNote } from '../models/secureNote';
|
||||||
|
|
||||||
export class GetCommand {
|
export class GetCommand {
|
||||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
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<Response> {
|
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
|
||||||
|
if (id == null && object !== 'lastsync') {
|
||||||
|
return Response.badRequest('`id` argument is required.');
|
||||||
|
}
|
||||||
|
|
||||||
switch (object.toLowerCase()) {
|
switch (object.toLowerCase()) {
|
||||||
case 'item':
|
case 'item':
|
||||||
return await this.getCipher(id);
|
return await this.getCipher(id);
|
||||||
|
@ -40,6 +46,8 @@ export class GetCommand {
|
||||||
return await this.getCollection(id);
|
return await this.getCollection(id);
|
||||||
case 'template':
|
case 'template':
|
||||||
return await this.getTemplate(id);
|
return await this.getTemplate(id);
|
||||||
|
case 'lastsync':
|
||||||
|
return await this.getLastSync();
|
||||||
default:
|
default:
|
||||||
return Response.badRequest('Unknown object.');
|
return Response.badRequest('Unknown object.');
|
||||||
}
|
}
|
||||||
|
@ -139,4 +147,10 @@ export class GetCommand {
|
||||||
const res = new TemplateResponse(template);
|
const res = new TemplateResponse(template);
|
||||||
return Response.success(res);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,11 +82,11 @@ export class Program {
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('get <object> <id>')
|
.command('get <object> [id]')
|
||||||
.description('Get an object.')
|
.description('Get an object.')
|
||||||
.action(async (object, id, cmd) => {
|
.action(async (object, id, cmd) => {
|
||||||
const command = new GetCommand(this.main.cipherService, this.main.folderService,
|
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);
|
const response = await command.run(object, id, cmd);
|
||||||
this.processResponse(response, cmd);
|
this.processResponse(response, cmd);
|
||||||
});
|
});
|
||||||
|
@ -140,7 +140,10 @@ export class Program {
|
||||||
|
|
||||||
if (response.data != null) {
|
if (response.data != null) {
|
||||||
if (response.data.object === 'string') {
|
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') {
|
} else if (response.data.object === 'list') {
|
||||||
this.printJson((response.data as ListResponse).data, cmd);
|
this.printJson((response.data as ListResponse).data, cmd);
|
||||||
} else if (response.data.object === 'template') {
|
} else if (response.data.object === 'template') {
|
||||||
|
|
Loading…
Reference in New Issue