diff --git a/app/core/background/indexer_service.py b/app/core/background/indexer_service.py index 5be17ce..0a68cdb 100644 --- a/app/core/background/indexer_service.py +++ b/app/core/background/indexer_service.py @@ -28,6 +28,16 @@ async def indexer_loop(platform_found: bool, seqno: int) -> [bool, int]: make_log("Indexer", "Service running", level="debug") with db_session() as session: + content_without_cid = session.query(StoredContent).filter( + StoredContent.content_id == None + ) + for target_content in content_without_cid: + target_cid = target_content.cid.serialize_v2() + make_log("Indexer", f"Content without CID: {target_content.hash}, setting CID: {target_cid}", level="debug") + target_content.content_id = target_cid + + session.commit() + last_known_index = session.query(StoredContent).filter( StoredContent.type == "onchain/content" ).order_by(StoredContent.onchain_index.desc()).first() diff --git a/app/core/content/content_id.py b/app/core/content/content_id.py index fafb698..43d333c 100644 --- a/app/core/content/content_id.py +++ b/app/core/content/content_id.py @@ -38,7 +38,7 @@ class ContentId: def safe_onchain_index(self): return self.onchain_index if (not (self.onchain_index is None) and self.onchain_index >= 0) else None - def serialize_v2(self) -> str: + def serialize_v2(self, include_accept_type=False) -> str: cid_bin = ( (2).to_bytes(1, 'big') # cid version + self.content_hash @@ -47,7 +47,7 @@ class ContentId: oi_bin_hex = hex(self.safe_onchain_index)[2:] oi_bin_len = math.ceil(len(oi_bin_hex) / 2) cid_bin += b'\xb0' + oi_bin_len.to_bytes(1, 'big') + bytes.fromhex(oi_bin_hex) - if self.accept_type: + if self.accept_type and include_accept_type: at_bin_len = len(self.accept_type.encode()) at_bin = string_to_bytes_fixed_size(self.accept_type, at_bin_len) cid_bin += (