secubox-openwrt/package/secubox/secubox-app-peertube/files/www/cgi-bin/peertube-import-status
CyberMind-FR bbf2b19415 feat(peertube): Add video import with multi-track subtitle sync
- New peertube-import script for importing from YouTube, Vimeo, 1000+ sites
- CGI endpoints for portal integration (peertube-import, peertube-import-status)
- Portal UI: Video Import card with progress tracking
- Multi-language subtitle download and PeerTube caption upload
- Fixed stdout/stderr separation for reliable function returns
- UCI config: uses peertube.admin.username/password
- Package version bumped to 1.2.0
- Added README.md with full documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-21 20:18:51 +01:00

70 lines
1.7 KiB
Bash

#!/bin/sh
# CGI endpoint for checking PeerTube import status
# Returns JSON response
# Set headers
printf "Content-Type: application/json\r\n"
printf "Access-Control-Allow-Origin: *\r\n"
printf "\r\n"
# Get job_id from query string or POST body
JOB_ID=""
if [ -n "$QUERY_STRING" ]; then
JOB_ID=$(echo "$QUERY_STRING" | sed -n 's/.*job_id=\([^&]*\).*/\1/p')
fi
if [ -z "$JOB_ID" ] && [ "$REQUEST_METHOD" = "POST" ]; then
INPUT=$(cat)
if command -v jq >/dev/null 2>&1; then
JOB_ID=$(echo "$INPUT" | jq -r '.job_id // empty')
else
JOB_ID=$(echo "$INPUT" | jsonfilter -e '@.job_id' 2>/dev/null)
fi
fi
if [ -z "$JOB_ID" ]; then
echo '{"error": "job_id is required"}'
exit 0
fi
# Sanitize job_id (only allow alphanumeric and underscore)
JOB_ID=$(echo "$JOB_ID" | tr -cd 'a-zA-Z0-9_')
STATUS_FILE="/tmp/peertube-import-${JOB_ID}.status"
RESULT_FILE="/tmp/peertube-import-${JOB_ID}.json"
LOG_FILE="/tmp/peertube-import-${JOB_ID}.log"
PROGRESS_FILE="/tmp/peertube-import-${JOB_ID}.progress"
# Check if job exists
if [ ! -f "$STATUS_FILE" ]; then
echo '{"error": "Job not found", "job_id": "'"$JOB_ID"'"}'
exit 0
fi
STATUS=$(cat "$STATUS_FILE" 2>/dev/null || echo "unknown")
PROGRESS=$(cat "$PROGRESS_FILE" 2>/dev/null || echo "0")
# If completed or failed, return full result
if [ -f "$RESULT_FILE" ]; then
if [ "$STATUS" = "completed" ] || [ "$STATUS" = "failed" ]; then
cat "$RESULT_FILE"
exit 0
fi
fi
# Otherwise return status with progress and logs
LOGS=""
if [ -f "$LOG_FILE" ]; then
LOGS=$(tail -3 "$LOG_FILE" 2>/dev/null | tr '\n' ' ' | sed 's/"/\\"/g' | head -c 300)
fi
cat << EOF
{
"status": "$STATUS",
"job_id": "$JOB_ID",
"progress": $PROGRESS,
"logs": "$LOGS"
}
EOF