implement search service

This commit is contained in:
Kyle Spearrin 2018-08-13 14:38:04 -04:00
parent ee73f9a51a
commit 314cef78fd
8 changed files with 25 additions and 26 deletions

2
jslib

@ -1 +1 @@
Subproject commit 4ca7a9709e9ccd0e67ce09309ae605f2057bf089
Subproject commit bdb2efd77054d28a686dcf50a849ffbf62a996d6

5
package-lock.json generated
View File

@ -3209,6 +3209,11 @@
"yallist": "^2.1.2"
}
},
"lunr": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.1.tgz",
"integrity": "sha1-ETYWorYC3cEJMqe/ik5uV+v+zfI="
},
"make-dir": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",

View File

@ -48,7 +48,7 @@
"@types/form-data": "^2.2.1",
"@types/inquirer": "^0.0.42",
"@types/lowdb": "^1.0.1",
"@types/lunr": "^2.1.5",
"@types/lunr": "^2.1.6",
"@types/node": "^10.0.8",
"@types/node-fetch": "^1.6.9",
"@types/node-forge": "^0.7.1",
@ -69,6 +69,7 @@
"form-data": "2.3.2",
"inquirer": "5.2.0",
"lowdb": "1.0.0",
"lunr": "2.3.1",
"node-fetch": "2.1.2",
"node-forge": "0.7.1",
"papaparse": "4.3.5"

View File

@ -23,6 +23,7 @@ import { LowdbStorageService } from 'jslib/services/lowdbStorage.service';
import { NodeApiService } from 'jslib/services/nodeApi.service';
import { NodeCryptoFunctionService } from 'jslib/services/nodeCryptoFunction.service';
import { PasswordGenerationService } from 'jslib/services/passwordGeneration.service';
import { SearchService } from 'jslib/services/search.service';
import { SettingsService } from 'jslib/services/settings.service';
import { SyncService } from 'jslib/services/sync.service';
import { TokenService } from 'jslib/services/token.service';
@ -56,6 +57,7 @@ export class Main {
auditService: AuditService;
importService: ImportService;
exportService: ExportService;
searchService: SearchService;
cryptoFunctionService: NodeCryptoFunctionService;
authService: AuthService;
program: Program;
@ -89,13 +91,15 @@ export class Main {
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
this.settingsService = new SettingsService(this.userService, this.storageService);
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
this.apiService, this.storageService, this.i18nService, this.platformUtilsService);
this.apiService, this.storageService, this.i18nService, this.platformUtilsService, null);
this.folderService = new FolderService(this.cryptoService, this.userService, this.apiService,
this.storageService, this.i18nService, this.cipherService);
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
this.i18nService);
this.searchService = new SearchService(this.cipherService, this.platformUtilsService);
this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService,
this.cryptoService, this.platformUtilsService, this.storageService, this.messagingService, null);
this.cryptoService, this.platformUtilsService, this.storageService, this.messagingService,
this.searchService, null);
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
this.storageService, this.messagingService, async (expired: boolean) => await this.logout());

View File

@ -8,6 +8,7 @@ import { CipherService } from 'jslib/abstractions/cipher.service';
import { CollectionService } from 'jslib/abstractions/collection.service';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { FolderService } from 'jslib/abstractions/folder.service';
import { SearchService } from 'jslib/abstractions/search.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { TotpService } from 'jslib/abstractions/totp.service';
import { UserService } from 'jslib/abstractions/user.service';
@ -43,7 +44,8 @@ export class GetCommand {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private totpService: TotpService,
private auditService: AuditService, private cryptoService: CryptoService,
private tokenService: TokenService, private userService: UserService) { }
private tokenService: TokenService, private userService: UserService,
private searchService: SearchService) { }
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
if (id != null) {
@ -87,7 +89,7 @@ export class GetCommand {
}
} else if (id.trim() !== '') {
let ciphers = await this.cipherService.getAllDecrypted();
ciphers = CliUtils.searchCiphers(ciphers, id);
ciphers = this.searchService.searchCiphersBasic(ciphers, id);
if (ciphers.length > 1) {
return Response.multipleResults(ciphers.map((c) => c.id));
}

View File

@ -3,6 +3,7 @@ import * as program from 'commander';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CollectionService } from 'jslib/abstractions/collection.service';
import { FolderService } from 'jslib/abstractions/folder.service';
import { SearchService } from 'jslib/abstractions/search.service';
import { UserService } from 'jslib/abstractions/user.service';
import { Response } from '../models/response';
@ -16,7 +17,8 @@ import { CliUtils } from '../utils';
export class ListCommand {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private userService: UserService) { }
private collectionService: CollectionService, private userService: UserService,
private searchService: SearchService) { }
async run(object: string, cmd: program.Command): Promise<Response> {
switch (object.toLowerCase()) {
@ -75,7 +77,7 @@ export class ListCommand {
}
if (cmd.search != null && cmd.search.trim() !== '') {
ciphers = CliUtils.searchCiphers(ciphers, cmd.search);
ciphers = this.searchService.searchCiphersBasic(ciphers, cmd.search);
}
const res = new ListResponse(ciphers.map((o) => new CipherResponse(o)));

View File

@ -225,7 +225,7 @@ export class Program {
.action(async (object, cmd) => {
await this.exitIfLocked();
const command = new ListCommand(this.main.cipherService, this.main.folderService,
this.main.collectionService, this.main.userService);
this.main.collectionService, this.main.userService, this.main.searchService);
const response = await command.run(object, cmd);
this.processResponse(response);
});
@ -271,7 +271,8 @@ export class Program {
await this.exitIfLocked();
const command = new GetCommand(this.main.cipherService, this.main.folderService,
this.main.collectionService, this.main.totpService, this.main.auditService,
this.main.cryptoService, this.main.tokenService, this.main.userService);
this.main.cryptoService, this.main.tokenService, this.main.userService,
this.main.searchService);
const response = await command.run(object, id, cmd);
this.processResponse(response);
});

View File

@ -102,22 +102,6 @@ export class CliUtils {
});
}
static searchCiphers(ciphers: CipherView[], search: string) {
search = search.toLowerCase();
return ciphers.filter((c) => {
if (c.name != null && c.name.toLowerCase().indexOf(search) > -1) {
return true;
}
if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(search) > -1) {
return true;
}
if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(search) > -1) {
return true;
}
return false;
});
}
static searchFolders(folders: FolderView[], search: string) {
search = search.toLowerCase();
return folders.filter((f) => {