indexImageHash function

Future<void> indexImageHash({
  1. required String hash,
  2. required String storedName,
  3. String? scope,
})

Implementation

Future<void> indexImageHash({
  required String hash,
  required String storedName,
  String? scope,
}) async {
  try {
    await _ensureCollectionDirExists(IMAGE_INDEX_COLLECTION);

    final payload = {
      'hash': hash,
      'storedName': storedName,
      'scope': scope ?? '',
      'ts': DateTime.now().millisecondsSinceEpoch,
    };

    // scoped entry
    final id = _imageIndexDocId(hash, scope: scope);
    await imageIndexCollection.doc(id).set(payload);

    // global entry (scope-agnostic fallback)
    final globalId = _imageIndexDocId(hash, scope: '');
    await imageIndexCollection.doc(globalId).set({
      ...payload,
      'scope': '',
    });
  } catch (e) {
    debugPrint('indexImageHash failed: $e');
  }
}