Skip to content

Commit

Permalink
Clean up temp files after image and version upload
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed May 13, 2024
1 parent 80b57c5 commit fcfcfee
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/clj/daisyproducer2/routes/services.clj
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,14 @@
new-url (format "/documents/%s/versions/%s" id new-key)]
;; update the unknown words list for this document
(unknown/update-words tempfile id)
(fs/delete tempfile)
(created new-url {})) ;; add an empty body
(catch clojure.lang.ExceptionInfo e
(let [{:keys [error-id errors]} (ex-data e)
message (ex-message e)]
(log/warn message error-id errors)
(bad-request {:status-text (ex-message e) :errors errors})))))}}]
(bad-request {:status-text (ex-message e) :errors errors})))
(finally
(fs/delete tempfile))))}}]

["/:version-id"
{:get {:summary "Get a version"
Expand Down Expand Up @@ -486,9 +487,12 @@
:parameters {:path {:id int?} :multipart {:file multipart/temp-file-part}}
:handler (fn [{{{:keys [id]} :path {{:keys [filename tempfile]} :file} :multipart} :parameters
{{uid :uid} :user} :identity}]
(let [new-key (images/insert-image id filename tempfile)
new-url (format "/documents/%s/images/%s" id new-key)]
(created new-url {})))}
(try
(let [new-key (images/insert-image id filename tempfile)
new-url (format "/documents/%s/images/%s" id new-key)]
(created new-url {}))
(finally
(fs/delete tempfile))))}
:delete {:summary "Delete all images of a given document"
:middleware [wrap-restricted]
:swagger {:security [{:apiAuth []}]}
Expand Down

0 comments on commit fcfcfee

Please sign in to comment.