|
@@ -1,7 +1,10 @@
|
|
|
|
|
+import { SupportedAction } from '~/interfaces/activity';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
|
|
+import { generateAddActivityMiddleware } from '../../middlewares/add-activity';
|
|
|
import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
|
|
import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
const logger = loggerFactory('growi:routes:apiv3:search'); // eslint-disable-line no-unused-vars
|
|
const logger = loggerFactory('growi:routes:apiv3:search'); // eslint-disable-line no-unused-vars
|
|
|
|
|
|
|
|
const express = require('express');
|
|
const express = require('express');
|
|
@@ -23,6 +26,9 @@ module.exports = (crowi) => {
|
|
|
const loginRequired = require('../../middlewares/login-required')(crowi);
|
|
const loginRequired = require('../../middlewares/login-required')(crowi);
|
|
|
const adminRequired = require('../../middlewares/admin-required')(crowi);
|
|
const adminRequired = require('../../middlewares/admin-required')(crowi);
|
|
|
const csrf = require('../../middlewares/csrf')(crowi);
|
|
const csrf = require('../../middlewares/csrf')(crowi);
|
|
|
|
|
+ const addActivity = generateAddActivityMiddleware(crowi);
|
|
|
|
|
+
|
|
|
|
|
+ const activityEvent = crowi.event('activity');
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -114,7 +120,7 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
* 200:
|
|
|
* description: Return 200
|
|
* description: Return 200
|
|
|
*/
|
|
*/
|
|
|
- router.put('/indices', accessTokenParser, loginRequired, adminRequired, csrf, validatorForPutIndices, apiV3FormValidator, async(req, res) => {
|
|
|
|
|
|
|
+ router.put('/indices', accessTokenParser, loginRequired, adminRequired, csrf, addActivity, validatorForPutIndices, apiV3FormValidator, async(req, res) => {
|
|
|
const operation = req.body.operation;
|
|
const operation = req.body.operation;
|
|
|
|
|
|
|
|
const { searchService } = crowi;
|
|
const { searchService } = crowi;
|
|
@@ -131,10 +137,16 @@ module.exports = (crowi) => {
|
|
|
case 'normalize':
|
|
case 'normalize':
|
|
|
// wait the processing is terminated
|
|
// wait the processing is terminated
|
|
|
await searchService.normalizeIndices();
|
|
await searchService.normalizeIndices();
|
|
|
|
|
+
|
|
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_ADMIN_SEARCH_INDICES_NORMALIZE });
|
|
|
|
|
+
|
|
|
return res.status(200).send({ message: 'Operation is successfully processed.' });
|
|
return res.status(200).send({ message: 'Operation is successfully processed.' });
|
|
|
case 'rebuild':
|
|
case 'rebuild':
|
|
|
// NOT wait the processing is terminated
|
|
// NOT wait the processing is terminated
|
|
|
searchService.rebuildIndex();
|
|
searchService.rebuildIndex();
|
|
|
|
|
+
|
|
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_ADMIN_SEARCH_INDICES_REBUILD });
|
|
|
|
|
+
|
|
|
return res.status(200).send({ message: 'Operation is successfully requested.' });
|
|
return res.status(200).send({ message: 'Operation is successfully requested.' });
|
|
|
default:
|
|
default:
|
|
|
throw new Error(`Unimplemented operation: ${operation}`);
|
|
throw new Error(`Unimplemented operation: ${operation}`);
|