check / check (push) Waiting to run
`--verify`, or `lib.backup({ verify: true })`, hashes each original already
at its save path as the download check does, streamed, a live photo as
`<imageHash>:<videoHash>`. A mismatch is logged, removed and fetched again in
the same run; a failed fetch goes into `failures.json`. A file with no
recorded hash counts as unchecked. The result, the summary and `--json` gain
`verified`, `mismatched` and `unchecked`.
Judgement call: a stored original that cannot be read for hashing is recorded as failed and left in place.
Judgement call: the summary prints the three counts only with `--verify`.
Judgement call: the README's `BackupOptions` list does not name `verify`, to stay clear of #178's edit of that paragraph; Backup layout documents it.
Model: opus-5-5
181 lines
5.5 KiB
JavaScript
181 lines
5.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { stdout, stderr } from "node:process";
|
|
import { input, password } from "@inquirer/prompts";
|
|
import { Command } from "commander";
|
|
import envPaths from "env-paths";
|
|
import { init } from "../src/crypto/index.js";
|
|
import {
|
|
type CliContext,
|
|
loginCommand,
|
|
whoamiCommand,
|
|
logoutCommand,
|
|
collectionsCommand,
|
|
filesCommand,
|
|
getCommand,
|
|
getThumbCommand,
|
|
backupMetadataCommand,
|
|
backupCommand,
|
|
listMissingThumbnailsCommand,
|
|
fixMissingThumbnailsCommand,
|
|
} from "../src/cli-commands.js";
|
|
import { run as runCommand } from "../src/cli-run.js";
|
|
import { loadSession } from "../src/cli-session.js";
|
|
import { Client } from "../src/client.js";
|
|
import { VERSION } from "../src/index.js";
|
|
import { UNATTENDED_RETRY_OPTIONS } from "../src/retry.js";
|
|
|
|
const paths = envPaths("quak", { suffix: "" });
|
|
|
|
const program = new Command();
|
|
|
|
program
|
|
.name("quak")
|
|
.description("CLI for the Ente end-to-end encrypted photo service")
|
|
.version(VERSION)
|
|
.option(
|
|
"--cache-dir <path>",
|
|
"Directory for the local metadata/content cache " +
|
|
"(default: the per-user cache directory)",
|
|
);
|
|
|
|
const context = (): CliContext => ({
|
|
stdout,
|
|
stderr,
|
|
sessionDir: paths.data,
|
|
cacheDir: program.opts<{ cacheDir?: string }>().cacheDir,
|
|
loadSession,
|
|
login: (opts) => Client.login(opts),
|
|
prompt: (message) => input({ message }),
|
|
promptSecret: (message) => password({ message, mask: true }),
|
|
});
|
|
|
|
const run = (command: Promise<number>): Promise<void> =>
|
|
runCommand(command, stdout, stderr, (code) => process.exit(code));
|
|
|
|
program
|
|
.command("login")
|
|
.description("Log in to an Ente account and save the session")
|
|
.action(() => run(loginCommand(context())));
|
|
|
|
program
|
|
.command("whoami")
|
|
.description("Print the logged-in account")
|
|
.action(() => run(whoamiCommand(context())));
|
|
|
|
program
|
|
.command("logout")
|
|
.description("End the session on the server and delete the saved session")
|
|
.action(() => run(logoutCommand(context())));
|
|
|
|
program
|
|
.command("collections")
|
|
.description("List all collections (albums)")
|
|
.option("--json", "Output as JSON array")
|
|
.action((opts: { json?: boolean }) =>
|
|
run(collectionsCommand(context(), opts)),
|
|
);
|
|
|
|
program
|
|
.command("files")
|
|
.description("List files in a collection")
|
|
.requiredOption(
|
|
"--collection <id>",
|
|
"Collection ID (from `quak collections`)",
|
|
)
|
|
.option("--json", "Output as JSON array")
|
|
.action((opts: { collection: string; json?: boolean }) =>
|
|
run(filesCommand(context(), opts)),
|
|
);
|
|
|
|
program
|
|
.command("get")
|
|
.description("Download and decrypt a single file")
|
|
.argument("<fileID>", "File ID (from `quak files`)")
|
|
.option("--out <path>", "Output file path")
|
|
.option("--collection <id>", "Accepted for compatibility; ignored")
|
|
.action((fileID: string, opts: { out?: string }) =>
|
|
run(getCommand(context(), fileID, opts)),
|
|
);
|
|
|
|
program
|
|
.command("get-thumb")
|
|
.description("Download and decrypt a thumbnail")
|
|
.argument("<fileID>", "File ID (from `quak files`)")
|
|
.option("--out <path>", "Output file path")
|
|
.option("--collection <id>", "Accepted for compatibility; ignored")
|
|
.action((fileID: string, opts: { out?: string }) =>
|
|
run(getThumbCommand(context(), fileID, opts)),
|
|
);
|
|
|
|
program
|
|
.command("backup-metadata")
|
|
.description(
|
|
"Dump all decrypted account metadata to a directory of JSON files",
|
|
)
|
|
.argument("<dir>", "Output directory")
|
|
.option(
|
|
"--exif",
|
|
"Download each file and extract full EXIF/IPTC/XMP metadata (slow)",
|
|
)
|
|
.option("--all", "Alias for --exif")
|
|
.action((dir: string, opts: { exif?: boolean; all?: boolean }) =>
|
|
run(backupMetadataCommand(context(), dir, opts)),
|
|
);
|
|
|
|
program
|
|
.command("backup")
|
|
.description(
|
|
"Download all photos to a local directory, organized by collection",
|
|
)
|
|
.argument("<dir>", "Output directory")
|
|
.option("--json", "Print result as JSON instead of human-readable summary")
|
|
.option(
|
|
"--verify",
|
|
"Re-hash stored originals and download again any that do not match",
|
|
)
|
|
// A backup usually runs from cron with nobody watching, so every request
|
|
// it makes retries for longer than the other commands' requests do.
|
|
.action((dir: string, opts: { json?: boolean; verify?: boolean }) =>
|
|
run(
|
|
backupCommand(
|
|
{
|
|
...context(),
|
|
loadSession: (path) =>
|
|
loadSession(path, { retry: UNATTENDED_RETRY_OPTIONS }),
|
|
},
|
|
dir,
|
|
opts,
|
|
),
|
|
),
|
|
);
|
|
|
|
const helper = program
|
|
.command("helper")
|
|
.description("Maintenance and repair utilities");
|
|
|
|
helper
|
|
.command("list-missing-thumbnails")
|
|
.description("List files whose thumbnails are missing or empty")
|
|
.option("--json", "Output as JSON array")
|
|
.action((opts: { json?: boolean }) =>
|
|
run(listMissingThumbnailsCommand(context(), opts)),
|
|
);
|
|
|
|
helper
|
|
.command("fix-missing-thumbnails")
|
|
.description(
|
|
"Generate and upload thumbnails for files that are missing them",
|
|
)
|
|
.option(
|
|
"--file <ids...>",
|
|
"Specific file IDs to fix (default: fix all missing)",
|
|
)
|
|
.option("--json", "Output as JSON")
|
|
.action((opts: { file?: string[]; json?: boolean }) =>
|
|
run(fixMissingThumbnailsCommand(context(), opts)),
|
|
);
|
|
|
|
await init();
|
|
await program.parseAsync();
|