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:
ookami125 2026-06-22 00:02:11 -04:00
parent 8295b8522c
commit 36c8acc83a
2 changed files with 20 additions and 2 deletions

View file

@ -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
- ⬛ A paused torrent should still do a full piece check.

View file

@ -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);