mirror of
https://github.com/penpot/penpot.git
synced 2026-09-13 15:38:38 +00:00
🐛 Avoid json decoder liner limit exception by chunking
Happens only when we send large binary data serialized with transit (mainly used for upload fonts data).
This commit is contained in:
parent
33e650242c
commit
8632b18eec
@ -33,6 +33,7 @@
|
|||||||
- Fix allow negative spread values on shadow token creation [Taiga #13167](https://tree.taiga.io/project/penpot/issue/13167)
|
- Fix allow negative spread values on shadow token creation [Taiga #13167](https://tree.taiga.io/project/penpot/issue/13167)
|
||||||
- Fix spanish translations on import export token modal [Taiga #13171](https://tree.taiga.io/project/penpot/issue/13171)
|
- Fix spanish translations on import export token modal [Taiga #13171](https://tree.taiga.io/project/penpot/issue/13171)
|
||||||
- Remove whitespaces from asset export filename [Github #8133](https://github.com/penpot/penpot/pull/8133)
|
- Remove whitespaces from asset export filename [Github #8133](https://github.com/penpot/penpot/pull/8133)
|
||||||
|
- Fix exception on uploading large fonts [Github #8135](https://github.com/penpot/penpot/pull/8135)
|
||||||
|
|
||||||
## 2.12.1
|
## 2.12.1
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,17 @@
|
|||||||
[app.rpc.helpers :as rph]
|
[app.rpc.helpers :as rph]
|
||||||
[app.rpc.quotes :as quotes]
|
[app.rpc.quotes :as quotes]
|
||||||
[app.storage :as sto]
|
[app.storage :as sto]
|
||||||
[app.util.services :as sv]))
|
[app.storage.tmp :as tmp]
|
||||||
|
[app.util.services :as sv]
|
||||||
|
[datoteka.io :as io])
|
||||||
|
(:import
|
||||||
|
java.io.InputStream
|
||||||
|
java.io.OutputStream
|
||||||
|
java.io.SequenceInputStream
|
||||||
|
java.util.Collections))
|
||||||
|
|
||||||
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
|
||||||
(def valid-weight #{100 200 300 400 500 600 700 800 900 950})
|
(def valid-weight #{100 200 300 400 500 600 700 800 900 950})
|
||||||
(def valid-style #{"normal" "italic"})
|
(def valid-style #{"normal" "italic"})
|
||||||
@ -105,7 +115,7 @@
|
|||||||
|
|
||||||
(defn create-font-variant
|
(defn create-font-variant
|
||||||
[{:keys [::sto/storage ::db/conn]} {:keys [data] :as params}]
|
[{:keys [::sto/storage ::db/conn]} {:keys [data] :as params}]
|
||||||
(letfn [(generate-missing! [data]
|
(letfn [(generate-missing [data]
|
||||||
(let [data (media/run {:cmd :generate-fonts :input data})]
|
(let [data (media/run {:cmd :generate-fonts :input data})]
|
||||||
(when (and (not (contains? data "font/otf"))
|
(when (and (not (contains? data "font/otf"))
|
||||||
(not (contains? data "font/ttf"))
|
(not (contains? data "font/ttf"))
|
||||||
@ -116,8 +126,26 @@
|
|||||||
:hint "invalid font upload, unable to generate missing font assets"))
|
:hint "invalid font upload, unable to generate missing font assets"))
|
||||||
data))
|
data))
|
||||||
|
|
||||||
|
(process-chunks [chunks]
|
||||||
|
(let [tmp (tmp/tempfile :prefix "penpot.tempfont." :suffix "")
|
||||||
|
streams (map io/input-stream chunks)
|
||||||
|
streams (Collections/enumeration streams)]
|
||||||
|
(with-open [^OutputStream output (io/output-stream tmp)
|
||||||
|
^InputStream input (SequenceInputStream. streams)]
|
||||||
|
(io/copy input output))
|
||||||
|
tmp))
|
||||||
|
|
||||||
|
(join-chunks [data]
|
||||||
|
(reduce-kv (fn [data mtype content]
|
||||||
|
(if (vector? content)
|
||||||
|
(assoc data mtype (process-chunks content))
|
||||||
|
data))
|
||||||
|
data
|
||||||
|
data))
|
||||||
|
|
||||||
(prepare-font [data mtype]
|
(prepare-font [data mtype]
|
||||||
(when-let [resource (get data mtype)]
|
(when-let [resource (get data mtype)]
|
||||||
|
|
||||||
(let [hash (sto/calculate-hash resource)
|
(let [hash (sto/calculate-hash resource)
|
||||||
content (-> (sto/content resource)
|
content (-> (sto/content resource)
|
||||||
(sto/wrap-with-hash hash))]
|
(sto/wrap-with-hash hash))]
|
||||||
@ -156,7 +184,8 @@
|
|||||||
:otf-file-id (:id otf)
|
:otf-file-id (:id otf)
|
||||||
:ttf-file-id (:id ttf)}))]
|
:ttf-file-id (:id ttf)}))]
|
||||||
|
|
||||||
(let [data (generate-missing! data)
|
(let [data (join-chunks data)
|
||||||
|
data (generate-missing data)
|
||||||
assets (persist-fonts-files! data)
|
assets (persist-fonts-files! data)
|
||||||
result (insert-font-variant! assets)]
|
result (insert-font-variant! assets)]
|
||||||
(vary-meta result assoc ::audit/replace-props (update params :data (comp vec keys))))))
|
(vary-meta result assoc ::audit/replace-props (update params :data (comp vec keys))))))
|
||||||
|
|||||||
@ -24,6 +24,20 @@
|
|||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
|
(def ^:const default-chunk-size
|
||||||
|
(* 1024 1024 4)) ;; 4MiB
|
||||||
|
|
||||||
|
(defn- chunk-array
|
||||||
|
[data chunk-size]
|
||||||
|
(let [total-size (alength data)]
|
||||||
|
(loop [offset 0
|
||||||
|
chunks []]
|
||||||
|
(if (< offset total-size)
|
||||||
|
(let [end (min (+ offset chunk-size) total-size)
|
||||||
|
chunk (.subarray ^js data offset end)]
|
||||||
|
(recur end (conj chunks chunk)))
|
||||||
|
chunks))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; General purpose events & IMPL
|
;; General purpose events & IMPL
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -116,9 +130,9 @@
|
|||||||
(not= hhea-descender win-descent)
|
(not= hhea-descender win-descent)
|
||||||
(and f-selection (or
|
(and f-selection (or
|
||||||
(not= hhea-ascender os2-ascent)
|
(not= hhea-ascender os2-ascent)
|
||||||
(not= hhea-descender os2-descent))))]
|
(not= hhea-descender os2-descent))))
|
||||||
|
data (js/Uint8Array. data)]
|
||||||
{:content {:data (js/Uint8Array. data)
|
{:content {:data (chunk-array data default-chunk-size)
|
||||||
:name name
|
:name name
|
||||||
:type type}
|
:type type}
|
||||||
:font-family (or family "")
|
:font-family (or family "")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user