mirror of
https://github.com/penpot/penpot.git
synced 2025-05-23 20:46:11 +02:00
✨ Minor improvements on storage http handlers.
This commit is contained in:
parent
77c1163591
commit
d32cacf1da
2 changed files with 37 additions and 29 deletions
|
@ -22,9 +22,8 @@
|
||||||
(def ^:private signature-max-age
|
(def ^:private signature-max-age
|
||||||
(dt/duration {:hours 24 :minutes 15}))
|
(dt/duration {:hours 24 :minutes 15}))
|
||||||
|
|
||||||
(defn- generic-handler
|
(defn- serve-object
|
||||||
[storage request id]
|
[storage obj]
|
||||||
(if-let [obj (sto/get-object storage id)]
|
|
||||||
(let [mdata (meta obj)
|
(let [mdata (meta obj)
|
||||||
backend (sto/resolve-backend storage (:backend obj))]
|
backend (sto/resolve-backend storage (:backend obj))]
|
||||||
(case (:type backend)
|
(case (:type backend)
|
||||||
|
@ -44,13 +43,21 @@
|
||||||
|
|
||||||
:fs
|
:fs
|
||||||
(let [url (sto/get-object-url storage obj)]
|
(let [url (sto/get-object-url storage obj)]
|
||||||
{:status 200
|
{:status 204
|
||||||
:headers {"x-accel-redirect" (:path url)
|
:headers {"x-accel-redirect" (:path url)
|
||||||
"content-type" (:content-type mdata)
|
"content-type" (:content-type mdata)
|
||||||
"cache-control" (str "max-age=" (inst-ms cache-max-age))}
|
"cache-control" (str "max-age=" (inst-ms cache-max-age))
|
||||||
:body ""})))
|
}
|
||||||
{:status 404
|
:body ""}))))
|
||||||
:body ""}))
|
|
||||||
|
(defn- generic-handler
|
||||||
|
[{:keys [pool] :as storage} request id]
|
||||||
|
(with-open [conn (db/open pool)]
|
||||||
|
(let [storage (assoc storage :conn conn)
|
||||||
|
obj (sto/get-object storage id)]
|
||||||
|
(if obj
|
||||||
|
(serve-object storage obj)
|
||||||
|
{:status 404 :body ""}))))
|
||||||
|
|
||||||
(defn coerce-id
|
(defn coerce-id
|
||||||
[id]
|
[id]
|
||||||
|
|
|
@ -60,6 +60,8 @@ http {
|
||||||
|
|
||||||
etag off;
|
etag off;
|
||||||
|
|
||||||
|
root /home/penpot/penpot/frontend/resources/public;
|
||||||
|
|
||||||
location @handle_redirect {
|
location @handle_redirect {
|
||||||
set $redirect_uri "$upstream_http_location";
|
set $redirect_uri "$upstream_http_location";
|
||||||
set $redirect_host "$upstream_http_x_host";
|
set $redirect_host "$upstream_http_x_host";
|
||||||
|
@ -90,7 +92,7 @@ http {
|
||||||
location /internal/assets {
|
location /internal/assets {
|
||||||
internal;
|
internal;
|
||||||
alias /home/penpot/penpot/backend/resources/public/assets;
|
alias /home/penpot/penpot/backend/resources/public/assets;
|
||||||
add_header x-accel-redirect "$upstream_http_x_accel_redirect";
|
add_header x-internal-redirect "$upstream_http_x_accel_redirect";
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api {
|
location /api {
|
||||||
|
@ -114,7 +116,6 @@ http {
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
root /home/penpot/penpot/frontend/resources/public;
|
|
||||||
add_header Cache-Control "no-cache, max-age=0";
|
add_header Cache-Control "no-cache, max-age=0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue