Change: only return file hash and not url
This commit is contained in:
parent
e02935eac8
commit
278e348c18
1 changed files with 10 additions and 10 deletions
|
@ -50,15 +50,11 @@ class PostPreviewSerializer(serializers.ModelSerializer):
|
|||
return [{"slug": i.slug, "name": i.name} for i in obj.category.all()]
|
||||
|
||||
def get_creator(self, obj: PostModel) -> Dict[str, Optional[str]]:
|
||||
avatar_url = (
|
||||
reverse("serve_file", args=[obj.creator.avatar.hash_blake3])
|
||||
if obj.creator.avatar
|
||||
else None
|
||||
)
|
||||
return {
|
||||
"slug": obj.creator.slug,
|
||||
"name": obj.creator.name,
|
||||
"avatar": avatar_url,
|
||||
"avatar": obj.creator.avatar.hash_blake3 if obj.creator.avatar else None,
|
||||
"blur_hash": obj.creator.avatar.blur_hash if obj.creator.avatar else None,
|
||||
}
|
||||
|
||||
def get_date(self, obj: PostModel) -> Dict[str, str]:
|
||||
|
@ -74,7 +70,8 @@ class PostPreviewSerializer(serializers.ModelSerializer):
|
|||
data.append(
|
||||
{
|
||||
"type": i.file_type,
|
||||
"src": reverse("serve_file", args=[i.hash_blake3]),
|
||||
"hash": i.hash_blake3,
|
||||
"blur_hash": i.blur_hash,
|
||||
}
|
||||
)
|
||||
return data
|
||||
|
@ -140,11 +137,10 @@ class PostSerializer(serializers.ModelSerializer):
|
|||
}
|
||||
|
||||
def get_creator(self, obj) -> Dict[str, Optional[str]]:
|
||||
avatar_url = obj.creator.avatar.file.url if obj.creator.avatar else None
|
||||
return {
|
||||
"slug": obj.creator.slug,
|
||||
"name": obj.creator.name,
|
||||
"avatar": avatar_url,
|
||||
"avatar": obj.creator.avatar.hash_blake3 if obj.creator.avatar else None,
|
||||
}
|
||||
|
||||
def get_tags(self, obj) -> List[str]:
|
||||
|
@ -161,6 +157,10 @@ class PostSerializer(serializers.ModelSerializer):
|
|||
data = []
|
||||
for i in obj.files.all():
|
||||
data.append(
|
||||
{"type": i.file_type, "mimetype": i.mimetype, "src": i.file.url}
|
||||
{
|
||||
"type": i.file_type,
|
||||
"mimetype": i.mimetype,
|
||||
"hash": i.hash_blake3,
|
||||
}
|
||||
)
|
||||
return data
|
||||
|
|
Loading…
Add table
Reference in a new issue