Added ability to rerasterize specific docs

This commit is contained in:
Rick Falkvinge
2017-08-24 09:39:57 +02:00
parent 4ba4d36cd1
commit 3279b9af1d
2 changed files with 57 additions and 5 deletions
+43 -1
View File
@@ -13,7 +13,7 @@ namespace Swarmops.Utility.BotCode
{
private static readonly string StorageRoot = "/var/lib/swarmops/upload/";
public static void RegenerateAll()
public static void RerasterizeAll()
{
// Because of a bug with transparent-background PDFs converting to black-background bitmaps, all PDFs imaged before
// DB version 37 need to be re-bitmapped
@@ -44,6 +44,11 @@ namespace Swarmops.Utility.BotCode
{
continue;
}
if (document.ForeignId == 0)
{
// orphan document
continue;
}
firstPart = document.ServerFileName.Substring(0, 64);
@@ -92,5 +97,42 @@ namespace Swarmops.Utility.BotCode
}
}
}
public static void Rerasterize(Document document)
{
if (document.Description.Length < 32)
{
throw new InvalidOperationException("Document has no GUID");
}
// a ServerFileName looks like "2015/06/22/29c88f2b-44e6-4a05-a6b0-f9aaec835c5b-00000001-0007-01-0019.png"
// 1234567890123456789012345678901234567890123456789012345678901234
if (document.ServerFileName.Length < 64)
{
throw new InvalidOperationException("Server file name has wrong scheme");
}
if (!document.ServerFileName.ToLowerInvariant().EndsWith(".png"))
{
throw new InvalidOperationException("Document is not rasterized");
}
if (document.ForeignId == 0)
{
throw new InvalidOperationException("Document is an orphan");
}
string firstPart = document.ServerFileName.Substring(0, 64);
Console.Write("Regenerating document...");
Process process = Process.Start("bash",
"-c \"convert -density 600 -background white -flatten " + StorageRoot + firstPart + " " +
StorageRoot + firstPart +
"-%04d.png\""); // Density 600 means 600dpi means production-grade conversion
process.WaitForExit();
Console.WriteLine(" done.");
}
}
}