From 36c8acc83ab32875288092586caaebc4418df4fc Mon Sep 17 00:00:00 2001 From: ookami125 Date: Mon, 22 Jun 2026 00:02:11 -0400 Subject: [PATCH] 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 --- ISSUES.md | 5 +++-- plugins/webui/webui.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ISSUES.md b/ISSUES.md index cc59617..6ac1c1a 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -4,7 +4,8 @@ - ⬛ Category default download location does nothing as changing it doesn't change the download location. Download location should be greyed out by default with the default location shown. Clicking should allow you to change the location. If the location is set it shouldn't change if the category is changed. - ✅ Automation variables at half window width makes the script unseeable. It should be displayed above the script if the window is to narrow. - ⬛ We need to implement the RSS and Search Tabs. -- ⬛ I need to be able to add Tags on adding a torrent. +- ✅ I need to be able to add Tags on adding a torrent. - ✅ Categories aren't saved across restart. - ✅ Pausing a torrent will go back into Downloading and Seeding. -- ⬛ A torrents data could overlap with another existing torrent. This should be blocked to avoid \ No newline at end of file +- ⬛ A torrents data could overlap with another existing torrent. This should be blocked to avoid +- ⬛ A paused torrent should still do a full piece check. \ No newline at end of file diff --git a/plugins/webui/webui.c b/plugins/webui/webui.c index a70144f..4750f4b 100644 --- a/plugins/webui/webui.c +++ b/plugins/webui/webui.c @@ -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);