diff --git a/kodak/configuration.py b/kodak/configuration.py index b80a63a..e21dee7 100644 --- a/kodak/configuration.py +++ b/kodak/configuration.py @@ -213,8 +213,15 @@ class ManipConfig: @classmethod def from_env(cls, key: str): """Build dataclass from environment""" + name = os.getenv(f"KODAK_MANIP_{key}_NAME", key.lower()) + + if name == "original": + raise exceptions.ConfigurationError( + "Manipulation name 'original' is reserved for application usage" + ) + return cls( - name=os.getenv(f"KODAK_MANIP_{key}_NAME", key.lower()), + name=name, crop=ManipCropConfig.from_env(key), scale=ManipScaleConfig.from_env(key), formats=set( diff --git a/kodak/database/__init__.py b/kodak/database/__init__.py index 1b7b6b5..bbfc7a5 100644 --- a/kodak/database/__init__.py +++ b/kodak/database/__init__.py @@ -11,11 +11,11 @@ from kodak.configuration import KodakConfig from kodak.database._shared import INTERFACE as interface from kodak.database._shared import KodakModel from kodak.database.access import AccessRecord -from kodak.database.alias import AliasRecord from kodak.database.image import ImageRecord +from kodak.database.manip import ManipRecord -MODELS: Tuple[Type[KodakModel], ...] = (ImageRecord, AliasRecord, AccessRecord) +MODELS: Tuple[Type[KodakModel], ...] = (ImageRecord, ManipRecord, AccessRecord) def calc_batch_size( diff --git a/kodak/database/alias.py b/kodak/database/manip.py similarity index 52% rename from kodak/database/alias.py rename to kodak/database/manip.py index bbf75dc..8d6fad7 100644 --- a/kodak/database/alias.py +++ b/kodak/database/manip.py @@ -1,13 +1,18 @@ import peewee +from kodak import constants from kodak.database._shared import ChecksumField +from kodak.database._shared import EnumField from kodak.database._shared import KodakModel +from kodak.database._shared import PathField from kodak.database.image import ImageRecord -class AliasRecord(KodakModel): +class ManipRecord(KodakModel): """Model for manipulated image records""" parent = peewee.ForeignKeyField(ImageRecord, null=False) - name = peewee.CharField(null=False) + manip = peewee.CharField(null=False) + file = PathField(null=False) + format_ = EnumField(constants.ImageFormat, null=False) checksum = ChecksumField(null=False) diff --git a/kodak/resources/__init__.py b/kodak/resources/__init__.py index e3d17f3..4445ea0 100644 --- a/kodak/resources/__init__.py +++ b/kodak/resources/__init__.py @@ -2,15 +2,15 @@ from typing import Tuple from typing import Type from kodak.resources._shared import KodakResource -from kodak.resources.alias import ImageAlias from kodak.resources.heartbeat import Heartbeat from kodak.resources.image import Image +from kodak.resources.manip import ImageManip from kodak.resources.openapi import OpenAPI RESOURCES: Tuple[Type[KodakResource], ...] = ( Heartbeat, Image, - ImageAlias, + ImageManip, OpenAPI, ) diff --git a/kodak/resources/alias.py b/kodak/resources/alias.py deleted file mode 100644 index 5405cb9..0000000 --- a/kodak/resources/alias.py +++ /dev/null @@ -1,18 +0,0 @@ -from kodak.resources._shared import authenticated -from kodak.resources._shared import KodakResource -from kodak.resources._shared import ResponseTuple - - -class ImageAlias(KodakResource): - """Handle generating and returning a processed image alias""" - - routes = ("/image//",) - - @authenticated - def get(self, image_name: str, alias: str) -> ResponseTuple: - """Retrieve an image variation""" - raise NotImplementedError - - def head(self, image_name: str, alias: str) -> ResponseTuple: - """Alias HEAD to GET""" - return self._head(self.get(image_name, alias)) diff --git a/kodak/resources/image.py b/kodak/resources/image.py index 6a9af7e..d047e04 100644 --- a/kodak/resources/image.py +++ b/kodak/resources/image.py @@ -11,7 +11,7 @@ from kodak.resources._shared import ResponseTuple class Image(KodakResource): """Handle requests for original source images""" - routes = ("/image/",) + routes = ("/image//original",) @authenticated def get(self, image_name: str) -> flask.Response: # pylint: disable=no-self-use diff --git a/kodak/resources/manip.py b/kodak/resources/manip.py new file mode 100644 index 0000000..3bee4c4 --- /dev/null +++ b/kodak/resources/manip.py @@ -0,0 +1,18 @@ +from kodak.resources._shared import authenticated +from kodak.resources._shared import KodakResource +from kodak.resources._shared import ResponseTuple + + +class ImageManip(KodakResource): + """Handle generating and returning a processed image manip""" + + routes = ("/image//",) + + @authenticated + def get(self, image_name: str, manip: str) -> ResponseTuple: + """Retrieve an image variation""" + raise NotImplementedError + + def head(self, image_name: str, manip: str) -> ResponseTuple: + """Alias HEAD to GET""" + return self._head(self.get(image_name, manip)) diff --git a/openapi.yaml b/openapi.yaml index cc67abc..9a1395b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -67,7 +67,7 @@ paths: '500': description: Server is not operating correctly headers: *headers-default - /image/{image_name}: + /image/{image_name}/original: head: summary: Returns metadata about the image request operationId: ImageHead