dev@locazia: add blockchain routes, edit resolve content system to cid class, add web2 docs
This commit is contained in:
1 parent
78a4a84c2b
commit
d7ebc26bce
14 files changed
+314
-61
No files matched your search
@@ -4,12 +4,7 @@ from sqlalchemy.orm import relationship
|
||||
from .base import AlchemyBase
|
||||
from hashlib import sha256
|
||||
from base58 import b58encode, b58decode
|
||||
|
||||
|
||||
# DMY CID v1 specs
|
||||
# 1. int8 cid version
|
||||
# 2. int256 sha256 of content
|
||||
# 3. int128 onchain content index
|
||||
from app.core.content.content_id import ContentId
|
||||
|
||||
|
||||
class StoredContent(AlchemyBase):
|
||||
@@ -37,13 +32,10 @@ class StoredContent(AlchemyBase):
|
||||
user = relationship('User', uselist=False, foreign_keys=[user_id])
|
||||
key = relationship('KnownKey', uselist=False, foreign_keys=[key_id])
|
||||
|
||||
def make_dmy_cid_v1(self) -> str:
|
||||
vhash = sha256(
|
||||
(1).to_bytes(1, 'big') # cid version
|
||||
+ b58decode(hash)
|
||||
+ (self.onchain_index or 0).to_bytes(16, 'big')
|
||||
).digest()
|
||||
return b58encode(vhash).decode()
|
||||
|
||||
def make_deeplink(self):
|
||||
return f"dmy://storage?cid={self.make_dmy_cid_v1()}"
|
||||
@property
|
||||
def cid(self) -> ContentId:
|
||||
return ContentId(
|
||||
content_hash=b58decode(self.hash),
|
||||
onchain_index=self.onchain_index,
|
||||
accept_type=self.meta.get('content_type', 'image/jpeg')
|
||||
)
|
||||
Reference in new issue
Block a user