Skip to content

Commit

Permalink
(control) Move 'new crawl spec' to /node/:id/actions, out of /node/:i…
Browse files Browse the repository at this point in the history
…d/storage
  • Loading branch information
vlofgren committed Jan 15, 2024
1 parent b192373 commit f29a9d9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 76 deletions.
Expand Up @@ -62,9 +62,11 @@ public void register() {
redirectControl.renderRedirectAcknowledgement("Sideloading", "..")
);
Spark.post("/public/nodes/:id/actions/new-crawl", this::triggerNewCrawl,
redirectControl.renderRedirectAcknowledgement("Crawling", ".."));
redirectControl.renderRedirectAcknowledgement("Crawling", "..")
);
Spark.post("/public/nodes/:id/actions/recrawl", this::triggerAutoRecrawl,
redirectControl.renderRedirectAcknowledgement("Recrawling", ".."));
redirectControl.renderRedirectAcknowledgement("Recrawling", "..")
);
Spark.post("/public/nodes/:id/actions/process", this::triggerAutoProcess,
redirectControl.renderRedirectAcknowledgement("Processing", "..")
);
Expand All @@ -74,6 +76,9 @@ public void register() {
Spark.post("/public/nodes/:id/actions/restore-backup", this::triggerRestoreBackup,
redirectControl.renderRedirectAcknowledgement("Restoring", "..")
);
Spark.post("/public/nodes/:id/actions/new-crawl-specs", this::createNewSpecsAction,
redirectControl.renderRedirectAcknowledgement("Creating", "../actions?view=new-crawl")
);
}

public Object sideloadEncyclopedia(Request request, Response response) throws Exception {
Expand Down Expand Up @@ -215,4 +220,13 @@ private void changeActiveStorage(int nodeId, FileStorageType type, FileStorageId
}


private Object createNewSpecsAction(Request request, Response response) {
final String description = request.queryParams("description");
final String url = request.queryParams("url");
int nodeId = Integer.parseInt(request.params("id"));

executorClient.createCrawlSpecFromDownload(Context.fromRequest(request), nodeId, description, url);

return "";
}
}
Expand Up @@ -75,7 +75,6 @@ public void register() throws IOException {
var storageDetailsRenderer = rendererFactory.renderer("control/node/node-storage-details");
var configRenderer = rendererFactory.renderer("control/node/node-config");

var newSpecsFormRenderer = rendererFactory.renderer("control/node/node-new-specs-form");

Spark.get("/public/nodes", this::nodeListModel, nodeListRenderer::render);
Spark.get("/public/nodes/:id", this::nodeOverviewModel, overviewRenderer::render);
Expand All @@ -89,10 +88,6 @@ public void register() throws IOException {
Spark.post("/public/nodes/:id/process/:processBase/stop", this::stopProcess,
redirectControl.renderRedirectAcknowledgement("Stopping", "../..")
);
Spark.get("/public/nodes/:id/storage/new-specs", this::newSpecsModel, newSpecsFormRenderer::render);
Spark.post("/public/nodes/:id/storage/new-specs", this::createNewSpecsAction,
redirectControl.renderRedirectAcknowledgement("Creating", ".")
);

Spark.get("/public/nodes/:id/storage/:view", this::nodeStorageListModel, storageListRenderer::render);

Expand Down Expand Up @@ -168,26 +163,6 @@ public String redirectToOverview(Request request) {
return redirectToOverview(Integer.parseInt(request.params("id")));
}

private Object createNewSpecsAction(Request request, Response response) {
final String description = request.queryParams("description");
final String url = request.queryParams("url");
int nodeId = Integer.parseInt(request.params("id"));

executorClient.createCrawlSpecFromDownload(Context.fromRequest(request), nodeId, description, url);

return "";
}

private Object newSpecsModel(Request request, Response response) throws SQLException {
int nodeId = Integer.parseInt(request.params("id"));

return Map.of(
"tab", Map.of("storage", true),
"node", nodeConfigurationService.get(nodeId),
"view", Map.of("specs", true)
);
}

private Object nodeActorsModel(Request request, Response response) throws SQLException {
int nodeId = Integer.parseInt(request.params("id"));

Expand Down
@@ -0,0 +1,25 @@
<h1 class="my-3">Create New Specification</h1>

<div class="my-3 p-3 border bg-light">
<p>A crawling specification is a list of domain names to crawl.</p>
<p>
If you are just looking to test the software, feel free to use <a href="https://downloads.marginalia.nu/domain-list-test.txt">this
short list of marginalia-related websites</a>, that are safe to crawl repeatedly without causing any problems.
</p>
</div>

<form method="post" action="actions/new-crawl-specs">
<div class="form">
<label class="form-label" for="description">Description</label>
<input class="form-control" type="text" name="description" id="description" maxlength="255">
<div class="form-text" id="basic-addon4">This is how you'll be able to find the
specification later so give it a good and descriptive name</div>

<div id="spec-url-options" class="py-3">
<label class="form-label" for="url">URL to list of domain names</label>
<input class="form-control" type="text" name="url" id="url" />
</div>

<button type="submit" class="btn btn-primary">Create</button>
</div>
</form>
Expand Up @@ -2,13 +2,13 @@

{{#unless allCrawlSpecs}}
No crawling specifications have been created. You must create a crawl spec before you can crawl.
<a href="/nodes/{{node.id}}/storage/new-specs">create a crawl spec</a>.
<a href="?view=new-crawl-specs">create a crawl spec</a>.
{{/unless}}

{{#if allCrawlSpecs}}
<div class="my-3 p-3 border bg-light">
This will perform a new crawl on node {{node.id}} based on the crawl spec you select below.
Additional specifications can be created <a href="/nodes/{{node.id}}/storage/new-specs">with this form</a>.
Additional specifications can be created <a href="?view=new-crawl-specs">with this form</a>.
</div>
<div class="my-3 p-3 border">
<p><em class="text-danger">IMPORTANT!</em> Be sure you've read and understood the
Expand Down
Expand Up @@ -10,6 +10,7 @@
{{> control/node/partial-node-nav }}

{{#if view.new-crawl}} {{> control/node/actions/partial-new-crawl }} {{/if}}
{{#if view.new-crawl-specs}} {{> control/node/actions/partial-new-crawl-specs }} {{/if}}
{{#if view.re-crawl}} {{> control/node/actions/partial-recrawl }} {{/if}}
{{#if view.process}} {{> control/node/actions/partial-process }} {{/if}}
{{#if view.load}} {{> control/node/actions/partial-load }} {{/if}}
Expand Down

This file was deleted.

0 comments on commit f29a9d9

Please sign in to comment.