mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
Merge pull request #1944 from penpot/hiru-dbg-update-file
Hiru dbg update file
This commit is contained in:
commit
047b3f0987
1 changed files with 27 additions and 19 deletions
|
@ -12,6 +12,7 @@
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.db.sql :as sql]
|
||||||
[app.rpc.mutations.files :as m.files]
|
[app.rpc.mutations.files :as m.files]
|
||||||
[app.rpc.queries.profile :as profile]
|
[app.rpc.queries.profile :as profile]
|
||||||
[app.util.blob :as blob]
|
[app.util.blob :as blob]
|
||||||
|
@ -59,7 +60,7 @@
|
||||||
"select revn, changes, data from file_change where file_id=? and revn = ?")
|
"select revn, changes, data from file_change where file_id=? and revn = ?")
|
||||||
|
|
||||||
(defn prepare-response
|
(defn prepare-response
|
||||||
[{:keys [params] :as request} body]
|
[{:keys [params] :as request} body filename]
|
||||||
(when-not body
|
(when-not body
|
||||||
(ex/raise :type :not-found
|
(ex/raise :type :not-found
|
||||||
:code :enpty-data
|
:code :enpty-data
|
||||||
|
@ -69,8 +70,7 @@
|
||||||
:body body
|
:body body
|
||||||
:headers {"content-type" "application/transit+json"})
|
:headers {"content-type" "application/transit+json"})
|
||||||
(contains? params :download)
|
(contains? params :download)
|
||||||
(update :headers assoc "content-disposition" "attachment")))
|
(update :headers assoc "content-disposition" (str "attachment; filename=" filename))))
|
||||||
|
|
||||||
|
|
||||||
(defn- retrieve-file-data
|
(defn- retrieve-file-data
|
||||||
[{:keys [pool]} {:keys [params] :as request}]
|
[{:keys [pool]} {:keys [params] :as request}]
|
||||||
|
@ -78,8 +78,9 @@
|
||||||
(ex/raise :type :authentication
|
(ex/raise :type :authentication
|
||||||
:code :only-admins-allowed))
|
:code :only-admins-allowed))
|
||||||
|
|
||||||
(let [file-id (some-> (get-in request [:params :file-id]) uuid/uuid)
|
(let [file-id (some-> (get-in request [:params :file-id]) uuid/uuid)
|
||||||
revn (some-> (get-in request [:params :revn]) d/parse-integer)]
|
revn (some-> (get-in request [:params :revn]) d/parse-integer)
|
||||||
|
filename (str file-id)]
|
||||||
(when-not file-id
|
(when-not file-id
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :missing-arguments))
|
:code :missing-arguments))
|
||||||
|
@ -88,9 +89,9 @@
|
||||||
(some-> (db/exec-one! pool [sql:retrieve-single-change file-id revn]) :data)
|
(some-> (db/exec-one! pool [sql:retrieve-single-change file-id revn]) :data)
|
||||||
(some-> (db/get-by-id pool :file file-id) :data))]
|
(some-> (db/get-by-id pool :file file-id) :data))]
|
||||||
(if (contains? params :download)
|
(if (contains? params :download)
|
||||||
(-> (prepare-response request data)
|
(-> (prepare-response request data filename)
|
||||||
(update :headers assoc "content-type" "application/octet-stream"))
|
(update :headers assoc "content-type" "application/octet-stream"))
|
||||||
(prepare-response request (some-> data blob/decode))))))
|
(prepare-response request (some-> data blob/decode) filename)))))
|
||||||
|
|
||||||
(defn- upload-file-data
|
(defn- upload-file-data
|
||||||
[{:keys [pool]} {:keys [profile-id params] :as request}]
|
[{:keys [pool]} {:keys [profile-id params] :as request}]
|
||||||
|
@ -98,12 +99,18 @@
|
||||||
data (some-> params :file :path fs/slurp-bytes blob/decode)]
|
data (some-> params :file :path fs/slurp-bytes blob/decode)]
|
||||||
|
|
||||||
(if (and data project-id)
|
(if (and data project-id)
|
||||||
(let [fname (str "imported-file-" (dt/now))]
|
(let [fname (str "imported-file-" (dt/now))
|
||||||
(m.files/create-file pool {:id (uuid/next)
|
file-id (uuid/uuid (-> params :file :filename))
|
||||||
:name fname
|
file (db/exec-one! pool (sql/select :file {:id file-id}))]
|
||||||
:project-id project-id
|
(if file
|
||||||
:profile-id profile-id
|
(db/update! pool :file
|
||||||
:data data})
|
{:data (blob/encode data)}
|
||||||
|
{:id file-id})
|
||||||
|
(m.files/create-file pool {:id file-id
|
||||||
|
:name fname
|
||||||
|
:project-id project-id
|
||||||
|
:profile-id profile-id
|
||||||
|
:data data}))
|
||||||
(yrs/response 200 "OK"))
|
(yrs/response 200 "OK"))
|
||||||
(yrs/response 500 "ERROR"))))
|
(yrs/response 500 "ERROR"))))
|
||||||
|
|
||||||
|
@ -121,8 +128,9 @@
|
||||||
(ex/raise :type :authentication
|
(ex/raise :type :authentication
|
||||||
:code :only-admins-allowed))
|
:code :only-admins-allowed))
|
||||||
|
|
||||||
(let [file-id (some-> (get-in request [:params :id]) uuid/uuid)
|
(let [file-id (some-> (get-in request [:params :id]) uuid/uuid)
|
||||||
revn (or (get-in request [:params :revn]) "latest")]
|
revn (or (get-in request [:params :revn]) "latest")
|
||||||
|
filename (str file-id)]
|
||||||
|
|
||||||
(when (or (not file-id) (not revn))
|
(when (or (not file-id) (not revn))
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
|
@ -132,7 +140,7 @@
|
||||||
(cond
|
(cond
|
||||||
(d/num-string? revn)
|
(d/num-string? revn)
|
||||||
(let [item (db/exec-one! pool [sql:retrieve-single-change file-id (d/parse-integer revn)])]
|
(let [item (db/exec-one! pool [sql:retrieve-single-change file-id (d/parse-integer revn)])]
|
||||||
(prepare-response request (some-> item :changes blob/decode vec)))
|
(prepare-response request (some-> item :changes blob/decode vec) filename))
|
||||||
|
|
||||||
(str/includes? revn ":")
|
(str/includes? revn ":")
|
||||||
(let [[start end] (->> (str/split revn #":")
|
(let [[start end] (->> (str/split revn #":")
|
||||||
|
@ -144,7 +152,8 @@
|
||||||
(map :changes)
|
(map :changes)
|
||||||
(map blob/decode)
|
(map blob/decode)
|
||||||
(mapcat identity)
|
(mapcat identity)
|
||||||
(vec))))
|
(vec))
|
||||||
|
filename))
|
||||||
:else
|
:else
|
||||||
(ex/raise :type :validation :code :invalid-arguments))))
|
(ex/raise :type :validation :code :invalid-arguments))))
|
||||||
|
|
||||||
|
@ -176,8 +185,7 @@
|
||||||
(some-> report :error :trace))
|
(some-> report :error :trace))
|
||||||
:params (:params report)}]
|
:params (:params report)}]
|
||||||
(-> (io/resource "templates/error-report.tmpl")
|
(-> (io/resource "templates/error-report.tmpl")
|
||||||
(tmpl/render params))))
|
(tmpl/render params))))]
|
||||||
]
|
|
||||||
|
|
||||||
(when-not (authorized? pool request)
|
(when-not (authorized? pool request)
|
||||||
(ex/raise :type :authentication
|
(ex/raise :type :authentication
|
||||||
|
|
Loading…
Add table
Reference in a new issue