From caf181e6c665d26ff41f8bd74522589a0168dafd Mon Sep 17 00:00:00 2001 From: user Date: Fri, 8 Mar 2024 03:27:20 +0300 Subject: [PATCH] dev@locazia: fix file upload --- app/core/_utils/string_binary.py | 4 +++- app/core/content/content_id.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/core/_utils/string_binary.py b/app/core/_utils/string_binary.py index b047824..68764df 100644 --- a/app/core/_utils/string_binary.py +++ b/app/core/_utils/string_binary.py @@ -2,7 +2,9 @@ def string_to_bytes_fixed_size(src: str, size: int, encoding='utf-8') -> bytes: assert type(src) is str, "src must be a string" src_bin = src.encode(encoding) - assert len(src_bin) <= size, "src is too long" + while len(src_bin) > size: + src = src[:-1] + src_bin = src.encode(encoding) return src_bin + b'\x00' * (size - len(src_bin)) diff --git a/app/core/content/content_id.py b/app/core/content/content_id.py index 0a4d7fa..b976b9f 100644 --- a/app/core/content/content_id.py +++ b/app/core/content/content_id.py @@ -24,7 +24,7 @@ class ContentId: return b58encode(self.content_hash).decode() def serialize_v1(self) -> str: - at_bin = self.accept_type[:15] # string_to_bytes_fixed_size(self.accept_type, 15) + at_bin = string_to_bytes_fixed_size(self.accept_type, 15) assert len(self.content_hash) == 32, "Invalid hash length" if self.onchain_index < 0: oi_bin = b''