mirror of
https://github.com/penpot/penpot.git
synced 2025-06-11 11:11:39 +02:00
♻️ Refactor file persistence layer.
This commit is contained in:
parent
182afedc54
commit
4e694ff194
86 changed files with 3205 additions and 3313 deletions
|
@ -1,13 +1,15 @@
|
|||
(ns app.http
|
||||
(:require
|
||||
[app.http.export :refer [export-handler]]
|
||||
[app.http.thumbnail :refer [thumbnail-handler]]
|
||||
[app.http.impl :as impl]
|
||||
[lambdaisland.glogi :as log]
|
||||
[promesa.core :as p]
|
||||
[reitit.core :as r]))
|
||||
|
||||
(def routes
|
||||
[["/export" {:handler export-handler}]])
|
||||
[["/export/thumbnail" {:handler thumbnail-handler}]
|
||||
["/export" {:handler export-handler}]])
|
||||
|
||||
(defn start!
|
||||
[extra]
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns app.http.export
|
||||
(:require
|
||||
[app.http.export-bitmap :as bitmap]
|
||||
|
@ -12,6 +21,7 @@
|
|||
|
||||
(s/def ::name ::us/string)
|
||||
(s/def ::page-id ::us/uuid)
|
||||
(s/def ::file-id ::us/uuid)
|
||||
(s/def ::object-id ::us/uuid)
|
||||
(s/def ::scale ::us/number)
|
||||
(s/def ::suffix ::us/string)
|
||||
|
@ -23,7 +33,7 @@
|
|||
(s/def ::exports (s/coll-of ::export :kind vector?))
|
||||
|
||||
(s/def ::handler-params
|
||||
(s/keys :req-un [::page-id ::object-id ::name ::exports]))
|
||||
(s/keys :req-un [::page-id ::file-id ::object-id ::name ::exports]))
|
||||
|
||||
(declare handle-single-export)
|
||||
(declare handle-multiple-export)
|
||||
|
@ -32,7 +42,7 @@
|
|||
|
||||
(defn export-handler
|
||||
[{:keys [params browser cookies] :as request}]
|
||||
(let [{:keys [exports page-id object-id name]} (us/conform ::handler-params params)
|
||||
(let [{:keys [exports page-id file-id object-id name]} (us/conform ::handler-params params)
|
||||
token (.get ^js cookies "auth-token")]
|
||||
(case (count exports)
|
||||
0 (exc/raise :type :validation :code :missing-exports)
|
||||
|
@ -41,6 +51,7 @@
|
|||
(assoc (first exports)
|
||||
:name name
|
||||
:token token
|
||||
:file-id file-id
|
||||
:page-id page-id
|
||||
:object-id object-id))
|
||||
(handle-multiple-export
|
||||
|
@ -49,6 +60,7 @@
|
|||
(assoc item
|
||||
:name name
|
||||
:token token
|
||||
:file-id file-id
|
||||
:page-id page-id
|
||||
:object-id object-id)) exports)))))
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
(:import
|
||||
goog.Uri))
|
||||
|
||||
(defn- screenshot-object
|
||||
[browser {:keys [page-id object-id token scale suffix type]}]
|
||||
(defn screenshot-object
|
||||
[browser {:keys [file-id page-id object-id token scale type]}]
|
||||
(letfn [(handle [page]
|
||||
(let [path (str "/render-object/" page-id "/" object-id)
|
||||
(let [path (str "/render-object/" file-id "/" page-id "/" object-id)
|
||||
uri (doto (Uri. (:public-uri cfg/config))
|
||||
(.setPath "/")
|
||||
(.setFragment path))
|
||||
|
@ -46,13 +46,14 @@
|
|||
(s/def ::suffix ::us/string)
|
||||
(s/def ::type #{:jpeg :png})
|
||||
(s/def ::page-id ::us/uuid)
|
||||
(s/def ::file-id ::us/uuid)
|
||||
(s/def ::object-id ::us/uuid)
|
||||
(s/def ::scale ::us/number)
|
||||
(s/def ::token ::us/string)
|
||||
(s/def ::filename ::us/string)
|
||||
|
||||
(s/def ::export-params
|
||||
(s/keys :req-un [::name ::suffix ::type ::object-id ::page-id ::scale ::token]
|
||||
(s/keys :req-un [::name ::suffix ::type ::object-id ::page-id ::scale ::token ::file-id]
|
||||
:opt-un [::filename]))
|
||||
|
||||
(defn export
|
||||
|
|
|
@ -249,13 +249,14 @@
|
|||
(s/def ::suffix ::us/string)
|
||||
(s/def ::type #{:svg})
|
||||
(s/def ::page-id ::us/uuid)
|
||||
(s/def ::file-id ::us/uuid)
|
||||
(s/def ::object-id ::us/uuid)
|
||||
(s/def ::scale ::us/number)
|
||||
(s/def ::token ::us/string)
|
||||
(s/def ::filename ::us/string)
|
||||
|
||||
(s/def ::export-params
|
||||
(s/keys :req-un [::name ::suffix ::type ::object-id ::page-id ::scale ::token]
|
||||
(s/keys :req-un [::name ::suffix ::type ::object-id ::page-id ::file-id ::scale ::token]
|
||||
:opt-un [::filename]))
|
||||
|
||||
(defn export
|
||||
|
|
46
exporter/src/app/http/thumbnail.cljs
Normal file
46
exporter/src/app/http/thumbnail.cljs
Normal file
|
@ -0,0 +1,46 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns app.http.thumbnail
|
||||
(:require
|
||||
[app.common.exceptions :as exc :include-macros true]
|
||||
[app.common.spec :as us]
|
||||
[app.http.export-bitmap :as bitmap]
|
||||
[cljs.spec.alpha :as s]
|
||||
[cuerdas.core :as str]
|
||||
[lambdaisland.glogi :as log]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(s/def ::page-id ::us/uuid)
|
||||
(s/def ::file-id ::us/uuid)
|
||||
(s/def ::object-id ::us/uuid)
|
||||
(s/def ::scale ::us/number)
|
||||
|
||||
(s/def ::handler-params
|
||||
(s/keys :req-un [::page-id ::file-id ::object-id]))
|
||||
|
||||
(declare handle-single-export)
|
||||
(declare handle-multiple-export)
|
||||
(declare perform-export)
|
||||
(declare attach-filename)
|
||||
|
||||
(defn thumbnail-handler
|
||||
[{:keys [params browser cookies] :as request}]
|
||||
(let [{:keys [page-id file-id object-id]} (us/conform ::handler-params params)
|
||||
params {:token (.get ^js cookies "auth-token")
|
||||
:file-id file-id
|
||||
:page-id page-id
|
||||
:object-id object-id
|
||||
:scale 0.3
|
||||
:type :jpeg}]
|
||||
(p/let [content (bitmap/screenshot-object browser params)]
|
||||
{:status 200
|
||||
:body content
|
||||
:headers {"content-type" "image/jpeg"
|
||||
"content-length" (alength content)}})))
|
Loading…
Add table
Add a link
Reference in a new issue