mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 09:01:48 +02:00
🐛 Fix template import (#6299)
This commit is contained in:
parent
202b9f3075
commit
2aaa2f3033
5 changed files with 41 additions and 40 deletions
|
@ -156,10 +156,13 @@ http {
|
|||
}
|
||||
|
||||
location / {
|
||||
location ~ ^/github/penpot-files/(?<template_file>[a-zA-Z0-9\-\_\.]+) {
|
||||
proxy_pass https://raw.githubusercontent.com/penpot/penpot-files/main/$template_file;
|
||||
location ~ ^/github/penpot-files/(.+)$ {
|
||||
rewrite ^/github/penpot-files/(.+) /penpot/penpot-files/refs/heads/main/$1 break;
|
||||
proxy_pass https://raw.githubusercontent.com;
|
||||
|
||||
proxy_hide_header Access-Control-Allow-Origin;
|
||||
proxy_set_header User-Agent "curl/7.74.0";
|
||||
proxy_hide_header Cookies;
|
||||
proxy_set_header User-Agent "curl/8.5.0";
|
||||
proxy_set_header Host "raw.githubusercontent.com";
|
||||
proxy_set_header Accept "*/*";
|
||||
add_header Access-Control-Allow-Origin $http_origin;
|
||||
|
|
|
@ -135,10 +135,13 @@ http {
|
|||
}
|
||||
|
||||
location / {
|
||||
location ~ ^/github/penpot-files/(?<template_file>[a-zA-Z0-9\-\_\.]+) {
|
||||
proxy_pass https://raw.githubusercontent.com/penpot/penpot-files/main/$template_file;
|
||||
location ~ ^/github/penpot-files/(.+)$ {
|
||||
rewrite ^/github/penpot-files/(.+) /penpot/penpot-files/refs/heads/main/$1 break;
|
||||
proxy_pass https://raw.githubusercontent.com;
|
||||
|
||||
proxy_hide_header Access-Control-Allow-Origin;
|
||||
proxy_set_header User-Agent "curl/7.74.0";
|
||||
proxy_hide_header Cookies;
|
||||
proxy_set_header User-Agent "curl/8.5.0";
|
||||
proxy_set_header Host "raw.githubusercontent.com";
|
||||
proxy_set_header Accept "*/*";
|
||||
add_header Access-Control-Allow-Origin $http_origin;
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
(mf/defc dashboard-legacy-redirect*
|
||||
{::mf/props :obj
|
||||
::mf/private true}
|
||||
[{:keys [section team-id project-id search-term plugin-url template-url]}]
|
||||
[{:keys [section team-id project-id search-term plugin-url template]}]
|
||||
(let [section (case section
|
||||
:dashboard-legacy-search
|
||||
:dashboard-search
|
||||
|
@ -98,7 +98,7 @@
|
|||
:project-id project-id
|
||||
:search-term search-term
|
||||
:plugin plugin-url
|
||||
:template-url template-url}]
|
||||
:template template}]
|
||||
(st/emit! (rt/nav section (d/without-nils params)))))
|
||||
|
||||
[:> loader*
|
||||
|
@ -217,7 +217,7 @@
|
|||
project-id (some-> params :project-id uuid/parse*)
|
||||
search-term (some-> params :search-term)
|
||||
plugin-url (some-> params :plugin)
|
||||
template-url (some-> params :template)]
|
||||
template (some-> params :template)]
|
||||
[:?
|
||||
#_[:& app.main.ui.releases/release-notes-modal {:version "2.5"}]
|
||||
#_[:& app.main.ui.onboarding/onboarding-templates-modal]
|
||||
|
@ -244,7 +244,7 @@
|
|||
:search-term search-term
|
||||
:plugin-url plugin-url
|
||||
:project-id project-id
|
||||
:template-url template-url}]]])
|
||||
:template template}]]])
|
||||
|
||||
:workspace
|
||||
(let [params (get params :query)
|
||||
|
@ -326,14 +326,14 @@
|
|||
project-id (some-> params :path :project-id uuid/parse*)
|
||||
search-term (some-> params :query :search-term)
|
||||
plugin-url (some-> params :query :plugin)
|
||||
template-url (some-> params :template)]
|
||||
template (some-> params :template)]
|
||||
[:> dashboard-legacy-redirect*
|
||||
{:team-id team-id
|
||||
:section section
|
||||
:project-id project-id
|
||||
:search-term search-term
|
||||
:plugin-url plugin-url
|
||||
:template-url template-url}])
|
||||
:template template}])
|
||||
|
||||
:viewer-legacy
|
||||
(let [{:keys [query-params path-params]} route
|
||||
|
|
|
@ -34,12 +34,10 @@
|
|||
[app.main.ui.workspace.plugins]
|
||||
[app.plugins.register :as preg]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.http :as http]
|
||||
[app.util.i18n :refer [tr]]
|
||||
[app.util.keyboard :as kbd]
|
||||
[app.util.object :as obj]
|
||||
[app.util.storage :as storage]
|
||||
[app.util.webapi :as wapi]
|
||||
[beicon.v2.core :as rx]
|
||||
[cuerdas.core :as str]
|
||||
[goog.events :as events]
|
||||
|
@ -211,17 +209,22 @@
|
|||
(swap! storage/session dissoc :plugin-url))))))
|
||||
|
||||
(defn use-templates-import
|
||||
[can-edit? template-url project]
|
||||
[can-edit? template project]
|
||||
(let [project-id (get project :id)
|
||||
team-id (get project :team-id)]
|
||||
(mf/with-layout-effect [can-edit? template-url project-id team-id]
|
||||
(when (and (some? template-url)
|
||||
(mf/with-layout-effect [can-edit? template project-id team-id]
|
||||
(when (and (some? template)
|
||||
(some? project-id)
|
||||
(some? team-id))
|
||||
(if can-edit?
|
||||
(let [valid-url? (and (str/ends-with? template-url ".penpot")
|
||||
(str/starts-with? template-url cf/templates-uri))
|
||||
template-name (when valid-url? (subs template-url (count cf/templates-uri)))
|
||||
(let [valid-url? (str/ends-with? template ".penpot")
|
||||
|
||||
;; Backwards compatibility, ideally the template should be only the .penpot file name, not the full url
|
||||
template-name (if (str/starts-with? template "http")
|
||||
(subs template (count cf/templates-uri))
|
||||
template)
|
||||
|
||||
template-url (str "/github/penpot-files/" template-name)
|
||||
on-import #(st/emit! (dpj/fetch-files project-id)
|
||||
(dd/fetch-recent-files team-id)
|
||||
(dd/fetch-projects team-id)
|
||||
|
@ -230,30 +233,22 @@
|
|||
:name template-name
|
||||
:url template-url}))]
|
||||
(if valid-url?
|
||||
(do
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "install-template-from-link" :name template-name :url template-url}))
|
||||
(->> (http/send! {:method :get
|
||||
:uri template-url
|
||||
:response-type :blob
|
||||
:omit-default-headers true})
|
||||
(rx/subs!
|
||||
(fn [result]
|
||||
(if (or (< (:status result) 200) (>= (:status result) 300))
|
||||
(st/emit! (notif/error (tr "dashboard.import.error")))
|
||||
(st/emit! (modal/show
|
||||
(st/emit!
|
||||
(ptk/event ::ev/event {::ev/name "install-template-from-link" :name template-name :url template-url})
|
||||
(modal/show
|
||||
{:type :import
|
||||
:project-id project-id
|
||||
:entries [{:name template-name :uri (wapi/create-uri (:body result))}]
|
||||
:on-finish-import on-import})))))))
|
||||
:entries [{:name template-name :uri template-url}]
|
||||
:on-finish-import on-import}))
|
||||
(st/emit! (notif/error (tr "dashboard.import.bad-url")))))
|
||||
(st/emit! (notif/error (tr "dashboard.import.no-perms"))))
|
||||
|
||||
(binding [storage/*sync* true]
|
||||
(swap! storage/session dissoc :template-url))))))
|
||||
(swap! storage/session dissoc :template))))))
|
||||
|
||||
(mf/defc dashboard*
|
||||
{::mf/props :obj}
|
||||
[{:keys [profile project-id team-id search-term plugin-url template-url section]}]
|
||||
[{:keys [profile project-id team-id search-term plugin-url template section]}]
|
||||
(let [team (mf/deref refs/team)
|
||||
projects (mf/deref refs/projects)
|
||||
|
||||
|
@ -263,7 +258,7 @@
|
|||
(filterv #(= team-id (:team-id %)))))
|
||||
|
||||
can-edit? (dm/get-in team [:permissions :can-edit])
|
||||
template-url (or template-url (:template-url storage/session))
|
||||
template (or template (:template storage/session))
|
||||
plugin-url (or plugin-url (:plugin-url storage/session))
|
||||
|
||||
default-project
|
||||
|
@ -289,7 +284,7 @@
|
|||
(events/unlistenByKey key))))
|
||||
|
||||
(use-plugin-register plugin-url team-id (:id default-project))
|
||||
(use-templates-import can-edit? template-url default-project)
|
||||
(use-templates-import can-edit? template default-project)
|
||||
|
||||
[:& (mf/provider ctx/current-project-id) {:value project-id}
|
||||
[:> modal-container*]
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
(binding [storage/*sync* true]
|
||||
(when (some? template)
|
||||
(swap! storage/session assoc
|
||||
:template-url template))
|
||||
:template template))
|
||||
(when (some? plugin)
|
||||
(swap! storage/session assoc
|
||||
:plugin-url plugin))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue