mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 13:19:02 +00:00

Look, this will make the git history look funny, but trimming unnecessary depth from the source tree is a very necessary sanity-preserving measure when dealing with a super-modularized codebase like this one. While it makes the project configuration a bit less conventional, it will save you several clicks every time you jump between modules. Which you'll do a lot, because it's *modul*ar. The src/main/java convention makes a lot of sense for a non-modular project though. This ain't that.
42 lines
1.5 KiB
Java
42 lines
1.5 KiB
Java
package nu.marginalia.screenshot;
|
|
|
|
|
|
import nu.marginalia.service.module.DatabaseModule;
|
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
|
import org.mariadb.jdbc.Driver;
|
|
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.sql.SQLException;
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
public class ScreenshotLoaderMain {
|
|
public static void main(String... args) throws IOException {
|
|
|
|
org.mariadb.jdbc.Driver driver = new Driver();
|
|
var ds = new DatabaseModule(false).provideConnection();
|
|
|
|
try (var tis = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(args[0])));
|
|
var conn = ds.getConnection();
|
|
var ps = conn.prepareStatement("REPLACE INTO DATA_DOMAIN_SCREENSHOT(DOMAIN_NAME, CONTENT_TYPE, DATA) VALUES (?,?,?)")
|
|
) {
|
|
for (TarArchiveEntry entry = tis.getNextTarEntry(); entry != null; entry = tis.getNextTarEntry()) {
|
|
if (entry.isFile()) {
|
|
String fileName = entry.getName();
|
|
String domainName = fileName.substring(fileName.indexOf('/')+1, fileName.lastIndexOf('.'));
|
|
|
|
ps.setString(1, domainName);
|
|
ps.setString(2, "image/webp");
|
|
ps.setBlob(3, tis);
|
|
ps.executeUpdate();
|
|
|
|
System.out.println(domainName);
|
|
}
|
|
}
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|