diff --git a/frontend/src/components/file-chooser/file-chooser.js b/frontend/src/components/file-chooser/file-chooser.js index f10740e95c3..62eff0cd1a4 100644 --- a/frontend/src/components/file-chooser/file-chooser.js +++ b/frontend/src/components/file-chooser/file-chooser.js @@ -2,7 +2,7 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Input } from 'reactstrap'; import { seafileAPI } from '../../utils/seafile-api'; -import { gettext, isPro } from '../../utils/constants'; +import { gettext, isPro, enableSeasearch, enableElasticsearch } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import toaster from '../toast'; import RepoInfo from '../../models/repo-info'; @@ -211,23 +211,23 @@ class FileChooser extends React.Component { }; sendRequest = (queryData, cancelToken) => { - seafileAPI.searchFiles(queryData, cancelToken).then(res => { - if (!res.data.total) { - this.setState({ - searchResults: [], - isResultGot: true - }); - this.source = null; - return; - } - - let items = this.formatResultItems(res.data.results); - this.setState({ - searchResults: items, - isResultGot: true + if (isPro && enableSeasearch && !enableElasticsearch) { + seafileAPI.aiSearchFiles(queryData, cancelToken).then(res => { + this.handleSearchResult(res); + }); + } else { + seafileAPI.searchFiles(queryData, cancelToken).then(res => { + this.handleSearchResult(res); }); - this.source = null; + } + }; + + handleSearchResult = (res) => { + this.setState({ + searchResults: res.data.total ? this.formatResultItems(res.data.results) : [], + isResultGot: true }); + this.source = null; }; cancelRequest = () => {