webui: add tags when adding a torrent
api_add forwards tags to the daemon, assigns them to the new torrent, and registers any new tag names in the persisted taxonomy. Mark #7 done. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
8295b8522c
commit
36c8acc83a
2 changed files with 20 additions and 2 deletions
|
|
@ -1382,6 +1382,9 @@ static void api_add(int fd, const char *body, size_t len) {
|
|||
: "send a magnet, a source path, or uploaded torrent bytes");
|
||||
return;
|
||||
}
|
||||
/* Own a copy of the tags (req is freed before they are applied below). */
|
||||
json_t *tags = json_is_array(json_object_get(req, "tags"))
|
||||
? json_deep_copy(json_object_get(req, "tags")) : NULL;
|
||||
json_t *params = json_object();
|
||||
json_object_set_new(params, "output", json_string(save_path));
|
||||
if (source && *source) json_object_set_new(params, "source", json_string(source));
|
||||
|
|
@ -1397,16 +1400,30 @@ static void api_add(int fd, const char *body, size_t len) {
|
|||
* daemon (spawn_torrent) reads "category" and persists it. */
|
||||
if (category_name[0])
|
||||
json_object_set_new(params, "category", json_string(category_name));
|
||||
if (tags && json_array_size(tags) > 0)
|
||||
json_object_set_new(params, "tags", json_deep_copy(tags));
|
||||
json_t *result = rpc_call_json("add_torrent", params);
|
||||
json_decref(params);
|
||||
json_decref(req);
|
||||
if (!result) {
|
||||
json_decref(tags);
|
||||
http_text(fd, 502, "Bad Gateway", "add_torrent failed");
|
||||
return;
|
||||
}
|
||||
uint64_t new_id = json_u64(result, "torrent_id");
|
||||
if (display_name[0]) store_set_name(new_id, display_name);
|
||||
if (category_name[0]) store_set_category(new_id, category_name);
|
||||
if (tags && json_array_size(tags) > 0) {
|
||||
store_update_tags(new_id, tags, true); /* assign to the new torrent */
|
||||
size_t ti;
|
||||
json_t *tv;
|
||||
json_array_foreach(tags, ti, tv) { /* register any new tag names */
|
||||
const char *t = json_string_value(tv);
|
||||
if (t && *t) store_add_tag(t);
|
||||
}
|
||||
webui_sync_taxonomy(); /* persist the global tag list */
|
||||
}
|
||||
json_decref(tags);
|
||||
char id[32];
|
||||
snprintf(id, sizeof id, "%llu", (unsigned long long)new_id);
|
||||
json_t *reply = json_pack("{s:b,s:s}", "ok", 1, "hash", id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue