From 9ed90efed461f0c0c204382726199749efddb26a Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 11 Jan 2024 16:48:18 -0600 Subject: [PATCH] Add release document, use .extend rather than .join --- pict-rs.toml | 5 ----- releases/0.5.1.md | 32 ++++++++++++++++++++++++++++++++ src/store/object_store.rs | 11 ++++++++--- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 releases/0.5.1.md diff --git a/pict-rs.toml b/pict-rs.toml index d638b37..1a5bf9f 100644 --- a/pict-rs.toml +++ b/pict-rs.toml @@ -674,9 +674,4 @@ client_timeout = 30 # Note that in order for clients to fetch media from this URL directly, any server between the # client and pict-rs must not be configured to follow redirects, or else that server will fetch from # this public URL and serve the file itself. -# -# Note also that if a a path is to be included in the URL, it must have a trailing slash or else it -# will be overwritten by the filepath. -# e.g. https://example.com/sub/path will turn into https://example.com/sub/001/001/UUID -# while https://example.com/sub/path/ will turn into https://example.com/sub/path/001/001/UUID public_endpoint = "https://pict-rs.some.cdn.example.com/subpath/" diff --git a/releases/0.5.1.md b/releases/0.5.1.md new file mode 100644 index 0000000..a98df94 --- /dev/null +++ b/releases/0.5.1.md @@ -0,0 +1,32 @@ +# pict-rs 0.5.1 + +## Overview + +Just a quick point release to better support different public_endpoint usecases. Including paths for +the public_endpoint configuration is now supported. + +### Changes + +- [Support Paths in PUBLIC_ENDPOINT](#support-paths-in-public-endpoints) + + +## Upgrade Notes + +There's no significant changes from 0.5.0, so upgrading should be as simple as pulling a new version +of pict-rs. + + +## Descriptions + +### Support Paths in PUBLIC_ENDPOINT + +The `public_endpoint` configuration option for object storage has been updated to allow setting +paths at which the files are available. Previously any set path would be overridden, treating the +file's relative path as it's absolute path. Now pict-rs will serve files respecting configured +paths. + +Example +```toml +public_endpoint = "https://example.com/sub/path" +``` +This will produce URLs to `https://example.com/sub/path/$filepath` diff --git a/src/store/object_store.rs b/src/store/object_store.rs index b837e07..dd5b124 100644 --- a/src/store/object_store.rs +++ b/src/store/object_store.rs @@ -403,9 +403,14 @@ impl Store for ObjectStore { } fn public_url(&self, identifier: &Arc) -> Option { - self.public_endpoint - .as_ref() - .and_then(|endpoint| endpoint.join(identifier.as_ref()).ok()) + self.public_endpoint.clone().and_then(|mut endpoint| { + endpoint + .path_segments_mut() + .ok()? + .pop_if_empty() + .extend(identifier.as_ref().split('/')); + Some(endpoint) + }) } #[tracing::instrument(skip(self))]