Add the API for search files (#15605)
* Adding search files api * Fixing golangci-lint * Adding bulk-indexing and improving a bit the name indexing for bleve and elasticsearch * Add content extraction config migration * Fixing a problem with document extraction * Unapplying certain changes moved to other PR * Fixing tests * Making extract content app migration a private method * Addressing PR review comments * Addressing PR review comments * Adding feature flag * Removing debug string * Fixing imports * Fixing linting errors * Do not migrate the config if the feature flag is not enabled * Fix tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
074a8e5fd9
Коммит
85293fcf41
75
api4/file.go
75
api4/file.go
@@ -60,6 +60,8 @@ func (api *API) InitFile() {
|
||||
api.BaseRoutes.File.Handle("/preview", api.ApiSessionRequiredTrustRequester(getFilePreview)).Methods("GET")
|
||||
api.BaseRoutes.File.Handle("/info", api.ApiSessionRequired(getFileInfo)).Methods("GET")
|
||||
|
||||
api.BaseRoutes.Team.Handle("/files/search", api.ApiSessionRequiredDisableWhenBusy(searchFiles)).Methods("POST")
|
||||
|
||||
api.BaseRoutes.PublicFile.Handle("", api.ApiHandler(getPublicFile)).Methods("GET")
|
||||
|
||||
}
|
||||
@@ -725,3 +727,76 @@ func writeFileResponse(filename string, contentType string, contentSize int64, l
|
||||
|
||||
http.ServeContent(w, r, filename, lastModification, fileReader)
|
||||
}
|
||||
|
||||
func searchFiles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireTeamId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.Config().FeatureFlags.FilesSearch {
|
||||
c.Err = model.NewAppError("searchFiles", "api.post.search_files.not_implemented.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
params, jsonErr := model.SearchParameterFromJson(r.Body)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchFiles", "api.post.search_files.invalid_body.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if params.Terms == nil || *params.Terms == "" {
|
||||
c.SetInvalidParam("terms")
|
||||
return
|
||||
}
|
||||
terms := *params.Terms
|
||||
|
||||
timeZoneOffset := 0
|
||||
if params.TimeZoneOffset != nil {
|
||||
timeZoneOffset = *params.TimeZoneOffset
|
||||
}
|
||||
|
||||
isOrSearch := false
|
||||
if params.IsOrSearch != nil {
|
||||
isOrSearch = *params.IsOrSearch
|
||||
}
|
||||
|
||||
page := 0
|
||||
if params.Page != nil {
|
||||
page = *params.Page
|
||||
}
|
||||
|
||||
perPage := 60
|
||||
if params.PerPage != nil {
|
||||
perPage = *params.PerPage
|
||||
}
|
||||
|
||||
includeDeletedChannels := false
|
||||
if params.IncludeDeletedChannels != nil {
|
||||
includeDeletedChannels = *params.IncludeDeletedChannels
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
results, err := c.App.SearchFilesInTeamForUser(terms, c.App.Session().UserId, c.Params.TeamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage)
|
||||
|
||||
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||
metrics := c.App.Metrics()
|
||||
if metrics != nil {
|
||||
metrics.IncrementFilesSearchCounter()
|
||||
metrics.ObserveFilesSearchDuration(elapsedTime)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Write([]byte(results.ToJson()))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user