webui: replace nautctl web server with a loadable plugin
Drop the web UI that was compiled into nautctl and serve the torrent-ui front end (../torrent-ui/public) from a native plugin (plugins/webui) loaded via `nautd --plugin`. The plugin talks to the engine only through the host call_rpc ABI and adapts the daemon's RPC surface to the qBittorrent-style contract the UI expects (snapshot/SSE, torrent detail tabs, add/delete, cookie auth). Also folds in the daemon refactor that owns per-torrent worker threads and the swarm engine (naut_swarm) used by the plugin's data source. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
50a357968a
commit
8dde48c05a
27 changed files with 2706 additions and 403 deletions
|
|
@ -11,8 +11,16 @@
|
|||
|
||||
static void usage(const char *program) {
|
||||
fprintf(stderr,
|
||||
"usage: %s [--socket PATH] METHOD [PARAMS_JSON]\n"
|
||||
" %s [--socket PATH] events\n", program, program);
|
||||
"usage: %s [--socket PATH] COMMAND [ARGS]\n"
|
||||
"\n"
|
||||
"commands:\n"
|
||||
" add SOURCE OUTPUT [IP:PORT ...]\n"
|
||||
" list\n"
|
||||
" show TORRENT_ID\n"
|
||||
" remove TORRENT_ID\n"
|
||||
" script PATH | unscript\n"
|
||||
" status | events | shutdown\n"
|
||||
" METHOD [PARAMS_JSON] (raw RPC)\n", program);
|
||||
}
|
||||
|
||||
static json_t *parse_params(const char *text) {
|
||||
|
|
@ -54,6 +62,15 @@ static int stream_events(const char *socket_path) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool parse_id(const char *text, json_int_t *id) {
|
||||
if (!text || !*text || *text == '-') return false;
|
||||
char *end = NULL;
|
||||
unsigned long long value = strtoull(text, &end, 10);
|
||||
if (!end || *end || value > (unsigned long long)INT64_MAX) return false;
|
||||
*id = (json_int_t)value;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *socket_path = getenv("NAUT_SOCKET");
|
||||
if (!socket_path || !*socket_path) socket_path = DEFAULT_SOCKET;
|
||||
|
|
@ -66,7 +83,7 @@ int main(int argc, char **argv) {
|
|||
socket_path = argv[arg + 1];
|
||||
arg += 2;
|
||||
}
|
||||
if (arg >= argc || arg + 2 < argc) {
|
||||
if (arg >= argc) {
|
||||
usage(argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
|
@ -74,7 +91,49 @@ int main(int argc, char **argv) {
|
|||
const char *method = argv[arg++];
|
||||
if (strcmp(method, "events") == 0)
|
||||
return stream_events(socket_path);
|
||||
json_t *params = parse_params(arg < argc ? argv[arg] : NULL);
|
||||
|
||||
json_t *params = NULL;
|
||||
if (strcmp(method, "add") == 0) {
|
||||
if (arg + 1 >= argc) { usage(argv[0]); return 2; }
|
||||
method = "add_torrent";
|
||||
params = json_pack("{s:s,s:s}", "source", argv[arg],
|
||||
"output", argv[arg + 1]);
|
||||
arg += 2;
|
||||
json_t *peers = json_array();
|
||||
if (!params || !peers) {
|
||||
json_decref(params);
|
||||
json_decref(peers);
|
||||
return 1;
|
||||
}
|
||||
while (arg < argc)
|
||||
json_array_append_new(peers, json_string(argv[arg++]));
|
||||
json_object_set_new(params, "peers", peers);
|
||||
} else if (strcmp(method, "list") == 0) {
|
||||
if (arg != argc) { usage(argv[0]); return 2; }
|
||||
method = "torrents";
|
||||
params = json_object();
|
||||
} else if (strcmp(method, "show") == 0 ||
|
||||
strcmp(method, "remove") == 0) {
|
||||
json_int_t id;
|
||||
if (arg + 1 != argc || !parse_id(argv[arg], &id)) {
|
||||
usage(argv[0]);
|
||||
return 2;
|
||||
}
|
||||
method = strcmp(method, "show") == 0 ? "torrent" :
|
||||
"remove_torrent";
|
||||
params = json_pack("{s:I}", "torrent_id", id);
|
||||
} else if (strcmp(method, "script") == 0) {
|
||||
if (arg + 1 != argc) { usage(argv[0]); return 2; }
|
||||
method = "load_script";
|
||||
params = json_pack("{s:s}", "path", argv[arg]);
|
||||
} else if (strcmp(method, "unscript") == 0) {
|
||||
if (arg != argc) { usage(argv[0]); return 2; }
|
||||
method = "unload_script";
|
||||
params = json_object();
|
||||
} else {
|
||||
if (arg + 1 < argc) { usage(argv[0]); return 2; }
|
||||
params = parse_params(arg < argc ? argv[arg] : NULL);
|
||||
}
|
||||
if (!params) {
|
||||
fprintf(stderr, "nautctl: invalid JSON parameters\n");
|
||||
return 2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue