0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

Merge pull request #5086 from penpot/niwinz-bugfix-1

🐛 Ignore object thumbnail requests if file is already marked as deleted
This commit is contained in:
Alejandro 2024-09-13 12:30:27 +02:00 committed by GitHub
commit a0546b2e63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 37 additions and 15 deletions

View file

@ -273,7 +273,7 @@
(defn get-minimal-file
[cfg id & {:as opts}]
(let [opts (assoc opts ::sql/columns [:id :modified-at :revn :data-ref-id :data-backend])]
(let [opts (assoc opts ::sql/columns [:id :modified-at :deleted-at :revn :data-ref-id :data-backend])]
(db/get cfg :file {:id id} opts)))
(defn get-file-etag

View file

@ -233,7 +233,7 @@
"INSERT INTO file_tagged_object_thumbnail (file_id, object_id, tag, media_id)
VALUES (?, ?, ?, ?)
ON CONFLICT (file_id, object_id, tag)
DO UPDATE SET updated_at=?, media_id=?, deleted_at=null
DO UPDATE SET updated_at=?, media_id=?, deleted_at=?
RETURNING *")
(defn- persist-thumbnail!
@ -251,17 +251,19 @@
:content-type mtype
:bucket "file-object-thumbnail"})))
(defn- create-file-object-thumbnail!
[{:keys [::sto/storage] :as cfg} file-id object-id media tag]
(let [tsnow (dt/now)
media (persist-thumbnail! storage media tsnow)
[{:keys [::sto/storage] :as cfg} file object-id media tag]
(let [file-id (:id file)
timestamp (dt/now)
media (persist-thumbnail! storage media timestamp)
[th1 th2] (db/tx-run! cfg (fn [{:keys [::db/conn]}]
(let [th1 (db/exec-one! conn [sql:get-file-object-thumbnail file-id object-id tag])
th2 (db/exec-one! conn [sql:create-file-object-thumbnail
file-id object-id tag (:id media)
tsnow (:id media)])]
file-id object-id tag
(:id media)
timestamp
(:id media)
(:deleted-at file)])]
[th1 th2])))]
(when (and (some? th1)
@ -294,8 +296,8 @@
(media/validate-media-size! media)
(db/run! cfg files/check-edition-permissions! profile-id file-id)
(create-file-object-thumbnail! cfg file-id object-id media (or tag "frame")))
(when-let [file (files/get-minimal-file cfg file-id {::db/check-deleted false})]
(create-file-object-thumbnail! cfg file object-id media (or tag "frame"))))
;; --- MUTATION COMMAND: delete-file-object-thumbnail

View file

@ -75,6 +75,7 @@
:created-at (:created-at file)
:modified-at (:modified-at file)
:data-backend nil
:data-ref-id nil
:has-media-trimmed false}
{:id (:id file)})))

View file

@ -133,7 +133,13 @@
file))
(def ^:private sql:get-files-for-library
"SELECT f.id, f.data, f.modified_at, f.features, f.version
"SELECT f.id,
f.data,
f.modified_at,
f.features,
f.version,
f.data_backend,
f.data_ref_id
FROM file AS f
LEFT JOIN file_library_rel AS fl ON (fl.file_id = f.id)
WHERE fl.library_file_id = ?

View file

@ -6,4 +6,4 @@
(ns app.common.files.defaults)
(def version 51)
(def version 52)

View file

@ -1010,13 +1010,25 @@
(defn migrate-up-51
"This migration fixes library invalid colors"
[data]
(let [update-colors
(fn [colors]
(into {} (filter #(-> % val valid-color?) colors)))]
(update data :colors update-colors)))
(defn migrate-up-52
"Fixes incorrect value on `layout-wrap-type` prop"
[data]
(letfn [(update-shape [shape]
(if (= :no-wrap (:layout-wrap-type shape))
(assoc shape :layout-wrap-type :nowrap)
shape))
(update-page [page]
(d/update-when page :objects update-vals update-shape))]
(update data :pages-index update-vals update-page)))
(def migrations
"A vector of all applicable migrations"
[{:id 2 :migrate-up migrate-up-2}
@ -1059,4 +1071,5 @@
{:id 48 :migrate-up migrate-up-48}
{:id 49 :migrate-up migrate-up-49}
{:id 50 :migrate-up migrate-up-50}
{:id 51 :migrate-up migrate-up-51}])
{:id 51 :migrate-up migrate-up-51}
{:id 52 :migrate-up migrate-up-52}])