mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-15 16:53:18 -05:00
[db,jsonapi]] update api/library/tracks and db to accept 'flag' param
This commit is contained in:
parent
5cbb5f061d
commit
ad573b8bc7
21
src/db.c
21
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)
|
||||
{
|
||||
|
10
src/db.h
10
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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user