3OHG2256H6S4KQVKWDMSSLEKQPWCNOKEUNCQ73PRSQMEMJQ6X6NQC
clap.parseParam("-m <ID> Download metadata for ID image.") catch unreachable,
clap.parseParam("-d <ID> Download image data of ID.") catch unreachable,
clap.parseParam("-i <ID> Operate on ID.") catch unreachable,
clap.parseParam("-m Download metadata for ID image.") catch unreachable,
clap.parseParam("-d Download image data of ID.") catch unreachable,
clap.parseParam("-e <PATH> Extract image.") catch unreachable,
if (args.option("-d")) |id_str| {
const id = std.fmt.parseInt(u64, id_str, 10) catch {
log.err("Image ID must be a positive integer.", .{});
if (args.flag("-d")) {
const id = if (maybe_id) |id|
id
else {
log.err(
"Operation download image requires an ID (-i) argument.",
.{},
);
sqliteErrorReport("Couldn't insert", &db);
sqliteErrorReport("Couldn't add iamge hash", &db);
return;
};
try db.exec("COMMIT", .{});
response_buffer.clearRetainingCapacity();
std.mem.set(u8, hash_buf[0..], 0);
std.mem.set(u8, hash_buf2[0..], 0);
}
if (res.thumb_url) |url| {
easyFetch(handle, url, &response_buffer) catch return;
try db.exec("BEGIN IMMEDIATE;", .{});
errdefer db.exec("ROLLBACK;", .{}) catch {};
db.exec(
"UPDATE OR ROLLBACK image SET thumb = ? WHERE id = ?",
.{
.thumb = response_buffer.items,
.id = id,
},
) catch {
sqliteErrorReport("Couldn't add thumb to DB", &db);
return;
};
try hashit(response_buffer.items);
db.exec(
"UPDATE OR ROLLBACK image SET hash_thumb = ? WHERE id = ?",
.{ hash_buf2[0..], id },
) catch {
sqliteErrorReport("Couldn't add thumb hash", &db);
log.err("No metadata for id {d} available.", .{id});
log.err("No metadata for id {d} available", .{id});
return;
}
}
if (args.option("-e")) |path| {
const id = if (maybe_id) |id|
id
else {
log.err(
"Operation extract image requires an ID (-i) argument.",
.{},
);
};
const maybe_image = db.oneAlloc(
[]u8,
alloc,
"SELECT image FROM image WHERE id = ?",
.{},
.{ .id = id },
) catch {
sqliteErrorReport("ID check read error", &db);
return;
};
if (maybe_image) |image| {
var file = try std.fs.cwd().createFile(
path,
.{
.read = false,
.truncate = true,
},
);
try file.writeAll(image);
file.close();
} else {
log.info("No image data for ID {d}.", .{id});