From c5fe0d217b11b7604d3c63097c18660cc37bf39a Mon Sep 17 00:00:00 2001 From: whatdoineed2do/Ray Date: Sat, 9 May 2020 17:09:03 +0100 Subject: [PATCH 1/2] [jsonapi] support 'limit' on 'api/queue/items/add?expression=' Extend to support SMART query allows 'limit' curl -X POST "http://localhost:3689/api/queue/items/add?expression=genre+is+%22Pop%22+order+by+time_added+desc+limit+3" --- src/httpd_jsonapi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index 3df3e597..d162f2e7 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -2299,7 +2299,6 @@ queue_tracks_add_byexpression(const char *param, int pos, int *total_count) query_params.type = Q_ITEMS; query_params.sort = S_NAME; - query_params.idx_type = I_NONE; memset(&smartpl_expression, 0, sizeof(struct smartpl)); expression = safe_asprintf("\"query\" { %s }", param); @@ -2311,10 +2310,13 @@ queue_tracks_add_byexpression(const char *param, int pos, int *total_count) query_params.filter = strdup(smartpl_expression.query_where); query_params.order = safe_strdup(smartpl_expression.order); + query_params.limit = smartpl_expression.limit; free_smartpl(&smartpl_expression, 1); player_get_status(&status); + query_params.idx_type = query_params.limit > 0 ? I_FIRST : I_NONE; + ret = db_queue_add_by_query(&query_params, status.shuffle, status.item_id, pos, total_count, NULL); free_query_params(&query_params, 1); From 69c56f5971fb26a9c2ec8dafde92b693436fe147 Mon Sep 17 00:00:00 2001 From: whatdoineed2do/Ray Date: Sat, 9 May 2020 20:04:27 +0100 Subject: [PATCH 2/2] [jsonapi] items/add?expression can take 'limit' param --- src/httpd_jsonapi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index d162f2e7..c95a9fdb 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -2287,7 +2287,7 @@ queue_tracks_add_byuris(const char *param, int pos, int *total_count) } static int -queue_tracks_add_byexpression(const char *param, int pos, int *total_count) +queue_tracks_add_byexpression(const char *param, int pos, int limit, int *total_count) { char *expression; struct smartpl smartpl_expression; @@ -2310,7 +2310,7 @@ queue_tracks_add_byexpression(const char *param, int pos, int *total_count) query_params.filter = strdup(smartpl_expression.query_where); query_params.order = safe_strdup(smartpl_expression.order); - query_params.limit = smartpl_expression.limit; + query_params.limit = limit > 0 ? limit : smartpl_expression.limit; free_smartpl(&smartpl_expression, 1); player_get_status(&status); @@ -2333,6 +2333,7 @@ jsonapi_reply_queue_tracks_add(struct httpd_request *hreq) const char *param_expression; const char *param; int pos = -1; + int limit = -1; bool shuffle; int total_count = 0; json_object *reply; @@ -2384,7 +2385,11 @@ jsonapi_reply_queue_tracks_add(struct httpd_request *hreq) } else { - ret = queue_tracks_add_byexpression(param_expression, pos, &total_count); + // This overrides the value specified in query + param = evhttp_find_header(hreq->query, "limit"); + if (param) + safe_atoi32(param, &limit); + ret = queue_tracks_add_byexpression(param_expression, pos, limit, &total_count); } if (ret == 0)