0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-09 00:28:20 -05:00

📎 Move import parser from util to worker directory

This commit is contained in:
Andrey Antukh 2024-01-08 16:20:29 +01:00
parent b6c257bfc5
commit e0a1cd6e77
2 changed files with 43 additions and 43 deletions

View file

@ -20,12 +20,12 @@
[app.main.repo :as rp] [app.main.repo :as rp]
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.import.parser :as cip]
[app.util.json :as json] [app.util.json :as json]
[app.util.sse :as sse] [app.util.sse :as sse]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[app.util.zip :as uz] [app.util.zip :as uz]
[app.worker.impl :as impl] [app.worker.impl :as impl]
[app.worker.import.parser :as parser]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]
[tubax.core :as tubax])) [tubax.core :as tubax]))
@ -259,8 +259,8 @@
(defn process-import-node (defn process-import-node
[context file node] [context file node]
(let [type (cip/get-type node) (let [type (parser/get-type node)
close? (cip/close? node)] close? (parser/close? node)]
(if close? (if close?
(case type (case type
:frame (fb/close-artboard file) :frame (fb/close-artboard file)
@ -270,11 +270,11 @@
#_default file) #_default file)
(let [resolve (:resolve context) (let [resolve (:resolve context)
old-id (cip/get-id node) old-id (parser/get-id node)
interactions (->> (cip/parse-interactions node) interactions (->> (parser/parse-interactions node)
(mapv #(update % :destination resolve))) (mapv #(update % :destination resolve)))
data (-> (cip/parse-data type node) data (-> (parser/parse-data type node)
(resolve-data-ids type context) (resolve-data-ids type context)
(cond-> (some? old-id) (cond-> (some? old-id)
(assoc :id (resolve old-id))) (assoc :id (resolve old-id)))
@ -319,17 +319,17 @@
(defn resolve-media (defn resolve-media
[context file-id node] [context file-id node]
(if (or (and (not (cip/close? node)) (if (or (and (not (parser/close? node))
(cip/has-image? node)) (parser/has-image? node))
(cip/has-stroke-images? node) (parser/has-stroke-images? node)
(cip/has-fill-images? node)) (parser/has-fill-images? node))
(let [name (cip/get-image-name node) (let [name (parser/get-image-name node)
has-image (cip/has-image? node) has-image (parser/has-image? node)
image-data (cip/get-image-data node) image-data (parser/get-image-data node)
image-fill (cip/get-image-fill node) image-fill (parser/get-image-fill node)
fill-images-data (->> (cip/get-fill-images-data node) fill-images-data (->> (parser/get-fill-images-data node)
(map #(assoc % :type :fill))) (map #(assoc % :type :fill)))
stroke-images-data (->> (cip/get-stroke-images-data node) stroke-images-data (->> (parser/get-stroke-images-data node)
(map #(assoc % :type :stroke))) (map #(assoc % :type :stroke)))
images-data (concat images-data (concat
@ -367,18 +367,18 @@
(rx/observe-on :async)))) (rx/observe-on :async))))
(defn media-node? [node] (defn media-node? [node]
(or (and (cip/shape? node) (or (and (parser/shape? node)
(cip/has-image? node) (parser/has-image? node)
(not (cip/close? node))) (not (parser/close? node)))
(cip/has-stroke-images? node) (parser/has-stroke-images? node)
(cip/has-fill-images? node))) (parser/has-fill-images? node)))
(defn import-page (defn import-page
[context file [page-id page-name content]] [context file [page-id page-name content]]
(let [nodes (->> content cip/node-seq) (let [nodes (->> content parser/node-seq)
file-id (:id file) file-id (:id file)
resolve (:resolve context) resolve (:resolve context)
page-data (-> (cip/parse-page-data content) page-data (-> (parser/parse-page-data content)
(assoc :name page-name) (assoc :name page-name)
(assoc :id (resolve page-id))) (assoc :id (resolve page-id)))
flows (->> (get-in page-data [:options :flows]) flows (->> (get-in page-data [:options :flows])
@ -412,32 +412,32 @@
(rx/merge-map (rx/merge-map
(fn [pre-proc] (fn [pre-proc]
(->> (rx/from nodes) (->> (rx/from nodes)
(rx/filter cip/shape?) (rx/filter parser/shape?)
(rx/map (fn [node] (or (get pre-proc node) node))) (rx/map (fn [node] (or (get pre-proc node) node)))
(rx/reduce (partial process-import-node context) file) (rx/reduce (partial process-import-node context) file)
(rx/map (comp fb/close-page setup-interactions)))))))) (rx/map (comp fb/close-page setup-interactions))))))))
(defn import-component [context file node] (defn import-component [context file node]
(let [resolve (:resolve context) (let [resolve (:resolve context)
content (cip/find-node node :g) content (parser/find-node node :g)
file-id (:id file) file-id (:id file)
old-id (cip/get-id node) old-id (parser/get-id node)
id (resolve old-id) id (resolve old-id)
path (get-in node [:attrs :penpot:path] "") path (get-in node [:attrs :penpot:path] "")
type (cip/get-type content) type (parser/get-type content)
main-instance-id (resolve (uuid (get-in node [:attrs :penpot:main-instance-id] ""))) main-instance-id (resolve (uuid (get-in node [:attrs :penpot:main-instance-id] "")))
main-instance-page (resolve (uuid (get-in node [:attrs :penpot:main-instance-page] ""))) main-instance-page (resolve (uuid (get-in node [:attrs :penpot:main-instance-page] "")))
data (-> (cip/parse-data type content) data (-> (parser/parse-data type content)
(assoc :path path) (assoc :path path)
(assoc :id id) (assoc :id id)
(assoc :main-instance-id main-instance-id) (assoc :main-instance-id main-instance-id)
(assoc :main-instance-page main-instance-page)) (assoc :main-instance-page main-instance-page))
file (-> file (fb/start-component data type)) file (-> file (fb/start-component data type))
children (cip/node-seq node)] children (parser/node-seq node)]
(->> (rx/from children) (->> (rx/from children)
(rx/filter cip/shape?) (rx/filter parser/shape?)
(rx/skip 1) ;; Skip the outer component and the respective closint tag (rx/skip 1) ;; Skip the outer component and the respective closint tag
(rx/skip-last 1) ;; because they are handled in start-component an finish-component (rx/skip-last 1) ;; because they are handled in start-component an finish-component
(rx/mapcat (partial resolve-media context file-id)) (rx/mapcat (partial resolve-media context file-id))
@ -446,18 +446,18 @@
(defn import-deleted-component [context file node] (defn import-deleted-component [context file node]
(let [resolve (:resolve context) (let [resolve (:resolve context)
content (cip/find-node node :g) content (parser/find-node node :g)
file-id (:id file) file-id (:id file)
old-id (cip/get-id node) old-id (parser/get-id node)
id (resolve old-id) id (resolve old-id)
path (get-in node [:attrs :penpot:path] "") path (get-in node [:attrs :penpot:path] "")
main-instance-id (resolve (uuid (get-in node [:attrs :penpot:main-instance-id] ""))) main-instance-id (resolve (uuid (get-in node [:attrs :penpot:main-instance-id] "")))
main-instance-page (resolve (uuid (get-in node [:attrs :penpot:main-instance-page] ""))) main-instance-page (resolve (uuid (get-in node [:attrs :penpot:main-instance-page] "")))
main-instance-x (get-in node [:attrs :penpot:main-instance-x] "") main-instance-x (get-in node [:attrs :penpot:main-instance-x] "")
main-instance-y (get-in node [:attrs :penpot:main-instance-y] "") main-instance-y (get-in node [:attrs :penpot:main-instance-y] "")
type (cip/get-type content) type (parser/get-type content)
data (-> (cip/parse-data type content) data (-> (parser/parse-data type content)
(assoc :path path) (assoc :path path)
(assoc :id id) (assoc :id id)
(assoc :main-instance-id main-instance-id) (assoc :main-instance-id main-instance-id)
@ -467,10 +467,10 @@
file (-> file (fb/start-component data)) file (-> file (fb/start-component data))
component-id (:current-component-id file) component-id (:current-component-id file)
children (cip/node-seq node)] children (parser/node-seq node)]
(->> (rx/from children) (->> (rx/from children)
(rx/filter cip/shape?) (rx/filter parser/shape?)
(rx/skip 1) (rx/skip 1)
(rx/skip-last 1) (rx/skip-last 1)
(rx/mapcat (partial resolve-media context file-id)) (rx/mapcat (partial resolve-media context file-id))
@ -511,7 +511,7 @@
(assoc :id (resolve id)))] (assoc :id (resolve id)))]
(fb/add-library-color file color)))] (fb/add-library-color file color)))]
(->> (get-file context :colors) (->> (get-file context :colors)
(rx/merge-map (comp d/kebab-keys cip/string->uuid)) (rx/merge-map (comp d/kebab-keys parser/string->uuid))
(rx/reduce add-color file))) (rx/reduce add-color file)))
(rx/of file))) (rx/of file)))
@ -521,7 +521,7 @@
(if (:has-typographies context) (if (:has-typographies context)
(let [resolve (:resolve context)] (let [resolve (:resolve context)]
(->> (get-file context :typographies) (->> (get-file context :typographies)
(rx/merge-map (comp d/kebab-keys cip/string->uuid)) (rx/merge-map (comp d/kebab-keys parser/string->uuid))
(rx/map (fn [[id typography]] (rx/map (fn [[id typography]]
(-> typography (-> typography
(d/kebab-keys) (d/kebab-keys)
@ -535,7 +535,7 @@
(if (:has-media context) (if (:has-media context)
(let [resolve (:resolve context)] (let [resolve (:resolve context)]
(->> (get-file context :media-list) (->> (get-file context :media-list)
(rx/merge-map (comp d/kebab-keys cip/string->uuid)) (rx/merge-map (comp d/kebab-keys parser/string->uuid))
(rx/mapcat (rx/mapcat
(fn [[id media]] (fn [[id media]]
(let [media (assoc media :id (resolve id))] (let [media (assoc media :id (resolve id))]
@ -559,7 +559,7 @@
[context file] [context file]
(if (:has-components context) (if (:has-components context)
(let [split-components (let [split-components
(fn [content] (->> (cip/node-seq content) (fn [content] (->> (parser/node-seq content)
(filter #(= :symbol (:tag %)))))] (filter #(= :symbol (:tag %)))))]
(->> (get-file context :components) (->> (get-file context :components)
@ -571,7 +571,7 @@
[context file] [context file]
(if (:has-deleted-components context) (if (:has-deleted-components context)
(let [split-components (let [split-components
(fn [content] (->> (cip/node-seq content) (fn [content] (->> (parser/node-seq content)
(filter #(= :symbol (:tag %)))))] (filter #(= :symbol (:tag %)))))]
(->> (get-file context :deleted-components) (->> (get-file context :deleted-components)
@ -645,7 +645,7 @@
(rx/filter (fn [data] (= "application/zip" (:type data)))) (rx/filter (fn [data] (= "application/zip" (:type data))))
(rx/merge-map #(zip/loadAsync (:body %))) (rx/merge-map #(zip/loadAsync (:body %)))
(rx/merge-map #(get-file {:zip %} :manifest)) (rx/merge-map #(get-file {:zip %} :manifest))
(rx/map (comp d/kebab-keys cip/string->uuid)) (rx/map (comp d/kebab-keys parser/string->uuid))
(rx/map #(hash-map :uri (:uri file) :data % :type "application/zip"))) (rx/map #(hash-map :uri (:uri file) :data % :type "application/zip")))
(->> st (->> st
(rx/filter (fn [data] (= "application/octet-stream" (:type data)))) (rx/filter (fn [data] (= "application/octet-stream" (:type data))))

View file

@ -4,7 +4,7 @@
;; ;;
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns app.util.import.parser (ns app.worker.import.parser
(:require (:require
[app.common.colors :as cc] [app.common.colors :as cc]
[app.common.data :as d] [app.common.data :as d]