mirror of
https://github.com/penpot/penpot.git
synced 2025-04-13 07:21:40 -05:00
✨ More improvements on media uploading.
This commit is contained in:
parent
6a32428ca1
commit
ad2d8c8ee0
4 changed files with 30 additions and 10 deletions
|
@ -99,7 +99,8 @@
|
|||
:tokens (ig/ref :app.tokens/tokens)
|
||||
:metrics (ig/ref :app.metrics/metrics)
|
||||
:storage (ig/ref :app.storage/storage)
|
||||
:redis (ig/ref :app.redis/redis)}
|
||||
:redis (ig/ref :app.redis/redis)
|
||||
:svgc (ig/ref :app.svgparse/svgc)}
|
||||
|
||||
:app.notifications/handler
|
||||
{:redis (ig/ref :app.redis/redis)
|
||||
|
|
|
@ -120,10 +120,11 @@
|
|||
(ex/raise :type :validation
|
||||
:code :unable-to-parse-svg
|
||||
:hint "uploaded svg has invalid content"))
|
||||
(reduce (fn [_ f]
|
||||
(reduce (fn [default f]
|
||||
(if-let [res (f attrs)]
|
||||
(reduced res)
|
||||
nil))
|
||||
default))
|
||||
{:width 100 :height 100}
|
||||
[(fn parse-width-and-height
|
||||
[{:keys [width height]}]
|
||||
(when (and (string? width)
|
||||
|
|
|
@ -56,8 +56,19 @@
|
|||
(-> (assoc cfg :conn conn)
|
||||
(create-file-media-object params)))))
|
||||
|
||||
(defn- big-enough-for-thumbnail?
|
||||
"Checks if the provided image info is big enough for
|
||||
create a separate thumbnail storage object."
|
||||
[info]
|
||||
(or (> (:width info) (:width thumbnail-options))
|
||||
(> (:height info) (:height thumbnail-options))))
|
||||
|
||||
(defn- svg-image?
|
||||
[info]
|
||||
(= (:mtype info) "image/svg+xml"))
|
||||
|
||||
(defn create-file-media-object
|
||||
[{:keys [conn storage] :as cfg} {:keys [id file-id is-local name content] :as params}]
|
||||
[{:keys [conn storage svgc] :as cfg} {:keys [id file-id is-local name content] :as params}]
|
||||
(media/validate-media-type (:content-type content))
|
||||
(let [storage (assoc storage :conn conn)
|
||||
source-path (fs/path (:tempfile content))
|
||||
|
@ -65,13 +76,19 @@
|
|||
|
||||
source-info (media/run {:cmd :info :input {:path source-path :mtype source-mtype}})
|
||||
|
||||
thumb (when (not= (:mtype source-info) "image/svg+xml")
|
||||
thumb (when (and (not (svg-image? source-info))
|
||||
(big-enough-for-thumbnail? source-info))
|
||||
(media/run (assoc thumbnail-options
|
||||
:cmd :generic-thumbnail
|
||||
:input {:mtype (:mtype source-info) :path source-path})))
|
||||
:input {:mtype (:mtype source-info)
|
||||
:path source-path})))
|
||||
|
||||
image (sto/put-object storage {:content (sto/content source-path)
|
||||
:content-type (:mtype source-info)})
|
||||
image (if (= (:mtype source-info) "image/svg+xml")
|
||||
(let [data (svgc (slurp source-path))]
|
||||
(sto/put-object storage {:content (sto/content data)
|
||||
:content-type (:mtype source-info)}))
|
||||
(sto/put-object storage {:content (sto/content source-path)
|
||||
:content-type (:mtype source-info)}))
|
||||
|
||||
thumb (when thumb
|
||||
(sto/put-object storage {:content (sto/content (:data thumb) (:size thumb))
|
||||
|
|
5
vendor/svgclean/main.js
vendored
5
vendor/svgclean/main.js
vendored
|
@ -1,6 +1,6 @@
|
|||
const plugins = [
|
||||
{removeDimensions: true},
|
||||
{removeXMLNS: true},
|
||||
// {removeXMLNS: false},
|
||||
{removeScriptElement: true},
|
||||
{removeViewBox: false},
|
||||
{moveElemsAttrsToGroup: false},
|
||||
|
@ -14,9 +14,10 @@ const plugins = [
|
|||
];
|
||||
|
||||
const svgc = require("./src/svgclean.js");
|
||||
const inst = svgc.configure({plugins, multipass: undefined});
|
||||
const inst = svgc.configure({plugins});
|
||||
|
||||
exports.optimize = function(data) {
|
||||
return svgc.optimize(inst, data)
|
||||
.then((result) => result.data);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue