mirror of
https://github.com/penpot/penpot.git
synced 2025-07-08 01:37:17 +02:00
Replace internal storage impl with datoteka library.
This commit is contained in:
parent
4efe9ac5a9
commit
618ce12fd8
17 changed files with 33 additions and 726 deletions
|
@ -12,8 +12,8 @@
|
|||
[mount.core :as mount]
|
||||
[cuerdas.core :as str]
|
||||
[suricatta.core :as sc]
|
||||
[storages.core :as st]
|
||||
[storages.fs :as fs]
|
||||
[datoteka.storages :as st]
|
||||
[datoteka.core :as fs]
|
||||
[uxbox.config]
|
||||
[uxbox.db :as db]
|
||||
[uxbox.migrations]
|
||||
|
@ -68,7 +68,7 @@
|
|||
{:pre [(fs/path? localpath)
|
||||
(uuid? collid)
|
||||
(uuid? iconid)]}
|
||||
(let [filename (fs/base-name localpath)
|
||||
(let [filename (fs/name localpath)
|
||||
extension (second (fs/split-ext filename))
|
||||
data (svg/parse localpath)
|
||||
params {:name (:name data filename)
|
||||
|
@ -85,7 +85,7 @@
|
|||
(defn- import-icon
|
||||
[conn id fpath]
|
||||
{:pre [(uuid? id) (fs/path? fpath)]}
|
||||
(let [filename (fs/base-name fpath)
|
||||
(let [filename (fs/name fpath)
|
||||
iconid (uuid/namespaced +icons-uuid-ns+ (str id filename))]
|
||||
(when-not (retrieve-icon conn iconid)
|
||||
(println "Importing icon:" (str fpath))
|
||||
|
@ -95,8 +95,9 @@
|
|||
[conn basedir {:keys [path regex] :as entry}]
|
||||
{:pre [(us/valid? ::import-entry entry)]}
|
||||
(let [id (create-icons-collection conn entry)
|
||||
path (fs/resolve basedir path)]
|
||||
(doseq [fpath (fs/list-files path)]
|
||||
path (fs/join basedir path)]
|
||||
(doseq [fpath (->> (fs/list-dir path)
|
||||
(filter fs/regular-file?))]
|
||||
(when (re-matches regex (str fpath))
|
||||
(import-icon conn id fpath)))))
|
||||
|
||||
|
@ -137,7 +138,7 @@
|
|||
{:pre [(fs/path? localpath)
|
||||
(uuid? collid)
|
||||
(uuid? imageid)]}
|
||||
(let [filename (fs/base-name localpath)
|
||||
(let [filename (fs/name localpath)
|
||||
storage media/images-storage
|
||||
[width height] (retrieve-image-size localpath)
|
||||
extension (second (fs/split-ext filename))
|
||||
|
@ -157,7 +158,7 @@
|
|||
(defn- import-image
|
||||
[conn id fpath]
|
||||
{:pre [(uuid? id) (fs/path? fpath)]}
|
||||
(let [filename (fs/base-name fpath)
|
||||
(let [filename (fs/name fpath)
|
||||
imageid (uuid/namespaced +images-uuid-ns+ (str id filename))]
|
||||
(when-not (retrieve-image conn imageid)
|
||||
(println "Importing image:" (str fpath))
|
||||
|
@ -167,8 +168,9 @@
|
|||
[conn basedir {:keys [path regex] :as entry}]
|
||||
{:pre [(us/valid? ::import-entry entry)]}
|
||||
(let [id (create-images-collection conn entry)
|
||||
path (fs/resolve basedir path)]
|
||||
(doseq [fpath (fs/list-files path)]
|
||||
path (fs/join basedir path)]
|
||||
(doseq [fpath (->> (fs/list-dir path)
|
||||
(filter fs/regular-file?))]
|
||||
(when (re-matches regex (str fpath))
|
||||
(import-image conn id fpath)))))
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
(:require [clojure.spec :as s]
|
||||
[promesa.core :as p]
|
||||
[catacumba.http :as http]
|
||||
[storages.core :as st]
|
||||
[uxbox.util.spec :as us]
|
||||
[uxbox.services :as sv]
|
||||
[uxbox.util.response :refer (rsp)]
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
(:require [clojure.spec :as s]
|
||||
[promesa.core :as p]
|
||||
[catacumba.http :as http]
|
||||
[storages.core :as st]
|
||||
[storages.fs :as fs]
|
||||
[datoteka.storages :as st]
|
||||
[datoteka.core :as fs]
|
||||
[uxbox.media :as media]
|
||||
[uxbox.images :as images]
|
||||
[uxbox.util.spec :as us]
|
||||
|
@ -116,7 +116,7 @@
|
|||
(let [{:keys [file id width height
|
||||
mimetype collection]} (us/conform ::create-image data)
|
||||
id (or id (uuid/random))
|
||||
filename (fs/base-name file)
|
||||
filename (fs/name file)
|
||||
storage media/images-storage]
|
||||
(letfn [(persist-image-entry [path]
|
||||
(sv/novelty {:id id
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
(:require [clojure.spec :as s]
|
||||
[promesa.core :as p]
|
||||
[catacumba.http :as http]
|
||||
[storages.core :as st]
|
||||
[storages.fs :as fs]
|
||||
[datoteka.storages :as st]
|
||||
[datoteka.core :as fs]
|
||||
[uxbox.media :as media]
|
||||
[uxbox.images :as images]
|
||||
[uxbox.util.spec :as us]
|
||||
|
@ -80,7 +80,7 @@
|
|||
(defn update-photo
|
||||
[{user :identity data :data}]
|
||||
(letfn [(store-photo [file]
|
||||
(let [filename (fs/base-name file)
|
||||
(let [filename (fs/name file)
|
||||
storage media/images-storage]
|
||||
(st/save storage filename file)))
|
||||
(assign-photo [path]
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
(ns uxbox.images
|
||||
"Image postprocessing."
|
||||
(:require [clojure.spec :as s]
|
||||
[storages.core :as st]
|
||||
[storages.fs :as fs]
|
||||
[clojure.java.io :as io]
|
||||
[datoteka.storages :as st]
|
||||
[datoteka.core :as fs]
|
||||
[datoteka.proto :as pt]
|
||||
[uxbox.util.spec :as us]
|
||||
[uxbox.media :as media]
|
||||
[uxbox.util.images :as images]
|
||||
|
|
|
@ -6,15 +6,13 @@
|
|||
|
||||
(ns uxbox.media
|
||||
"A media storage impl for uxbox."
|
||||
(:require [mount.core :as mount :refer (defstate)]
|
||||
(:require [mount.core :refer [defstate]]
|
||||
[clojure.java.io :as io]
|
||||
[cuerdas.core :as str]
|
||||
[storages.core :as st]
|
||||
[storages.backend.local :refer (localfs)]
|
||||
[storages.backend.misc :refer (hashed scoped)]
|
||||
[uxbox.config :refer (config)]))
|
||||
|
||||
;; FIXME: migrate from storages to datoteka
|
||||
[datoteka.storages :as st]
|
||||
[datoteka.storages.local :refer [localfs]]
|
||||
[datoteka.storages.misc :refer [hashed scoped]]
|
||||
[uxbox.config :refer [config]]))
|
||||
|
||||
;; --- State
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
(:refer-clojure :exclude [with-open])
|
||||
(:require [clojure.java.io :as io]
|
||||
[suricatta.core :as sc]
|
||||
[storages.fs :as fs]
|
||||
[datoteka.core :as fs]
|
||||
[uxbox.db :as db]
|
||||
[uxbox.sql :as sql]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
(:require [clojure.spec :as s]
|
||||
[promesa.core :as p]
|
||||
[suricatta.core :as sc]
|
||||
[storages.core :as st]
|
||||
[storages.fs :as fs]
|
||||
[datoteka.storages :as st]
|
||||
[datoteka.core :as fs]
|
||||
[uxbox.config :as ucfg]
|
||||
[uxbox.util.spec :as us]
|
||||
[uxbox.sql :as sql]
|
||||
|
@ -184,7 +184,7 @@
|
|||
(ex/raise :type :validation
|
||||
:code ::image-does-not-exists))
|
||||
(let [path @(st/lookup storage (:path image))
|
||||
filename (fs/base-name path)
|
||||
filename (fs/name path)
|
||||
path @(st/save storage filename path)
|
||||
image (assoc image
|
||||
:path (str path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue