Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

added ZIM importer servlet

Michael Peter Christen76210ab9fbfd
diff --git a/htroot/IndexImportZim_p.html b/htroot/IndexImportZim_p.html
new file mode 100644
index 000000000..68d74762e
--- /dev/null
+++ b/htroot/IndexImportZim_p.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>YaCy '#[clientname]#': ZIM File Import</title>
+ #%env/templates/metas.template%#
+ #(import)#::<meta http-equiv="REFRESH" content="10;url=IndexImportZim_p.html" />
+ <!-- the url= removes http get parameters on refresh, preventing restart of import -->
+ #(/import)#
+ </head>
+ <body id="IndexImportZim">
+ #%env/templates/header.template%#
+ #%env/templates/submenuIndexImport.template%#
+ <h2>ZIM File Import</h2>
+
+ #(import)#
+ <p>No import thread is running, you can start a new thread here</p>
+ <form action="IndexImportZim_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
+ <!-- no post method here, we don't want to transmit the whole file, only the path-->
+ <fieldset>
+ <legend>Zim File Selection: select a '.zim' file</legend>
+ <p>
+ You can download ZIM files for example here
+ <a href="https://download.kiwix.org/zim/" target="_blank">Kiwix ZIM Archive</a>.
+ </p>
+ <dl>
+ <dt class="TableCellDark"><label for="file">File:</label></dt>
+ <dd><input name="file" id="file" type="file" value="" size="75" /></dd>
+ <dt></dt>
+ <dd><input name="submit" class="btn btn-primary" type="submit" value="Import ZIM File" /></dd>
+ </dl>
+ </fieldset>
+ </form>
+
+ <br />
+ ::
+ <form>
+ <fieldset><legend>Import Process</legend>
+ <dl>
+ <dt>Thread:</dt><dd>#[thread]#</dd>
+ <dt>ZIM File:</dt><dd>#[zimfile]#</dd>
+ <dt>Processed:</dt><dd>#[count]# Entries</dd>
+ <dt>Speed:</dt><dd>#[speed]# pages per second</dd>
+ <dt>Running Time:</dt><dd>#[runningHours]# hours, #[runningMinutes]# minutes</dd>
+ <dt>Remaining Time:</dt><dd>#[remainingHours]# hours, #[remainingMinutes]# minutes</dd>
+ </dl>
+ </fieldset>
+ <input name="abort" type="submit" class="btn btn-danger" value="Stop"/>
+ </form>
+ #(/import)#
+
+ #%env/templates/footer.template%#
+ </body>
+</html>
\ No newline at end of file
diff --git a/htroot/env/templates/submenuIndexImport.template b/htroot/env/templates/submenuIndexImport.template
index 39a1029a3..ccbc49412 100644
--- a/htroot/env/templates/submenuIndexImport.template
+++ b/htroot/env/templates/submenuIndexImport.template
@@ -14,6 +14,7 @@
<li><a href="Load_RSS_p.html" class="MenuItemLink #(authorized)#lock::unlock#(/authorized)#">RSS Feed Importer</a></li>
<li><a href="IndexImportOAIPMH_p.html" class="MenuItemLink #(authorized)#lock::unlock#(/authorized)#">OAI-PMH Importer</a></li>
<li><a href="IndexImportWarc_p.html" class="MenuItemLink #(authorized)#lock::unlock#(/authorized)#">Warc Importer</a></li>
+ <li><a href="IndexImportZim_p.html" class="MenuItemLink #(authorized)#lock::unlock#(/authorized)#">Zim Importer</a></li>
<li><a href="IndexImportJsonList_p.html" class="MenuItemLink #(authorized)#lock::unlock#(/authorized)#">JsonList Importer</a></li>
</ul>
</div>
diff --git a/source/net/yacy/htroot/IndexImportZim_p.java b/source/net/yacy/htroot/IndexImportZim_p.java
new file mode 100644
index 000000000..8517121d5
--- /dev/null
+++ b/source/net/yacy/htroot/IndexImportZim_p.java
@@ -0,0 +1,85 @@
+// IndexImportZim_p.java
+// -------------------------
+// (c) 2025 by Michael Peter Christen, [email protected]
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+package net.yacy.htroot;
+
+import java.io.File;
+import java.io.IOException;
+
+import net.yacy.cora.protocol.RequestHeader;
+import net.yacy.document.importer.ZimImporter;
+import net.yacy.server.serverObjects;
+import net.yacy.server.serverSwitch;
+
+public class IndexImportZim_p {
+
+ public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader request, final serverObjects post, @SuppressWarnings("unused") final serverSwitch env) {
+
+ // read multipart data from post request
+
+ final serverObjects prop = new serverObjects();
+
+ if (ZimImporter.job != null && ZimImporter.job.isAlive()) {
+ // one import is running, no option to insert anything
+ prop.put("import", 1);
+ prop.put("import_thread", "running");
+ prop.put("import_warcfile", ZimImporter.job.source());
+ prop.put("import_count", ZimImporter.job.count());
+ prop.put("import_speed", ZimImporter.job.speed());
+ prop.put("import_runningHours", (ZimImporter.job.runningTime() / 60) / 60);
+ prop.put("import_runningMinutes", (ZimImporter.job.runningTime() / 60) % 60);
+ prop.put("import_remainingHours", (ZimImporter.job.remainingTime() / 60) / 60);
+ prop.put("import_remainingMinutes", (ZimImporter.job.remainingTime() / 60) % 60);
+ if (post != null && post.containsKey("abort")) {
+ ZimImporter.job.quit();
+ }
+ } else {
+ prop.put("import", 0);
+ if (post != null) {
+ if (post.containsKey("file")) {
+ final String filename = post.get("file");
+ if (filename != null && filename.length() > 0) {
+ final File sourcefile = new File(filename);
+ if (sourcefile.exists()) {
+ try {
+ final ZimImporter zi = new ZimImporter(sourcefile.getAbsolutePath());
+ zi.start();
+ prop.put("import_thread", "started");
+ } catch (final IOException ex) {
+ prop.put("import_thread", "Error: file not found [" + filename + "]");
+ }
+ prop.put("import", 1);
+ prop.put("import_zimfile", filename);
+ } else {
+ prop.put("import_zimfile", "");
+ prop.put("import_thread", "Error: file not found [" + filename + "]");
+ }
+ }
+
+ prop.put("import_count", 0);
+ prop.put("import_speed", 0);
+ prop.put("import_runningHours", 0);
+ prop.put("import_runningMinutes", 0);
+ prop.put("import_remainingHours", 0);
+ prop.put("import_remainingMinutes", 0);
+ }
+ }
+ }
+ return prop;
+ }
+}