2023-03-06 17:32:13 +00:00
|
|
|
package nu.marginalia.screenshot;
|
2022-07-20 10:02:26 +00:00
|
|
|
|
2023-03-04 12:19:01 +00:00
|
|
|
|
|
|
|
import nu.marginalia.service.module.DatabaseModule;
|
2022-07-20 10:02:26 +00:00
|
|
|
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();
|
2024-01-11 11:40:03 +00:00
|
|
|
var ds = new DatabaseModule(false).provideConnection();
|
2022-07-20 10:02:26 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|