From ad573b8bc7301db602782386d1f1a6d22ff82aab Mon Sep 17 00:00:00 2001 From: whatdoineed2do/Ray Date: Sun, 5 Sep 2021 17:52:59 +0100 Subject: [PATCH] [db,jsonapi]] update api/library/tracks and db to accept 'flag' param --- src/db.c | 21 +++++++++++++++++++++ src/db.h | 10 ++++++++++ src/httpd_jsonapi.c | 16 ++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/db.c b/src/db.c index 9c3ecd9c..53587d81 100644 --- a/src/db.c +++ b/src/db.c @@ -3324,6 +3324,27 @@ db_file_rating_update_byvirtualpath(const char *virtual_path, uint32_t rating) #undef Q_TMPL } +int +db_file_flag_update_byid(uint32_t id, uint32_t flag) +{ +#define Q_TMPL "UPDATE files SET flag = %d WHERE id = %d;" + char *query; + int ret; + + query = sqlite3_mprintf(Q_TMPL, flag, id); + + ret = db_query_run(query, 1, 0); + + if (ret == 0) + { + db_admin_setint64(DB_ADMIN_DB_MODIFIED, (int64_t) time(NULL)); + listener_notify(LISTENER_RATING); + } + + return ((ret < 0) ? -1 : sqlite3_changes(hdl)); +#undef Q_TMPL +} + void db_file_delete_bypath(const char *path) { diff --git a/src/db.h b/src/db.h index 97ca3f58..731f7100 100644 --- a/src/db.h +++ b/src/db.h @@ -141,6 +141,13 @@ enum data_kind { const char * db_data_kind_label(enum data_kind data_kind); +enum flag_kind { + FLAG_KIND_NA = 0, // unset + FLAG_KIND_DELETE = 1, // delete + + FLAG_KIND_MAX // unused +}; + /* Note that fields marked as integers in the metadata map in filescanner_ffmpeg must be uint32_t here */ struct media_file_info { uint32_t id; @@ -655,6 +662,9 @@ db_file_seek_update(int id, uint32_t seek); int db_file_rating_update_byid(uint32_t id, uint32_t rating); +int +db_file_flag_update_byid(uint32_t id, uint32_t rating); + int db_file_rating_update_byvirtualpath(const char *virtual_path, uint32_t rating); diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index 89fdf63f..aa4938f6 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -311,6 +311,7 @@ track_to_json(struct db_media_file_info *dbmfi) safe_json_add_int_from_string(item, "samplerate", dbmfi->samplerate); safe_json_add_int_from_string(item, "bitrate", dbmfi->bitrate); safe_json_add_int_from_string(item, "channels", dbmfi->channels); + safe_json_add_int_from_string(item, "flag", dbmfi->flag); ret = safe_atoi32(dbmfi->media_kind, &intval); if (ret == 0) @@ -2221,6 +2222,7 @@ queue_item_to_json(struct db_queue_item *queue_item, char shuffle) json_object_object_add(item, "bitrate", json_object_new_int(queue_item->bitrate)); json_object_object_add(item, "samplerate", json_object_new_int(queue_item->samplerate)); json_object_object_add(item, "channels", json_object_new_int(queue_item->channels)); + json_object_object_add(item, "flag", json_object_new_int(queue_item->flag)); return item; } @@ -3339,6 +3341,20 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq) return HTTP_INTERNAL; } + // retreive via "/api/search?type=tracks&expression=flag+=+1" + param = evhttp_find_header(hreq->query, "flag"); + if (param) + { + ret = safe_atoi32(param, &val); + if (ret < 0 || (ret == 0 && (val < FLAG_KIND_NA || val >= FLAG_KIND_MAX)) ) + return HTTP_BADREQUEST; + + ret = db_file_flag_update_byid(track_id, val); + + if (ret < 0) + return HTTP_INTERNAL; + } + return HTTP_OK; }