[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: http: Add /search/latest and /search/latest/<prod
From: |
Mathieu Othacehe |
Subject: |
branch master updated: http: Add /search/latest and /search/latest/<product-type> routes. |
Date: |
Mon, 22 Jun 2020 04:31:06 -0400 |
This is an automated email from the git hooks/post-receive script.
mothacehe pushed a commit to branch master
in repository guix-cuirass.
The following commit(s) were added to refs/heads/master by this push:
new 61cc56f http: Add /search/latest and /search/latest/<product-type>
routes.
61cc56f is described below
commit 61cc56f6cc9ac4985c0013968af43e4da70aa954
Author: Mathieu Othacehe <m.othacehe@gmail.com>
AuthorDate: Sun Jun 21 12:56:50 2020 +0200
http: Add /search/latest and /search/latest/<product-type> routes.
* src/cuirass/http.scm (url-handler): Add "/search/latest" and
"/search/latest/<product-type>" routes.
---
src/cuirass/http.scm | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 4da36bc..ddf63df 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -516,6 +516,60 @@ Hydra format."
query))
(respond-json-with-error 500 "Query parameter not provided!"))))
+ (('GET "search" "latest")
+ (let* ((params (request-parameters request))
+ (query (and=> (assq-ref params 'query) uri-decode)))
+ (if query
+ (match (vector->list
+ (handle-builds-search-request
+ `((query . ,query)
+ (nr . 1)
+ (order . finish-time+build-id))))
+ ((build)
+ (let ((uri (string->uri-reference
+ (string-append "/build/"
+ (number->string
+ (assoc-ref build #:id))
+ "/details"))))
+ (respond (build-response #:code 302
+ #:headers `((location . ,uri)))
+ #:body "")))
+ (_
+ (respond-json-with-error 500 "No build found.")))
+ (respond-json-with-error 500 "Query parameter not provided."))))
+
+ (('GET "search" "latest" product-type)
+ (let* ((params (request-parameters request))
+ (query (and=> (assq-ref params 'query) uri-decode)))
+ (if query
+ (match (vector->list
+ (handle-builds-search-request
+ `((query . ,query)
+ (nr . 1)
+ (order . finish-time+build-id))))
+ ((build)
+ (let* ((build-id (assoc-ref build #:id))
+ (products (db-get-build-products build-id))
+ (product (find (lambda (product)
+ (string=? (assoc-ref product #:type)
+ product-type))
+ products))
+ (product-id (assoc-ref product #:id))
+ (uri (and product-id
+ (string->uri-reference
+ (string-append "/download/"
+ (number->string product-id))))))
+ (if uri
+ (respond (build-response #:code 302
+ #:headers `((location . ,uri)))
+ #:body "")
+ (respond-json-with-error
+ 500
+ "Could not find the request build product."))))
+ (_
+ (respond-json-with-error 500 "No build found.")))
+ (respond-json-with-error 500 "Query parameter not provided."))))
+
(('GET "download" id)
(let ((path (db-get-build-product-path id)))
(respond-file path)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: http: Add /search/latest and /search/latest/<product-type> routes.,
Mathieu Othacehe <=