dev@locazia: fix file upload
This commit is contained in:
parent
27116f9a37
commit
caf181e6c6
|
|
@ -2,7 +2,9 @@
|
||||||
def string_to_bytes_fixed_size(src: str, size: int, encoding='utf-8') -> bytes:
|
def string_to_bytes_fixed_size(src: str, size: int, encoding='utf-8') -> bytes:
|
||||||
assert type(src) is str, "src must be a string"
|
assert type(src) is str, "src must be a string"
|
||||||
src_bin = src.encode(encoding)
|
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))
|
return src_bin + b'\x00' * (size - len(src_bin))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class ContentId:
|
||||||
return b58encode(self.content_hash).decode()
|
return b58encode(self.content_hash).decode()
|
||||||
|
|
||||||
def serialize_v1(self) -> str:
|
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"
|
assert len(self.content_hash) == 32, "Invalid hash length"
|
||||||
if self.onchain_index < 0:
|
if self.onchain_index < 0:
|
||||||
oi_bin = b''
|
oi_bin = b''
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue