Skip to content

Commit

Permalink
Add examples and code to download images
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed Sep 20, 2024
1 parent 5761362 commit 29ad110
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
31 changes: 31 additions & 0 deletions src/clj/daisyproducer2/documents/alfresco.clj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@
(:body (client/get (str url "/alfresco/versions/1/nodes/" node-id "/versions/" version-id "/content")
{:basic-auth [user password]}))))

(defn- images
"Return a list of image node-ids for a given book `node-id`"
[node-id]
(let [{:keys [url user password]} (env :alfresco)]
(-> (str url "/alfresco/versions/1/nodes/" node-id "/children")
(client/get
{:as :json
:basic-auth [user password]
:query-params {"relativePath" "Bilder"
"where" "(nodeType='sbs:graphic')"
;; ignore the fact that this is paginated content. Just fetch
;; lots of items so that we most likely get them all
"maxItems" 5000
"fields" "id,content"}})
(get-in [:body :list :entries])
(->>
(filter (fn [item] (= (get-in item [:entry :content :mimeType]) "image/jpeg")))
(map #(get-in % [:entry :id]))))))

(defn- image-content [ids]
(let [{:keys [url user password]} (env :alfresco)]
(client/post (str url "/alfresco/versions/1/downloads/")
{:as :json
:basic-auth [user password]
:body (json/generate-string {:nodeIds (apply vector ids)})})
;; grab the id of the download from the response
;; wait until the download is ready, i.e. the response contains :status "DONE"
;; then fetch the content
;; all of this probably asynchronously
))

(defn content-for-product [product-id]
(let [daisy-file-node (-> product-id product parent daisy-file)
version (latest-version daisy-file-node)]
Expand Down
23 changes: 18 additions & 5 deletions test/alfresco.http
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Authorization: :auth

{
"query": {
"query": "select * from sbs:buch where sbs:pISBN = ' 978-3-03815-104-3'",
"query": "select * from sbs:buch where sbs:pISBN = '978-3-03815-104-3'",
"language": "cmis"
}
}
Expand All @@ -126,10 +126,23 @@ Authorization: :auth
GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/nodes/04517227-05ce-4051-a384-08a89a7527c0/children?where=(nodeType='cm:folder')&fields=name,id,nodeType
Authorization: :auth

# get the image folder
GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/nodes/04517227-05ce-4051-a384-08a89a7527c0/children?where=(name=Bilder)&fields=name,id,nodeType
# get the image folder using the relativePath parameter
GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/nodes/04517227-05ce-4051-a384-08a89a7527c0?relativePath=Bilder&fields=name,id,nodeType
Authorization: :auth

# get all children of the image folder
GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/nodes/e02bd3cb-4be0-4d83-9787-cedbcdc86e39/children?fields=name,id,nodeType,content
# get all image children of the image folder using the relativePath parameter
GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/nodes/04517227-05ce-4051-a384-08a89a7527c0/children?relativePath=Bilder&where=(nodeType='sbs:graphic')&fields=name,id,nodeType
Authorization: :auth

GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/nodes/e02bd3cb-4be0-4d83-9787-cedbcdc86e39/children?where=(nodeType='sbs:graphic')&fields=name,id,nodeType,content
Authorization: :auth

# get the status of the download
GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/downloads/6cf521f7-0632-4022-a5da-ebfa58554a87
Authorization: :auth

# get the content of the download
GET https://pam04.sbszh.ch/alfresco/api/-default-/public/alfresco/versions/1/nodes/6cf521f7-0632-4022-a5da-ebfa58554a87/content
Authorization: :auth

# see https://docs.alfresco.com/content-services/6.1/develop/rest-api-guide/folders-files/#downloadfile

0 comments on commit 29ad110

Please sign in to comment.