handleVerify method
Future<void>
handleVerify(
- ArgResults argResults
)
Implementation
Future<void> handleVerify(ArgResults argResults) async {
final args = argResults.rest.sublist(1);
if (args.length < 2) {
stderr.writeln('\u274c Usage: verify <file-uuid-or-path> <local-file>');
exit(1);
}
try {
final creds = await config.readCredentials();
if (creds == null) {
stderr.writeln('\u274c Not logged in.');
exit(1);
}
client.setAuth(creds);
final input = args[0];
final localPath = args[1];
final localFile = File(localPath);
if (!await localFile.exists()) {
stderr.writeln('\u274c Local file not found: $localPath');
exit(1);
}
final isUuid = RegExp(
r'^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$',
caseSensitive: false)
.hasMatch(input);
String fileUuid;
if (isUuid) {
fileUuid = input;
print('\ud83d\udd0d Verifying upload by UUID');
print(' Remote UUID: $fileUuid');
print(' Local file: $localPath\n');
} else {
print('\ud83d\udd0d Resolving remote path: $input');
final resolved = await client.resolvePath(input);
if (resolved['type'] != 'file') {
stderr.writeln('\u274c "$input" is not a file');
exit(1);
}
fileUuid = resolved['uuid'];
print(' \u2705 Resolved to UUID: $fileUuid');
print(' Local file: $localPath\n');
}
final match = await client.verifyUploadMetadata(fileUuid, localFile);
exit(match ? 0 : 1);
} catch (e) {
stderr.writeln('\u274c Verification failed: $e');
exit(1);
}
}