Adapt uxbox backend code to stroage module changes.

This commit is contained in:
Andrey Antukh 2016-11-22 21:42:44 +01:00
parent 6a3d8be32a
commit b319ee056d
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
7 changed files with 20 additions and 22 deletions

View file

@ -13,7 +13,7 @@
[cuerdas.core :as str] [cuerdas.core :as str]
[suricatta.core :as sc] [suricatta.core :as sc]
[storages.core :as st] [storages.core :as st]
[storages.util :as fs] [storages.fs :as fs]
[uxbox.config] [uxbox.config]
[uxbox.db :as db] [uxbox.db :as db]
[uxbox.migrations] [uxbox.migrations]

View file

@ -9,7 +9,7 @@
[promesa.core :as p] [promesa.core :as p]
[catacumba.http :as http] [catacumba.http :as http]
[storages.core :as st] [storages.core :as st]
[storages.util :as path] [storages.fs :as fs]
[uxbox.media :as media] [uxbox.media :as media]
[uxbox.images :as images] [uxbox.images :as images]
[uxbox.util.spec :as us] [uxbox.util.spec :as us]
@ -116,7 +116,7 @@
(let [{:keys [file id width height (let [{:keys [file id width height
mimetype collection]} (us/conform ::create-image data) mimetype collection]} (us/conform ::create-image data)
id (or id (uuid/random)) id (or id (uuid/random))
filename (path/base-name file) filename (fs/base-name file)
storage media/images-storage] storage media/images-storage]
(letfn [(persist-image-entry [path] (letfn [(persist-image-entry [path]
(sv/novelty {:id id (sv/novelty {:id id

View file

@ -9,7 +9,7 @@
[promesa.core :as p] [promesa.core :as p]
[catacumba.http :as http] [catacumba.http :as http]
[storages.core :as st] [storages.core :as st]
[storages.util :as path] [storages.fs :as fs]
[uxbox.media :as media] [uxbox.media :as media]
[uxbox.images :as images] [uxbox.images :as images]
[uxbox.util.spec :as us] [uxbox.util.spec :as us]
@ -80,7 +80,7 @@
(defn update-photo (defn update-photo
[{user :identity data :data}] [{user :identity data :data}]
(letfn [(store-photo [file] (letfn [(store-photo [file]
(let [filename (path/base-name file) (let [filename (fs/base-name file)
storage media/images-storage] storage media/images-storage]
(st/save storage filename file))) (st/save storage filename file)))
(assign-photo [path] (assign-photo [path]

View file

@ -6,9 +6,9 @@
(ns uxbox.images (ns uxbox.images
"Image postprocessing." "Image postprocessing."
(:require [storages.core :as st] (:require [clojure.spec :as s]
[storages.util :as path] [storages.core :as st]
[clojure.spec :as s] [storages.fs :as fs]
[uxbox.util.spec :as us] [uxbox.util.spec :as us]
[uxbox.media :as media] [uxbox.media :as media]
[uxbox.util.images :as images] [uxbox.util.images :as images]
@ -18,12 +18,12 @@
(defn make-thumbnail (defn make-thumbnail
[path {:keys [size format quality] :as cfg}] [path {:keys [size format quality] :as cfg}]
(let [parent (path/parent path) (let [parent (fs/parent path)
[filename ext] (path/split-ext path) [filename ext] (fs/split-ext path)
suffix-parts [(nth size 0) (nth size 1) quality format] suffix-parts [(nth size 0) (nth size 1) quality format]
final-name (apply str filename "-" (interpose "." suffix-parts)) final-name (apply str filename "-" (interpose "." suffix-parts))
final-path (path/path parent final-name) final-path (fs/path parent final-name)
images-storage media/images-storage images-storage media/images-storage
thumbs-storage media/thumbnails-storage] thumbs-storage media/thumbnails-storage]

View file

@ -10,19 +10,19 @@
[clojure.java.io :as io] [clojure.java.io :as io]
[cuerdas.core :as str] [cuerdas.core :as str]
[storages.core :as st] [storages.core :as st]
[storages.fs.local :refer (filesystem)] [storages.backend.local :refer (localfs)]
[storages.fs.misc :refer (hashed scoped)] [storages.backend.misc :refer (hashed scoped)]
[uxbox.config :refer (config)])) [uxbox.config :refer (config)]))
;; --- State ;; --- State
(defstate static-storage (defstate static-storage
:start (let [{:keys [basedir baseuri]} (:static config)] :start (let [{:keys [basedir baseuri]} (:static config)]
(filesystem {:basedir basedir :baseuri baseuri}))) (localfs {:basedir basedir :baseuri baseuri})))
(defstate media-storage (defstate media-storage
:start (let [{:keys [basedir baseuri]} (:media config)] :start (let [{:keys [basedir baseuri]} (:media config)]
(filesystem {:basedir basedir :baseuri baseuri}))) (localfs {:basedir basedir :baseuri baseuri})))
(defstate images-storage (defstate images-storage
:start (-> media-storage :start (-> media-storage

View file

@ -9,12 +9,11 @@
(:refer-clojure :exclude [with-open]) (:refer-clojure :exclude [with-open])
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[suricatta.core :as sc] [suricatta.core :as sc]
[storages.util :as path] [storages.fs :as fs]
[uxbox.db :as db] [uxbox.db :as db]
[uxbox.sql :as sql] [uxbox.sql :as sql]
[uxbox.util.uuid :as uuid] [uxbox.util.uuid :as uuid]
[uxbox.util.closeable :refer (with-open)] [uxbox.util.closeable :refer (with-open)]
[uxbox.util.tempfile :as tmpfile]
[uxbox.util.transit :as t] [uxbox.util.transit :as t]
[uxbox.util.snappy :as snappy])) [uxbox.util.snappy :as snappy]))
@ -55,7 +54,7 @@
"Given an id, returns a path to a temporal file with the exported "Given an id, returns a path to a temporal file with the exported
bundle of the specified project." bundle of the specified project."
[id] [id]
(let [path (tmpfile/create)] (let [path (fs/create-tempfile)]
(write-data path id) (write-data path id)
path)) path))
@ -105,7 +104,7 @@
(defn import! (defn import!
"Given a path to the previously exported bundle, try to import it." "Given a path to the previously exported bundle, try to import it."
[path] [path]
(with-open [istream (io/input-stream (path/path path)) (with-open [istream (io/input-stream (fs/path path))
zstream (snappy/input-stream istream) zstream (snappy/input-stream istream)
conn (db/connection)] conn (db/connection)]
(let [reader (t/reader zstream {:type :msgpack})] (let [reader (t/reader zstream {:type :msgpack})]

View file

@ -9,9 +9,8 @@
(:require [clojure.spec :as s] (:require [clojure.spec :as s]
[promesa.core :as p] [promesa.core :as p]
[suricatta.core :as sc] [suricatta.core :as sc]
[buddy.core.codecs :as codecs]
[storages.core :as st] [storages.core :as st]
[storages.util :as path] [storages.fs :as fs]
[uxbox.config :as ucfg] [uxbox.config :as ucfg]
[uxbox.util.spec :as us] [uxbox.util.spec :as us]
[uxbox.sql :as sql] [uxbox.sql :as sql]
@ -185,7 +184,7 @@
(ex/raise :type :validation (ex/raise :type :validation
:code ::image-does-not-exists)) :code ::image-does-not-exists))
(let [path @(st/lookup storage (:path image)) (let [path @(st/lookup storage (:path image))
filename (path/base-name path) filename (fs/base-name path)
path @(st/save storage filename path) path @(st/save storage filename path)
image (assoc image image (assoc image
:path (str path) :path (str path)