feat(ui/clients): add search, reindex in client
This commit is contained in:
parent
fd46d7b816
commit
9510d6e730
3 changed files with 51 additions and 7 deletions
|
@ -14,6 +14,7 @@ export const filePathQuery = "fp";
|
|||
export const listDirQuery = "dp";
|
||||
export const shareIDQuery = "shid";
|
||||
export const shareDirQuery = "shdir";
|
||||
export const keywordQuery = "k";
|
||||
// TODO: get timeout from server
|
||||
|
||||
function translateResp(resp: Response<any>): Response<any> {
|
||||
|
@ -236,5 +237,23 @@ export class FilesClient extends BaseClient {
|
|||
method: "get",
|
||||
url,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
search = (keyword: string): Promise<Response> => {
|
||||
return this.do({
|
||||
method: "get",
|
||||
url: `${this.url}/v1/fs/search`,
|
||||
params: {
|
||||
[keywordQuery]: keyword,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
reindex = (): Promise<Response> => {
|
||||
return this.do({
|
||||
method: "put",
|
||||
url: `${this.url}/v1/fs/reindex`,
|
||||
data: {},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
ListSharingsResp,
|
||||
ListSharingIDsResp,
|
||||
GetSharingDirResp,
|
||||
SearchItemsResp,
|
||||
IFilesClient,
|
||||
} from "./";
|
||||
|
||||
|
@ -34,6 +35,8 @@ export interface FilesClientResps {
|
|||
isSharingMockResp?: Response;
|
||||
generateHashMockResp?: Response;
|
||||
downloadMockResp: Response;
|
||||
searchMockResp: Response<SearchItemsResp>;
|
||||
reindexMockResp: Response;
|
||||
}
|
||||
|
||||
const sharingIDs = new Map<string, string>();
|
||||
|
@ -132,6 +135,18 @@ export const resps = {
|
|||
],
|
||||
},
|
||||
},
|
||||
searchMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {
|
||||
results: ["mock_search_result1", "mock_search_result2"],
|
||||
},
|
||||
},
|
||||
reindexMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {},
|
||||
},
|
||||
deleteUploadingMockResp: { status: 200, statusText: "", data: {} },
|
||||
addSharingMockResp: { status: 200, statusText: "", data: {} },
|
||||
deleteSharingMockResp: { status: 200, statusText: "", data: {} },
|
||||
|
@ -263,6 +278,14 @@ export class MockFilesClient {
|
|||
download = (url: string): Promise<Response> => {
|
||||
return this.wrapPromise(this.resps.downloadMockResp);
|
||||
};
|
||||
|
||||
search = (keyword: string): Promise<Response> => {
|
||||
return this.wrapPromise(this.resps.searchMockResp);
|
||||
};
|
||||
|
||||
reindex = (): Promise<Response> => {
|
||||
return this.wrapPromise(this.resps.reindexMockResp);
|
||||
};
|
||||
}
|
||||
|
||||
// JestFilesClient supports jest function mockings
|
||||
|
@ -291,15 +314,11 @@ export class JestFilesClient {
|
|||
deleteUploading = jest
|
||||
.fn()
|
||||
.mockReturnValue(makePromise(resps.deleteUploadingMockResp));
|
||||
addSharing = jest
|
||||
.fn()
|
||||
.mockReturnValue(makePromise(resps.addSharingMockResp));
|
||||
addSharing = jest.fn().mockReturnValue(makePromise(resps.addSharingMockResp));
|
||||
deleteSharing = jest
|
||||
.fn()
|
||||
.mockReturnValue(makePromise(resps.deleteSharingMockResp));
|
||||
isSharing = jest
|
||||
.fn()
|
||||
.mockReturnValue(makePromise(resps.isSharingMockResp));
|
||||
isSharing = jest.fn().mockReturnValue(makePromise(resps.isSharingMockResp));
|
||||
listSharings = jest
|
||||
.fn()
|
||||
.mockReturnValue(makePromise(resps.listSharingsMockResp));
|
||||
|
@ -313,6 +332,8 @@ export class JestFilesClient {
|
|||
.fn()
|
||||
.mockReturnValue(makePromise(resps.generateHashMockResp));
|
||||
download = jest.fn().mockReturnValue(makePromise(resps.downloadMockResp));
|
||||
search = jest.fn().mockReturnValue(makePromise(resps.searchMockResp));
|
||||
reindex = jest.fn().mockReturnValue(makePromise(resps.reindexMockResp));
|
||||
}
|
||||
|
||||
export const NewMockFilesClient = (url: string): IFilesClient => {
|
||||
|
|
|
@ -93,6 +93,10 @@ export interface GetSharingDirResp {
|
|||
sharingDir: string;
|
||||
}
|
||||
|
||||
export interface SearchItemsResp {
|
||||
results: string[];
|
||||
}
|
||||
|
||||
export interface ClientConfig {
|
||||
siteName: string;
|
||||
siteDesc: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue