Skip to content

Commit

Permalink
0.3.0 Add skip media files option
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTom committed Jul 10, 2017
1 parent 7088418 commit 54b65bc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/prod/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Madek",
"version": "0.1.0",
"version": "0.3.0",
"main": "js/main.js"
}
29 changes: 22 additions & 7 deletions electron_front/src/all/madek/app/front/download/step2.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

(defn submit []
(let [req {:method :patch
:json-params (assoc (select-keys @form-data* [:prefix_meta_key :recursive])
:json-params (assoc (select-keys @form-data*
[:prefix_meta_key :recursive :skip_media_files])
:step2-completed true)
:path "/download"}]
(request/send-off
Expand All @@ -56,18 +57,31 @@

;;; recursive ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn recursive-from-group-component []
(defn recursive-component []
(when (= :collection (-> @download* :entity :type))
[:div.recursive
[:h4 "Recursion on sets"]
[:div.form-group
[:label "Recursive export: "]
[:br]
[:input {:type :checkbox
:on-click #(set-value :recursive (-> @form-data* :recursive not))
:checked (-> @form-data* :recursive)} ] " recurse"
[:p.help-block "Sets and media-entries which are descendants of the selected set "
" will be exported if this option is enabled.."
" will be exported if this option is enabled."
"Recurring entities will be replaced by symbolic links the file system and "
"therefore infinite recursion is avoided." ]]))
"therefore infinite recursion is avoided." ]]]))

;;; recursive ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn skip-media-files []
[:div.recursive
[:h4 "Skip files"]
[:div.form-group
[:input {:type :checkbox
:on-click #(set-value :skip_media_files (-> @form-data* :skip_media_files not))
:checked (-> @form-data* :skip_media_files)} ] " skip files"
[:p.help-block "The download of any media-files will be skipped if this is checked. "
"This means that only the meta-data of media-entries or sets will be downloaded. " ]]])


;;; prefix ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down Expand Up @@ -153,8 +167,9 @@

(defn form-component []
[:div.form
[recursive-from-group-component]
[recursive-component]
[prefix-component]
[skip-media-files]
[:div.pull-left
[:button.btn.btn-info
{:on-click back}
Expand Down
11 changes: 8 additions & 3 deletions electron_front/src/all/madek/app/front/download/step3.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@

(defn summary-component []
[:div.summary
[:p " Export/Download the set "
[:p " Export/Download the " (case (-> @state/jvm-main-db :download :entity :type)
:collection "set"
:media-entry "media-entry"
"???") " "
[:a {:href "#"
:on-click #(.openExternal
shell (-> @state/jvm-main-db :download :entity :url))}
[:em (-> @state/jvm-main-db :download :entity :title)]]]
[:p "Export to " [:code (-> @state/jvm-main-db :download :target-directory)] "."]
[:p "Recursive: " [:code (-> @state/jvm-main-db :download :recursive not not str)] "."]
[:p "Meta-key used for prefixing entities: " (if-let [pmk (-> @state/jvm-main-db :download :prefix_meta_key presence)]
[:code pmk]
[:span "none"]) "."]])
[:code pmk]
[:span "none"]) "."]
[:p "Skip media-files " [:code (-> @state/jvm-main-db :download :skip_media_files not not str)]"."]])

(defn debug-component []
(when (:debug @state/client-db)
Expand Down
17 changes: 9 additions & 8 deletions jvm_main/src/madek/app/server/export.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@
id))

(defn download-media-entry
([id target-dir prefix-meta-key api-entry-point api-http-opts]
([id target-dir skip-media-files? prefix-meta-key api-entry-point api-http-opts]
(catcher/with-logging {}
(let [media-entry (I> identity-with-logging
(roa/get-root api-entry-point
:default-conn-opts api-http-opts)
(roa/relation :media-entry)
(roa/get {:id id}))]
(download-media-entry prefix-meta-key target-dir media-entry))))
([prefix-meta-key dir-path media-entry]
(download-media-entry skip-media-files? prefix-meta-key target-dir media-entry))))
([skip-media-files? prefix-meta-key dir-path media-entry]
(catcher/with-logging {}
(let [id (-> media-entry roa/data :id)
entry-prefix-path (path-prefix prefix-meta-key media-entry)
Expand All @@ -109,7 +109,8 @@
:download_started-at (str (time/now))))
(io/make-parents entry-dir-path)
(write-meta-data entry-dir-path meta-data id)
(download-media-files entry-dir-path media-entry)
(when-not skip-media-files?
(download-media-files entry-dir-path media-entry))
(set-item-to-finished id)))))))


