From 8295b8522c39d6301f5ae7531b725fbf4f61d41a Mon Sep 17 00:00:00 2001 From: ookami125 Date: Sun, 21 Jun 2026 23:34:50 -0400 Subject: [PATCH] webui: apply category on add + allow no category api_add now forwards the chosen category to the daemon (and fixes a use-after-free reading it from the freed request). Mark issues #3, #8, #9 done in ISSUES.md. Co-Authored-By: Claude Opus 4.8 --- ISSUES.md | 6 +++--- plugins/webui/webui.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ISSUES.md b/ISSUES.md index 9af04cb..cc59617 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -1,10 +1,10 @@ - ✅ Set Location doesn't work, it should also show the current location. - ⬛ I need a way to modify a category (including Uncategorozied). -- ⬛ Adding a Category means I can't have none selected on adding a torrent. +- ✅ Adding a Category means I can't have none selected on adding a torrent. - ⬛ 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. -- ⬛ Categories aren't saved across restart. -- ⬛ Pausing a torrent will go back into Downloading and Seeding. +- ✅ 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 diff --git a/plugins/webui/webui.c b/plugins/webui/webui.c index 7cccae6..a70144f 100644 --- a/plugins/webui/webui.c +++ b/plugins/webui/webui.c @@ -1358,11 +1358,16 @@ static void api_add(int fd, const char *body, size_t len) { const char *data = json_string_value(json_object_get(req, "data")); const char *save_path = json_string_value(json_object_get(req, "savePath")); /* The UI parses the .torrent client-side and sends a display name; the - * daemon only knows the temp upload path, so we keep the name here. */ + * daemon only knows the temp upload path, so we keep the name here. Copy + * out of `req` since it is freed before these are used below. */ const char *display = json_string_value(json_object_get(req, "name")); char display_name[256] = {0}; if (display && *display) snprintf(display_name, sizeof display_name, "%s", display); + const char *category = json_string_value(json_object_get(req, "category")); + char category_name[256] = {0}; + if (category && *category) + snprintf(category_name, sizeof category_name, "%s", category); if (!save_path || !*save_path) save_path = "."; if (!source) source = magnet; if ((!source || !*source) && (!data || !*data)) { @@ -1388,6 +1393,10 @@ static void api_add(int fd, const char *body, size_t len) { /* Forward the display name so the daemon persists it for restore. */ if (display_name[0]) json_object_set_new(params, "name", json_string(display_name)); + /* An empty category means "Uncategorized"; only forward a real one. The + * daemon (spawn_torrent) reads "category" and persists it. */ + if (category_name[0]) + json_object_set_new(params, "category", json_string(category_name)); json_t *result = rpc_call_json("add_torrent", params); json_decref(params); json_decref(req); @@ -1397,6 +1406,7 @@ static void api_add(int fd, const char *body, size_t len) { } 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); 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);