55 * 2.0.
66 */
77
8+ import { schema } from '@kbn/config-schema' ;
89import { IRouter , IScopedClusterClient } from 'kibana/server' ;
9- import { MAX_FILE_SIZE_BYTES , IngestPipelineWrapper , Mappings , Settings } from '../common' ;
10+ import {
11+ MAX_FILE_SIZE_BYTES ,
12+ IngestPipelineWrapper ,
13+ InputData ,
14+ Mappings ,
15+ Settings ,
16+ } from '../common' ;
1017import { wrapError } from './error_wrapper' ;
11- import { InputData , importDataProvider } from './import_data' ;
18+ import { analyzeFile } from './analyze_file' ;
19+ import { importDataProvider } from './import_data' ;
1220
1321import { updateTelemetry } from './telemetry' ;
14- import { importFileBodySchema , importFileQuerySchema } from './schemas' ;
22+ import { analyzeFileQuerySchema , importFileBodySchema , importFileQuerySchema } from './schemas' ;
1523
1624function importData (
1725 client : IScopedClusterClient ,
@@ -30,6 +38,44 @@ function importData(
3038 * Routes for the file upload.
3139 */
3240export function fileUploadRoutes ( router : IRouter ) {
41+ /**
42+ * @apiGroup FileDataVisualizer
43+ *
44+ * @api {post } /api/file_upload/analyze_file Analyze file data
45+ * @apiName AnalyzeFile
46+ * @apiDescription Performs analysis of the file data.
47+ *
48+ * @apiSchema (query) analyzeFileQuerySchema
49+ */
50+ router . post (
51+ {
52+ path : '/api/file_upload/analyze_file' ,
53+ validate : {
54+ body : schema . any ( ) ,
55+ query : analyzeFileQuerySchema ,
56+ } ,
57+ options : {
58+ body : {
59+ accepts : [ 'text/*' , 'application/json' ] ,
60+ maxBytes : MAX_FILE_SIZE_BYTES ,
61+ } ,
62+ tags : [ 'access:fileUpload:analyzeFile' ] ,
63+ } ,
64+ } ,
65+ async ( context , request , response ) => {
66+ try {
67+ const result = await analyzeFile (
68+ context . core . elasticsearch . client ,
69+ request . body ,
70+ request . query
71+ ) ;
72+ return response . ok ( { body : result } ) ;
73+ } catch ( e ) {
74+ return response . customError ( wrapError ( e ) ) ;
75+ }
76+ }
77+ ) ;
78+
3379 /**
3480 * @apiGroup FileDataVisualizer
3581 *
0 commit comments