dev@locazia: fix file upload

This commit is contained in:
user 2024-03-08 03:27:20 +03:00
parent 27116f9a37
commit caf181e6c6
2 changed files with 4 additions and 2 deletions

View File

@ -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))

View File

@ -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''