mirror of
https://github.com/enpaul/kodak.git
synced 2025-04-05 17:33:34 +00:00
One of the goals is to make the generated content directory directly hostable via a web browser for performance. This means that the application needs to be able to generate a file tree identical to the URL structure so that clients can fetch a single URL and either use the cached image or trigger a manipulation depending on whether it already exists. With a url structure of /key and /key/manip for the source and manips respectively, it becomes impossible to create a file tree matching it since 'key' must be both the source file and a directory containing the manipulated images. This updates it to use 'original' as a special manip name so the URL structure of /key/original and /key/manip can match the directory structure
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import datetime
|
|
|
|
import flask
|
|
|
|
from kodak import database
|
|
from kodak.resources._shared import authenticated
|
|
from kodak.resources._shared import KodakResource
|
|
from kodak.resources._shared import ResponseTuple
|
|
|
|
|
|
class Image(KodakResource):
|
|
"""Handle requests for original source images"""
|
|
|
|
routes = ("/image/<string:image_name>/original",)
|
|
|
|
@authenticated
|
|
def get(self, image_name: str) -> flask.Response: # pylint: disable=no-self-use
|
|
"""Retrieve an original source image"""
|
|
with database.interface.atomic():
|
|
image = database.ImageRecord.get(database.ImageRecord.name == image_name)
|
|
|
|
resp = flask.send_file(
|
|
image.source,
|
|
cache_timeout=int(datetime.timedelta(days=365).total_seconds()),
|
|
add_etags=False,
|
|
)
|
|
|
|
resp.headers["Content-Digest"] = image.checksum.as_header()
|
|
|
|
return resp
|
|
|
|
def head(self, image_name: str) -> ResponseTuple:
|
|
"""Alias HEAD to GET"""
|
|
return self._head(self.get(image_name))
|