mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
implement search service
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 4ca7a9709e...bdb2efd770
5
package-lock.json
generated
5
package-lock.json
generated
@@ -3209,6 +3209,11 @@
|
|||||||
"yallist": "^2.1.2"
|
"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": {
|
"make-dir": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
"@types/form-data": "^2.2.1",
|
"@types/form-data": "^2.2.1",
|
||||||
"@types/inquirer": "^0.0.42",
|
"@types/inquirer": "^0.0.42",
|
||||||
"@types/lowdb": "^1.0.1",
|
"@types/lowdb": "^1.0.1",
|
||||||
"@types/lunr": "^2.1.5",
|
"@types/lunr": "^2.1.6",
|
||||||
"@types/node": "^10.0.8",
|
"@types/node": "^10.0.8",
|
||||||
"@types/node-fetch": "^1.6.9",
|
"@types/node-fetch": "^1.6.9",
|
||||||
"@types/node-forge": "^0.7.1",
|
"@types/node-forge": "^0.7.1",
|
||||||
@@ -69,6 +69,7 @@
|
|||||||
"form-data": "2.3.2",
|
"form-data": "2.3.2",
|
||||||
"inquirer": "5.2.0",
|
"inquirer": "5.2.0",
|
||||||
"lowdb": "1.0.0",
|
"lowdb": "1.0.0",
|
||||||
|
"lunr": "2.3.1",
|
||||||
"node-fetch": "2.1.2",
|
"node-fetch": "2.1.2",
|
||||||
"node-forge": "0.7.1",
|
"node-forge": "0.7.1",
|
||||||
"papaparse": "4.3.5"
|
"papaparse": "4.3.5"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { LowdbStorageService } from 'jslib/services/lowdbStorage.service';
|
|||||||
import { NodeApiService } from 'jslib/services/nodeApi.service';
|
import { NodeApiService } from 'jslib/services/nodeApi.service';
|
||||||
import { NodeCryptoFunctionService } from 'jslib/services/nodeCryptoFunction.service';
|
import { NodeCryptoFunctionService } from 'jslib/services/nodeCryptoFunction.service';
|
||||||
import { PasswordGenerationService } from 'jslib/services/passwordGeneration.service';
|
import { PasswordGenerationService } from 'jslib/services/passwordGeneration.service';
|
||||||
|
import { SearchService } from 'jslib/services/search.service';
|
||||||
import { SettingsService } from 'jslib/services/settings.service';
|
import { SettingsService } from 'jslib/services/settings.service';
|
||||||
import { SyncService } from 'jslib/services/sync.service';
|
import { SyncService } from 'jslib/services/sync.service';
|
||||||
import { TokenService } from 'jslib/services/token.service';
|
import { TokenService } from 'jslib/services/token.service';
|
||||||
@@ -56,6 +57,7 @@ export class Main {
|
|||||||
auditService: AuditService;
|
auditService: AuditService;
|
||||||
importService: ImportService;
|
importService: ImportService;
|
||||||
exportService: ExportService;
|
exportService: ExportService;
|
||||||
|
searchService: SearchService;
|
||||||
cryptoFunctionService: NodeCryptoFunctionService;
|
cryptoFunctionService: NodeCryptoFunctionService;
|
||||||
authService: AuthService;
|
authService: AuthService;
|
||||||
program: Program;
|
program: Program;
|
||||||
@@ -89,13 +91,15 @@ export class Main {
|
|||||||
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
|
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
|
||||||
this.settingsService = new SettingsService(this.userService, this.storageService);
|
this.settingsService = new SettingsService(this.userService, this.storageService);
|
||||||
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
|
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.folderService = new FolderService(this.cryptoService, this.userService, this.apiService,
|
||||||
this.storageService, this.i18nService, this.cipherService);
|
this.storageService, this.i18nService, this.cipherService);
|
||||||
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
|
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
|
||||||
this.i18nService);
|
this.i18nService);
|
||||||
|
this.searchService = new SearchService(this.cipherService, this.platformUtilsService);
|
||||||
this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService,
|
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.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
||||||
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
||||||
this.storageService, this.messagingService, async (expired: boolean) => await this.logout());
|
this.storageService, this.messagingService, async (expired: boolean) => await this.logout());
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { CipherService } from 'jslib/abstractions/cipher.service';
|
|||||||
import { CollectionService } from 'jslib/abstractions/collection.service';
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||||
|
import { SearchService } from 'jslib/abstractions/search.service';
|
||||||
import { TokenService } from 'jslib/abstractions/token.service';
|
import { TokenService } from 'jslib/abstractions/token.service';
|
||||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||||
import { UserService } from 'jslib/abstractions/user.service';
|
import { UserService } from 'jslib/abstractions/user.service';
|
||||||
@@ -43,7 +44,8 @@ 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 auditService: AuditService, private cryptoService: CryptoService,
|
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> {
|
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
@@ -87,7 +89,7 @@ export class GetCommand {
|
|||||||
}
|
}
|
||||||
} else if (id.trim() !== '') {
|
} else if (id.trim() !== '') {
|
||||||
let ciphers = await this.cipherService.getAllDecrypted();
|
let ciphers = await this.cipherService.getAllDecrypted();
|
||||||
ciphers = CliUtils.searchCiphers(ciphers, id);
|
ciphers = this.searchService.searchCiphersBasic(ciphers, id);
|
||||||
if (ciphers.length > 1) {
|
if (ciphers.length > 1) {
|
||||||
return Response.multipleResults(ciphers.map((c) => c.id));
|
return Response.multipleResults(ciphers.map((c) => c.id));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as program from 'commander';
|
|||||||
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 { SearchService } from 'jslib/abstractions/search.service';
|
||||||
import { UserService } from 'jslib/abstractions/user.service';
|
import { UserService } from 'jslib/abstractions/user.service';
|
||||||
|
|
||||||
import { Response } from '../models/response';
|
import { Response } from '../models/response';
|
||||||
@@ -16,7 +17,8 @@ import { CliUtils } from '../utils';
|
|||||||
|
|
||||||
export class ListCommand {
|
export class ListCommand {
|
||||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
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> {
|
async run(object: string, cmd: program.Command): Promise<Response> {
|
||||||
switch (object.toLowerCase()) {
|
switch (object.toLowerCase()) {
|
||||||
@@ -75,7 +77,7 @@ export class ListCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.search != null && cmd.search.trim() !== '') {
|
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)));
|
const res = new ListResponse(ciphers.map((o) => new CipherResponse(o)));
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ export class Program {
|
|||||||
.action(async (object, cmd) => {
|
.action(async (object, cmd) => {
|
||||||
await this.exitIfLocked();
|
await this.exitIfLocked();
|
||||||
const command = new ListCommand(this.main.cipherService, this.main.folderService,
|
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);
|
const response = await command.run(object, cmd);
|
||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
});
|
});
|
||||||
@@ -271,7 +271,8 @@ export class Program {
|
|||||||
await this.exitIfLocked();
|
await this.exitIfLocked();
|
||||||
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.auditService,
|
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);
|
const response = await command.run(object, id, cmd);
|
||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
});
|
});
|
||||||
|
|||||||
16
src/utils.ts
16
src/utils.ts
@@ -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) {
|
static searchFolders(folders: FolderView[], search: string) {
|
||||||
search = search.toLowerCase();
|
search = search.toLowerCase();
|
||||||
return folders.filter((f) => {
|
return folders.filter((f) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user