aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/SearchManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/ApiManagers/SearchManager.ts')
-rw-r--r--src/server/ApiManagers/SearchManager.ts41
1 files changed, 14 insertions, 27 deletions
diff --git a/src/server/ApiManagers/SearchManager.ts b/src/server/ApiManagers/SearchManager.ts
index 0e794fed6..ccd0896bd 100644
--- a/src/server/ApiManagers/SearchManager.ts
+++ b/src/server/ApiManagers/SearchManager.ts
@@ -4,9 +4,10 @@ import { Search } from "../Search";
const findInFiles = require('find-in-files');
import * as path from 'path';
import { pathToDirectory, Directory } from "./UploadManager";
-import { command_line, addBeforeExitHandler } from "../ActionUtilities";
+import { command_line } from "../ActionUtilities";
import request = require('request-promise');
-import { red, green, yellow, cyan } from "colors";
+import { red } from "colors";
+import RouteSubscriber from "../RouteSubscriber";
export class SearchManager extends ApiManager {
@@ -14,14 +15,16 @@ export class SearchManager extends ApiManager {
register({
method: Method.GET,
- subscription: "/startSolr",
- onValidation: async ({ res }) => res.send((await SolrManager.SetRunning(true)) ? "Successfully started Solr!" : "Uh oh! Check the console for the error that occurred while starting Solr")
- });
-
- register({
- method: Method.GET,
- subscription: "/stopSolr",
- onValidation: async ({ res }) => res.send((await SolrManager.SetRunning(false)) ? "Successfully stopped Solr!" : "Uh oh! Check the console for the error that occurred while stopping Solr")
+ subscription: new RouteSubscriber("solr").add("action"),
+ onValidation: async ({ req, res }) => {
+ const { action } = req.params;
+ if (["start", "stop"].includes(action)) {
+ const status = req.params.action === "start";
+ const success = await SolrManager.SetRunning(status);
+ console.log(success ? `Successfully ${status ? "started" : "stopped"} Solr!` : `Uh oh! Check the console for the error that occurred while ${status ? "starting" : "stopping"} Solr`);
+ }
+ res.redirect("/home");
+ }
});
register({
@@ -65,30 +68,14 @@ export class SearchManager extends ApiManager {
export namespace SolrManager {
- export async function initializeSolr() {
- console.log(cyan("\nInspecting Solr status..."));
- try {
- await request("http://localhost:8983");
- console.log(green('Solr already running\n'));
- } catch (e) {
- console.log(cyan('Initializing Solr...'));
- await SolrManager.SetRunning(true);
- } finally {
- addBeforeExitHandler(async () => SolrManager.SetRunning(false));
- }
- }
-
export async function SetRunning(status: boolean): Promise<boolean> {
const args = status ? "start" : "stop -p 8983";
- console.log(`Solr management: trying to ${args}`);
try {
+ console.log(`Solr management: trying to ${args}`);
console.log(await command_line(`solr.cmd ${args}`, "../../solr-8.1.1/bin"));
return true;
} catch (e) {
console.log(red(`Solr management error: unable to ${args}`));
- if (status) {
- process.exit(0);
- }
return false;
}
}