Skip to content

Commit ceec3a1

Browse files
committed
delete base64 images
1 parent cf4126c commit ceec3a1

File tree

3 files changed

+7
-37
lines changed

3 files changed

+7
-37
lines changed

src/openinflation_dataclass/card.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pydantic import Field, model_validator
66

7-
from .types import Base64BytesIO, NetworkModel
7+
from .types import NetworkModel
88

99

1010
class WholesalePrice(NetworkModel):
@@ -73,8 +73,8 @@ class Card(NetworkModel):
7373

7474
categories_uid: list[str]
7575

76-
main_image: Base64BytesIO = Field(repr=False)
77-
images: list[Base64BytesIO] = Field(default_factory=list, repr=False)
76+
main_image: str = Field(repr=False)
77+
images: list[str] = Field(default_factory=list, repr=False)
7878

7979
@model_validator(mode="after")
8080
def validate_business_rules(self) -> Card:

src/openinflation_dataclass/tree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pydantic import Field
44

5-
from .types import Base64BytesIO, NetworkModel
5+
from .types import NetworkModel
66

77

88
class Category(NetworkModel):
@@ -13,8 +13,8 @@ class Category(NetworkModel):
1313
title: str
1414
adult: bool
1515

16-
icon: Base64BytesIO | None = Field(default=None, repr=False)
17-
banner: Base64BytesIO | None = Field(default=None, repr=False)
16+
icon: str | None = Field(default=None, repr=False)
17+
banner: str | None = Field(default=None, repr=False)
1818
children: list[Category] = Field(default_factory=list)
1919

2020

src/openinflation_dataclass/types.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
from __future__ import annotations
22

3-
import base64
4-
import binascii
5-
from io import BytesIO
6-
from typing import Annotated, Any
7-
8-
from pydantic import BaseModel, BeforeValidator, ConfigDict, PlainSerializer
9-
10-
11-
def _bytesio_from_network(value: Any) -> BytesIO:
12-
if isinstance(value, BytesIO):
13-
return value
14-
if isinstance(value, (bytes, bytearray)):
15-
return BytesIO(bytes(value))
16-
if isinstance(value, str):
17-
try:
18-
raw = base64.b64decode(value.encode("ascii"), validate=True)
19-
except (ValueError, UnicodeEncodeError, binascii.Error) as exc:
20-
raise ValueError("Invalid base64 string for BytesIO.") from exc
21-
return BytesIO(raw)
22-
raise TypeError(f"Expected BytesIO/base64 string/bytes, got: {type(value)!r}")
23-
24-
25-
def _bytesio_to_network(value: BytesIO) -> str:
26-
return base64.b64encode(value.getvalue()).decode("ascii")
27-
28-
29-
Base64BytesIO = Annotated[
30-
BytesIO,
31-
BeforeValidator(_bytesio_from_network),
32-
PlainSerializer(_bytesio_to_network, return_type=str, when_used="json"),
33-
]
3+
from pydantic import BaseModel, ConfigDict
344

355

366
class NetworkModel(BaseModel):

0 commit comments

Comments
 (0)