diff --git a/.claude/HISTORY.md b/.claude/HISTORY.md index cf2f6cb7..52ae8570 100644 --- a/.claude/HISTORY.md +++ b/.claude/HISTORY.md @@ -2992,3 +2992,35 @@ git checkout HEAD -- index.html - Files: - `secubox-app-peertube/files/usr/sbin/peertube-analyse` (778 lines) - `secubox-app-peertube/Makefile` (updated) + +64. **PeerTube Analyse Web Interface & Portal (2026-02-21)** + - Created standalone web interface for PeerTube video analysis. + - **URL**: https://analyse.gk2.secubox.in/peertube-analyse/ + - **Web Interface Features**: + - Cyberpunk-themed design matching SecuBox portal + - Video URL input with example presets + - Options: Force Whisper, No AI Analysis, Model/Language selection + - Progress status bar with live polling + - Tabbed results: Analysis (Markdown), Transcript, Metadata + - Copy to clipboard functionality + - **CGI Backend**: + - `/cgi-bin/peertube-analyse` — Start analysis (POST) + - `/cgi-bin/peertube-analyse-status` — Poll job status (GET) + - Async job system with background processing + - JSON API with job_id for polling + - **RPCD Integration**: + - Added `analyse` and `analyse_status` methods to `luci.peertube` + - ACL permissions updated for read/write access + - **Portal Integration**: + - New "Intelligence & Analyse" section in SecuBox portal + - Added PeerTube Analyse and Radio Stream services + - **HAProxy/SSL**: + - Domain: analyse.gk2.secubox.in + - Let's Encrypt certificate auto-provisioned + - Routing via uhttpd backend (static content) + - Files: + - `secubox-app-peertube/files/www/peertube-analyse/index.html` + - `secubox-app-peertube/files/www/cgi-bin/peertube-analyse` + - `secubox-app-peertube/files/www/cgi-bin/peertube-analyse-status` + - `luci-app-peertube/root/usr/libexec/rpcd/luci.peertube` (updated) + - `luci-app-secubox-portal/root/www/gk2-hub/portal.html` (updated) diff --git a/package/secubox/luci-app-peertube/root/usr/libexec/rpcd/luci.peertube b/package/secubox/luci-app-peertube/root/usr/libexec/rpcd/luci.peertube index 38b83b06..738a0cac 100644 --- a/package/secubox/luci-app-peertube/root/usr/libexec/rpcd/luci.peertube +++ b/package/secubox/luci-app-peertube/root/usr/libexec/rpcd/luci.peertube @@ -530,6 +530,151 @@ method_import_job_status() { json_dump } +# Method: analyse - Start video transcript analysis +method_analyse() { + read -r input + json_load "$input" + json_get_var url url "" + json_get_var force_whisper force_whisper "0" + json_get_var no_analyse no_analyse "0" + json_get_var model model "medium" + json_get_var lang lang "fr" + + if [ -z "$url" ]; then + json_init + json_add_boolean "success" 0 + json_add_string "error" "URL is required" + json_dump + return + fi + + # Check if peertube-analyse exists + if [ ! -x "/usr/sbin/peertube-analyse" ]; then + json_init + json_add_boolean "success" 0 + json_add_string "error" "peertube-analyse not installed" + json_dump + return + fi + + # Generate job ID + local job_id="analyse_$(date +%s)_$$" + local output_dir="/tmp/peertube-analyse/${job_id}" + local statusfile="/tmp/peertube-analyse-${job_id}.status" + local resultfile="/tmp/peertube-analyse-${job_id}.json" + + mkdir -p "$output_dir" + echo "starting" > "$statusfile" + + # Build command args + local args="" + [ "$force_whisper" = "1" ] && args="$args --force-whisper" + [ "$no_analyse" = "1" ] && args="$args --no-analyse" + [ -n "$model" ] && args="$args --model $model" + [ -n "$lang" ] && args="$args --lang $lang" + args="$args --output $output_dir" + + # Run in background + ( + echo "extracting" > "$statusfile" + + # Run the analysis + OUTPUT_BASE="$output_dir" /usr/sbin/peertube-analyse $args "$url" > "/tmp/peertube-analyse-${job_id}.log" 2>&1 + local rc=$? + + if [ $rc -eq 0 ]; then + echo "completed" > "$statusfile" + + # Build result JSON + local meta_file=$(find "$output_dir" -name "*.meta.json" -type f 2>/dev/null | head -1) + local transcript_file=$(find "$output_dir" -name "*.transcript.txt" -type f 2>/dev/null | head -1) + local analysis_file=$(find "$output_dir" -name "*.analyse.md" -type f 2>/dev/null | head -1) + + # Create result JSON manually (avoid jshn for large content) + { + echo '{' + echo '"success": true,' + echo '"job_id": "'"$job_id"'",' + + # Metadata (use jq if available, otherwise jsonfilter) + if [ -f "$meta_file" ]; then + echo '"metadata": ' + cat "$meta_file" + echo ',' + else + echo '"metadata": null,' + fi + + # Transcript + if [ -f "$transcript_file" ]; then + printf '"transcript": ' + cat "$transcript_file" | jq -Rs '.' + echo ',' + else + echo '"transcript": null,' + fi + + # Analysis + if [ -f "$analysis_file" ]; then + printf '"analysis": ' + cat "$analysis_file" | jq -Rs '.' + else + echo '"analysis": null' + fi + + echo '}' + } > "$resultfile" + else + echo "failed" > "$statusfile" + echo '{"success": false, "error": "Analysis failed", "job_id": "'"$job_id"'"}' > "$resultfile" + fi + ) & + + json_init + json_add_boolean "success" 1 + json_add_string "message" "Analysis started" + json_add_string "job_id" "$job_id" + json_dump +} + +# Method: analyse_status - Get analysis job status/results +method_analyse_status() { + read -r input + json_load "$input" + json_get_var job_id job_id "" + + if [ -z "$job_id" ]; then + json_init + json_add_boolean "success" 0 + json_add_string "error" "job_id is required" + json_dump + return + fi + + local statusfile="/tmp/peertube-analyse-${job_id}.status" + local resultfile="/tmp/peertube-analyse-${job_id}.json" + local logfile="/tmp/peertube-analyse-${job_id}.log" + + local status="unknown" + [ -f "$statusfile" ] && status=$(cat "$statusfile") + + # If completed, return the full result + if [ "$status" = "completed" ] && [ -f "$resultfile" ]; then + cat "$resultfile" + return + fi + + # Otherwise return status + local logs="" + [ -f "$logfile" ] && logs=$(tail -10 "$logfile") + + json_init + json_add_string "status" "$status" + json_add_string "job_id" "$job_id" + json_add_string "logs" "$logs" + json_dump +} + # Method: import_status - Check import progress method_import_status() { local import_dir="/var/lib/peertube/storage/tmp/import" @@ -589,6 +734,16 @@ list_methods() { json_add_object "import_job_status" json_add_string "job_id" "" json_close_object + json_add_object "analyse" + json_add_string "url" "" + json_add_string "force_whisper" "0" + json_add_string "no_analyse" "0" + json_add_string "model" "medium" + json_add_string "lang" "fr" + json_close_object + json_add_object "analyse_status" + json_add_string "job_id" "" + json_close_object json_dump } @@ -644,6 +799,12 @@ case "$1" in import_job_status) method_import_job_status ;; + analyse) + method_analyse + ;; + analyse_status) + method_analyse_status + ;; *) echo '{"error":"Method not found"}' ;; diff --git a/package/secubox/luci-app-peertube/root/usr/share/rpcd/acl.d/luci-app-peertube.json b/package/secubox/luci-app-peertube/root/usr/share/rpcd/acl.d/luci-app-peertube.json index 7993bed1..946feb1e 100644 --- a/package/secubox/luci-app-peertube/root/usr/share/rpcd/acl.d/luci-app-peertube.json +++ b/package/secubox/luci-app-peertube/root/usr/share/rpcd/acl.d/luci-app-peertube.json @@ -3,13 +3,13 @@ "description": "Grant access to PeerTube management", "read": { "ubus": { - "luci.peertube": ["status", "logs", "import_status", "import_job_status"] + "luci.peertube": ["status", "logs", "import_status", "import_job_status", "analyse_status"] }, "uci": ["peertube"] }, "write": { "ubus": { - "luci.peertube": ["start", "stop", "install", "uninstall", "update", "emancipate", "live_enable", "live_disable", "configure_haproxy", "import_video"] + "luci.peertube": ["start", "stop", "install", "uninstall", "update", "emancipate", "live_enable", "live_disable", "configure_haproxy", "import_video", "analyse"] }, "uci": ["peertube"] } diff --git a/package/secubox/luci-app-secubox-portal/root/www/gk2-hub/portal.html b/package/secubox/luci-app-secubox-portal/root/www/gk2-hub/portal.html index 8bfe8cbb..acf58b97 100644 --- a/package/secubox/luci-app-secubox-portal/root/www/gk2-hub/portal.html +++ b/package/secubox/luci-app-secubox-portal/root/www/gk2-hub/portal.html @@ -200,6 +200,20 @@ +