mirror of
https://github.com/penpot/penpot.git
synced 2025-03-16 01:31:22 -05:00
🔥 Remove unused media related api.
This commit is contained in:
parent
b71d5d26a6
commit
b2957c5f35
8 changed files with 10 additions and 216 deletions
|
@ -160,35 +160,6 @@
|
||||||
|
|
||||||
;; --- Utility functions
|
;; --- Utility functions
|
||||||
|
|
||||||
(defn resolve-urls
|
|
||||||
[row src dst]
|
|
||||||
(s/assert map? row)
|
|
||||||
(if (and src dst)
|
|
||||||
(let [src (if (vector? src) src [src])
|
|
||||||
dst (if (vector? dst) dst [dst])
|
|
||||||
value (get-in row src)]
|
|
||||||
(if (empty? value)
|
|
||||||
row
|
|
||||||
(let [url (ust/public-uri mst/media-storage value)]
|
|
||||||
(assoc-in row dst (str url)))))
|
|
||||||
row))
|
|
||||||
|
|
||||||
(defn- resolve-uri
|
|
||||||
[storage row src dst]
|
|
||||||
(let [src (if (vector? src) src [src])
|
|
||||||
dst (if (vector? dst) dst [dst])
|
|
||||||
value (get-in row src)]
|
|
||||||
(if (empty? value)
|
|
||||||
row
|
|
||||||
(let [url (ust/public-uri mst/media-storage value)]
|
|
||||||
(assoc-in row dst (str url))))))
|
|
||||||
|
|
||||||
(defn resolve-media-uris
|
|
||||||
[row & pairs]
|
|
||||||
(us/assert map? row)
|
|
||||||
(us/assert (s/coll-of vector?) pairs)
|
|
||||||
(reduce #(resolve-uri mst/media-storage %1 (nth %2 0) (nth %2 1)) row pairs))
|
|
||||||
|
|
||||||
(defn validate-media-type
|
(defn validate-media-type
|
||||||
[media-type]
|
[media-type]
|
||||||
(when-not (cm/valid-media-types media-type)
|
(when-not (cm/valid-media-types media-type)
|
||||||
|
@ -196,6 +167,11 @@
|
||||||
:code :media-type-not-allowed
|
:code :media-type-not-allowed
|
||||||
:hint "Seems like you are uploading an invalid media object")))
|
:hint "Seems like you are uploading an invalid media object")))
|
||||||
|
|
||||||
|
|
||||||
|
;; TODO: rewrite using jetty http client instead of jvm
|
||||||
|
;; builtin (because builtin http client uses a lot of memory for the
|
||||||
|
;; same operation.
|
||||||
|
|
||||||
(defn download-media-object
|
(defn download-media-object
|
||||||
[url]
|
[url]
|
||||||
(let [result (http/get! url {:as :byte-array})
|
(let [result (http/get! url {:as :byte-array})
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
(defn- load-query-services
|
(defn- load-query-services
|
||||||
[]
|
[]
|
||||||
(require 'app.services.queries.media)
|
|
||||||
(require 'app.services.queries.projects)
|
(require 'app.services.queries.projects)
|
||||||
(require 'app.services.queries.files)
|
(require 'app.services.queries.files)
|
||||||
(require 'app.services.queries.comments)
|
(require 'app.services.queries.comments)
|
||||||
|
|
|
@ -147,56 +147,3 @@
|
||||||
(-> thumb
|
(-> thumb
|
||||||
(dissoc :data :input)
|
(dissoc :data :input)
|
||||||
(assoc :path path))))
|
(assoc :path path))))
|
||||||
|
|
||||||
;; --- Mutation: Rename Media object
|
|
||||||
|
|
||||||
(declare select-media-object-for-update)
|
|
||||||
|
|
||||||
(s/def ::rename-media-object
|
|
||||||
(s/keys :req-un [::id ::profile-id ::name]))
|
|
||||||
|
|
||||||
(sm/defmutation ::rename-media-object
|
|
||||||
[{:keys [id profile-id name] :as params}]
|
|
||||||
(db/with-atomic [conn db/pool]
|
|
||||||
(let [obj (select-media-object-for-update conn id)]
|
|
||||||
(teams/check-edition-permissions! conn profile-id (:team-id obj))
|
|
||||||
(db/update! conn :media-object
|
|
||||||
{:name name}
|
|
||||||
{:id id}))))
|
|
||||||
|
|
||||||
(def ^:private sql:select-media-object-for-update
|
|
||||||
"select obj.*,
|
|
||||||
p.team_id as team_id
|
|
||||||
from media_object as obj
|
|
||||||
inner join file as f on (f.id = obj.file_id)
|
|
||||||
inner join project as p on (p.id = f.project_id)
|
|
||||||
where obj.id = ?
|
|
||||||
for update of obj")
|
|
||||||
|
|
||||||
(defn- select-media-object-for-update
|
|
||||||
[conn id]
|
|
||||||
(let [row (db/exec-one! conn [sql:select-media-object-for-update id])]
|
|
||||||
(when-not row
|
|
||||||
(ex/raise :type :not-found))
|
|
||||||
row))
|
|
||||||
|
|
||||||
;; --- Delete Media object
|
|
||||||
|
|
||||||
(s/def ::delete-media-object
|
|
||||||
(s/keys :req-un [::id ::profile-id]))
|
|
||||||
|
|
||||||
(sm/defmutation ::delete-media-object
|
|
||||||
[{:keys [profile-id id] :as params}]
|
|
||||||
(db/with-atomic [conn db/pool]
|
|
||||||
(let [obj (select-media-object-for-update conn id)]
|
|
||||||
(teams/check-edition-permissions! conn profile-id (:team-id obj))
|
|
||||||
|
|
||||||
;; Schedule object deletion
|
|
||||||
(tasks/submit! conn {:name "delete-object"
|
|
||||||
:delay cfg/default-deletion-delay
|
|
||||||
:props {:id id :type :media-object}})
|
|
||||||
|
|
||||||
(db/update! conn :media-object
|
|
||||||
{:deleted-at (dt/now)}
|
|
||||||
{:id id})
|
|
||||||
nil)))
|
|
||||||
|
|
|
@ -202,10 +202,7 @@
|
||||||
|
|
||||||
(defn retrieve-file-users
|
(defn retrieve-file-users
|
||||||
[conn id]
|
[conn id]
|
||||||
(->> (db/exec! conn [sql:file-users id id])
|
(db/exec! conn [sql:file-users id id]))
|
||||||
;; TODO: seems like the frontend is no longer uses :photo-uri,
|
|
||||||
;; so this can be removed probably.
|
|
||||||
(mapv #(media/resolve-media-uris % [:photo :photo-uri]))))
|
|
||||||
|
|
||||||
(s/def ::file-users
|
(s/def ::file-users
|
||||||
(s/keys :req-un [::profile-id ::id]))
|
(s/keys :req-un [::profile-id ::id]))
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
||||||
;; defined by the Mozilla Public License, v. 2.0.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2019-2020 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns app.services.queries.media
|
|
||||||
(:require
|
|
||||||
[clojure.spec.alpha :as s]
|
|
||||||
[app.common.exceptions :as ex]
|
|
||||||
[app.common.spec :as us]
|
|
||||||
[app.db :as db]
|
|
||||||
[app.media :as media]
|
|
||||||
[app.services.queries :as sq]
|
|
||||||
[app.services.queries.teams :as teams]))
|
|
||||||
|
|
||||||
(s/def ::id ::us/uuid)
|
|
||||||
(s/def ::name ::us/string)
|
|
||||||
(s/def ::profile-id ::us/uuid)
|
|
||||||
(s/def ::team-id ::us/uuid)
|
|
||||||
(s/def ::file-id ::us/uuid)
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Query: Media objects (by file)
|
|
||||||
|
|
||||||
(declare retrieve-media-objects)
|
|
||||||
(declare retrieve-file)
|
|
||||||
|
|
||||||
(s/def ::is-local ::us/boolean)
|
|
||||||
(s/def ::media-objects
|
|
||||||
(s/keys :req-un [::profile-id ::file-id ::is-local]))
|
|
||||||
|
|
||||||
;; TODO: check if we can resolve url with transducer for reduce
|
|
||||||
;; garbage generation for each request
|
|
||||||
|
|
||||||
(sq/defquery ::media-objects
|
|
||||||
[{:keys [profile-id file-id is-local] :as params}]
|
|
||||||
(db/with-atomic [conn db/pool]
|
|
||||||
(let [file (retrieve-file conn file-id)]
|
|
||||||
(teams/check-read-permissions! conn profile-id (:team-id file))
|
|
||||||
(->> (retrieve-media-objects conn file-id is-local)
|
|
||||||
(mapv #(media/resolve-urls % :path :uri))
|
|
||||||
(mapv #(media/resolve-urls % :thumb-path :thumb-uri))))))
|
|
||||||
|
|
||||||
(def ^:private sql:media-objects
|
|
||||||
"select obj.*,
|
|
||||||
thumb.path as thumb_path
|
|
||||||
from media_object as obj
|
|
||||||
inner join media_thumbnail as thumb on obj.id = thumb.media_object_id
|
|
||||||
where obj.deleted_at is null
|
|
||||||
and obj.file_id = ?
|
|
||||||
and obj.is_local = ?
|
|
||||||
order by obj.created_at desc")
|
|
||||||
|
|
||||||
(defn retrieve-media-objects
|
|
||||||
[conn file-id is-local]
|
|
||||||
(db/exec! conn [sql:media-objects file-id is-local]))
|
|
||||||
|
|
||||||
(def ^:private sql:retrieve-file
|
|
||||||
"select file.*,
|
|
||||||
project.team_id as team_id
|
|
||||||
from file
|
|
||||||
inner join project on (project.id = file.project_id)
|
|
||||||
where file.id = ?")
|
|
||||||
|
|
||||||
(defn- retrieve-file
|
|
||||||
[conn id]
|
|
||||||
(let [row (db/exec-one! conn [sql:retrieve-file id])]
|
|
||||||
(when-not row
|
|
||||||
(ex/raise :type :not-found))
|
|
||||||
row))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Query: Media object (by ID)
|
|
||||||
|
|
||||||
(declare retrieve-media-object)
|
|
||||||
|
|
||||||
(s/def ::id ::us/uuid)
|
|
||||||
(s/def ::media-object
|
|
||||||
(s/keys :req-un [::profile-id ::id]))
|
|
||||||
|
|
||||||
(sq/defquery ::media-object
|
|
||||||
[{:keys [profile-id id] :as params}]
|
|
||||||
(db/with-atomic [conn db/pool]
|
|
||||||
(let [media-object (retrieve-media-object conn id)]
|
|
||||||
(teams/check-read-permissions! conn profile-id (:team-id media-object))
|
|
||||||
(-> media-object
|
|
||||||
(media/resolve-urls :path :uri)))))
|
|
||||||
|
|
||||||
(def ^:private sql:media-object
|
|
||||||
"select obj.*,
|
|
||||||
p.team_id as team_id
|
|
||||||
from media_object as obj
|
|
||||||
inner join file as f on (f.id = obj.file_id)
|
|
||||||
inner join project as p on (p.id = f.project_id)
|
|
||||||
where obj.deleted_at is null
|
|
||||||
and obj.id = ?
|
|
||||||
order by created_at desc")
|
|
||||||
|
|
||||||
(defn retrieve-media-object
|
|
||||||
[conn id]
|
|
||||||
(let [row (db/exec-one! conn [sql:media-object id])]
|
|
||||||
(when-not row
|
|
||||||
(ex/raise :type :not-found))
|
|
||||||
row))
|
|
||||||
|
|
|
@ -9,15 +9,13 @@
|
||||||
|
|
||||||
(ns app.services.queries.profile
|
(ns app.services.queries.profile
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.db :as db]
|
|
||||||
[app.media :as media]
|
|
||||||
[app.services.queries :as sq]
|
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.util.blob :as blob]))
|
[app.db :as db]
|
||||||
|
[app.services.queries :as sq]
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
;; --- Helpers & Specs
|
;; --- Helpers & Specs
|
||||||
|
|
||||||
|
@ -82,7 +80,6 @@
|
||||||
(defn retrieve-profile
|
(defn retrieve-profile
|
||||||
[conn id]
|
[conn id]
|
||||||
(let [profile (some-> (retrieve-profile-data conn id)
|
(let [profile (some-> (retrieve-profile-data conn id)
|
||||||
(media/resolve-urls :photo :photo-uri)
|
|
||||||
(strip-private-attrs)
|
(strip-private-attrs)
|
||||||
(merge (retrieve-additional-data conn id)))]
|
(merge (retrieve-additional-data conn id)))]
|
||||||
(when (nil? profile)
|
(when (nil? profile)
|
||||||
|
|
|
@ -1706,7 +1706,6 @@
|
||||||
(def link-file-to-library dwp/link-file-to-library)
|
(def link-file-to-library dwp/link-file-to-library)
|
||||||
(def unlink-file-from-library dwp/unlink-file-from-library)
|
(def unlink-file-from-library dwp/unlink-file-from-library)
|
||||||
(def upload-media-objects dwp/upload-media-objects)
|
(def upload-media-objects dwp/upload-media-objects)
|
||||||
(def delete-media-object dwp/delete-media-object)
|
|
||||||
|
|
||||||
;; Selection
|
;; Selection
|
||||||
|
|
||||||
|
|
|
@ -422,18 +422,6 @@
|
||||||
(rx/finalize (fn []
|
(rx/finalize (fn []
|
||||||
(st/emit! (dm/hide-tag :media-loading))))))))))
|
(st/emit! (dm/hide-tag :media-loading))))))))))
|
||||||
|
|
||||||
|
|
||||||
;; --- Delete media object
|
|
||||||
|
|
||||||
(defn delete-media-object
|
|
||||||
[file-id id]
|
|
||||||
(ptk/reify ::delete-media-object
|
|
||||||
ptk/WatchEvent
|
|
||||||
(watch [_ state stream]
|
|
||||||
(let [params {:id id}]
|
|
||||||
(rp/mutation :delete-media-object params)))))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Helpers
|
;; --- Helpers
|
||||||
|
|
||||||
(defn purge-page
|
(defn purge-page
|
||||||
|
|
Loading…
Add table
Reference in a new issue