|
@@ -9,6 +9,7 @@ const router = express.Router();
|
|
|
|
|
|
|
|
const helmet = require('helmet');
|
|
const helmet = require('helmet');
|
|
|
|
|
|
|
|
|
|
+const ErrorV3 = require('../../models/vo/error-apiv3');
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -42,9 +43,14 @@ module.exports = (crowi) => {
|
|
|
* type: object
|
|
* type: object
|
|
|
*/
|
|
*/
|
|
|
router.get('/indices', helmet.noCache(), accessTokenParser, loginRequired, adminRequired, async(req, res) => {
|
|
router.get('/indices', helmet.noCache(), accessTokenParser, loginRequired, adminRequired, async(req, res) => {
|
|
|
|
|
+ const { searchService } = crowi;
|
|
|
|
|
+
|
|
|
|
|
+ if (!searchService.isConfigured) {
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3('SearchService is not configured', 'search-service-unconfigured'), 503);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
- const search = crowi.getSearcher();
|
|
|
|
|
- const info = await search.getInfoForAdmin();
|
|
|
|
|
|
|
+ const info = await searchService.getInfoForAdmin();
|
|
|
return res.status(200).send({ info });
|
|
return res.status(200).send({ info });
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
@@ -65,9 +71,14 @@ module.exports = (crowi) => {
|
|
|
* description: Successfully connected
|
|
* description: Successfully connected
|
|
|
*/
|
|
*/
|
|
|
router.post('/connection', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
|
|
router.post('/connection', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
|
|
|
|
|
+ const { searchService } = crowi;
|
|
|
|
|
+
|
|
|
|
|
+ if (!searchService.isConfigured) {
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3('SearchService is not configured', 'search-service-unconfigured'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
- const search = crowi.getSearcher();
|
|
|
|
|
- await search.initClient();
|
|
|
|
|
|
|
+ await searchService.initClient();
|
|
|
return res.status(200).send();
|
|
return res.status(200).send();
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
@@ -106,24 +117,31 @@ module.exports = (crowi) => {
|
|
|
router.put('/indices', accessTokenParser, loginRequired, adminRequired, csrf, validatorForPutIndices, ApiV3FormValidator, async(req, res) => {
|
|
router.put('/indices', accessTokenParser, loginRequired, adminRequired, csrf, validatorForPutIndices, ApiV3FormValidator, async(req, res) => {
|
|
|
const operation = req.body.operation;
|
|
const operation = req.body.operation;
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- const search = crowi.getSearcher();
|
|
|
|
|
|
|
+ const { searchService } = crowi;
|
|
|
|
|
+
|
|
|
|
|
+ if (!searchService.isConfigured) {
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3('SearchService is not configured', 'search-service-unconfigured'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!searchService.isReachable) {
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3('SearchService is not reachable', 'search-service-unreachable'));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ try {
|
|
|
switch (operation) {
|
|
switch (operation) {
|
|
|
case 'normalize':
|
|
case 'normalize':
|
|
|
// wait the processing is terminated
|
|
// wait the processing is terminated
|
|
|
- await search.normalizeIndices();
|
|
|
|
|
|
|
+ await searchService.normalizeIndices();
|
|
|
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
|
|
|
- search.rebuildIndex();
|
|
|
|
|
|
|
+ searchService.rebuildIndex();
|
|
|
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}`);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
- return res.apiv3Err(err);
|
|
|
|
|
|
|
+ return res.apiv3Err(err, 503);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|