Expand All @@ -126,7 +127,7 @@

(declare download-set)

(defn download-media-entries-for-set [id target-dir-path prefix-meta-key
(defn download-media-entries-for-set [id target-dir-path skip-media-files? prefix-meta-key
api-entry-point api-http-opts]
(let [me-get-opts (merge {:collection_id id}
(if (or (:basic-auth api-http-opts)
Expand All @@ -139,7 +140,7 @@
(roa/relation :media-entries)
(roa/get me-get-opts)
roa/coll-seq)]
(download-media-entry prefix-meta-key target-dir-path (roa/get me-rel {})))))
(download-media-entry skip-media-files? prefix-meta-key target-dir-path (roa/get me-rel {})))))

(defn download-collections-for-collection [collection target-dir-path recursive?
prefix-meta-key api-entry-point api-http-opts]
Expand All @@ -158,7 +159,7 @@
(-> collection roa/data :id)
target-dir-path recursive? prefix-meta-key api-entry-point api-http-opts))))

(defn download-set [id dl-path recursive? prefix-meta-key
(defn download-set [id dl-path recursive? skip-media-files? prefix-meta-key
api-entry-point api-http-opts]
(let [collection (-> (roa/get-root api-entry-point
:default-conn-opts api-http-opts)
Expand All @@ -183,7 +184,7 @@
(io/make-parents target-dir-path)
(write-meta-data target-dir-path meta-data id)
(download-media-entries-for-set
id target-dir-path prefix-meta-key api-entry-point api-http-opts)
id target-dir-path skip-media-files? prefix-meta-key api-entry-point api-http-opts)
(when recursive?
(download-collections-for-collection
collection target-dir-path recursive? prefix-meta-key
Expand Down
11 changes: 6 additions & 5 deletions jvm_main/src/madek/app/server/web.clj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
e))
:throwable Throwable})

(defn start-download-future [id target-dir recursive? prefix-meta-key entry-point http-options]
(defn start-download-future [id target-dir recursive? skip-media-files? prefix-meta-key entry-point http-options]
(reset! download-future
(future
(catcher/snatch
Expand All @@ -111,10 +111,10 @@
:throwable Throwable}
(case (-> @state/db :download :entity :type)
:collection (export/download-set
id target-dir recursive? prefix-meta-key
entry-point http-options)
id target-dir recursive? skip-media-files?
prefix-meta-key entry-point http-options)
:media-entry (export/download-media-entry
id target-dir prefix-meta-key
id target-dir skip-media-files? prefix-meta-key
entry-point http-options))
(swap! state/db (fn [db] (assoc-in db [:download :download-finished] true)))))))

Expand All @@ -135,10 +135,11 @@
(let [id (-> @state/db :download :entity :uuid)
target-dir (-> @state/db :download :target-directory)
recursive? (-> @state/db :download :recursive not not)
skip-media-files? (-> @state/db :download :skip_media_files not not)
prefix-meta-key (-> @state/db :download :prefix_meta_key presence)
entry-point (str (-> @state/db :connection :url) "/api")
http-options (-> @state/db :connection :http-options)]
(start-download-future id target-dir recursive? prefix-meta-key entry-point http-options))
(start-download-future id target-dir recursive? skip-media-files? prefix-meta-key entry-point http-options))
{:status 202})))

(defn patch-download-item [request]
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject madek "0.2.0"
(defproject madek "0.3.0"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "GPL"
Expand Down

0 comments on commit 54b65bc

Please sign in to comment.