From 562c95c4b5c56ad3ed4a68df6db860239675d6c1 Mon Sep 17 00:00:00 2001 From: shihao <3127647737@qq.com> Date: Thu, 23 Apr 2026 10:28:20 +0800 Subject: [PATCH] fix: harden source startup script --- start-aivideo.bat | 69 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/start-aivideo.bat b/start-aivideo.bat index ff5173a..d2a1273 100644 --- a/start-aivideo.bat +++ b/start-aivideo.bat @@ -3,22 +3,33 @@ setlocal set "ROOT=%~dp0" set "BACKEND_DIR=%ROOT%backend" -set "VENV_PYTHON=%BACKEND_DIR%\.venv\Scripts\python.exe" -set "SOURCE_BACKEND_ENV=set DATABASE_URL=sqlite:///./aivideo.sqlite3 && set CELERY_TASK_ALWAYS_EAGER=true && set STORAGE_PROVIDER=local && set LOCAL_STORAGE_PATH=storage_data && set STORAGE_PUBLIC_BASE_URL=http://127.0.0.1:8000/storage" +set "VENV_DIR=%BACKEND_DIR%\.venv" +set "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe" + +if /i "%~1"==":run_backend" goto run_backend +if /i "%~1"==":run_frontend" goto run_frontend + cd /d "%ROOT%" echo [1/6] Checking Python... set "PYTHON_CMD=" where py >nul 2>nul -if not errorlevel 1 set "PYTHON_CMD=py -3" - -if not defined PYTHON_CMD ( - where python >nul 2>nul - if not errorlevel 1 set "PYTHON_CMD=python" +if not errorlevel 1 ( + py -3 -c "import sys" >nul 2>nul + if not errorlevel 1 set "PYTHON_CMD=py -3" ) if not defined PYTHON_CMD ( - echo Python was not found in PATH. + where python >nul 2>nul + if not errorlevel 1 ( + python -c "import sys" >nul 2>nul + if not errorlevel 1 set "PYTHON_CMD=python" + ) +) + +if not defined PYTHON_CMD ( + echo A working Python 3 installation was not found. + echo Install Python 3.11 or later, then make sure py -3 or python works in a new terminal. pause exit /b 1 ) @@ -41,9 +52,25 @@ if exist "%BACKEND_DIR%\.env" ( echo The backend will start with built-in defaults ^(SQLite, local storage, mock task flow^). ) -if not exist "%VENV_PYTHON%" ( +set "VENV_READY=" +if exist "%VENV_PYTHON%" ( + "%VENV_PYTHON%" -c "import sys" >nul 2>nul + if not errorlevel 1 set "VENV_READY=1" +) + +if not defined VENV_READY ( + if exist "%VENV_DIR%" ( + echo Existing backend virtual environment is broken or stale. Recreating it... + rmdir /s /q "%VENV_DIR%" + if exist "%VENV_DIR%" ( + echo Failed to remove the broken backend virtual environment. + pause + exit /b 1 + ) + ) + echo [4/6] Creating backend virtual environment... - call %PYTHON_CMD% -m venv "%BACKEND_DIR%\.venv" + %PYTHON_CMD% -m venv "%VENV_DIR%" if errorlevel 1 ( echo Failed to create backend virtual environment. pause @@ -51,7 +78,7 @@ if not exist "%VENV_PYTHON%" ( ) echo Installing backend dependencies... - call "%VENV_PYTHON%" -m pip install --disable-pip-version-check -r "%BACKEND_DIR%\requirements.txt" + "%VENV_PYTHON%" -m pip install --disable-pip-version-check -r "%BACKEND_DIR%\requirements.txt" if errorlevel 1 ( echo Failed to install backend dependencies. pause @@ -74,8 +101,8 @@ if not exist "%ROOT%node_modules" ( ) echo [6/6] Starting backend and unified frontend... -start "AIVideo Backend" cmd /k "cd /d ""%BACKEND_DIR%"" && %SOURCE_BACKEND_ENV% && ""%VENV_PYTHON%"" -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000" -start "AIVideo Frontend" cmd /k "cd /d ""%ROOT%"" && npm run dev" +start "AIVideo Backend" cmd /k call "%~f0" :run_backend +start "AIVideo Frontend" cmd /k call "%~f0" :run_frontend echo. echo User UI: http://localhost:3000 @@ -84,3 +111,19 @@ echo API: http://localhost:8000 echo. echo Two windows have been opened for backend and frontend. pause +goto :eof + +:run_backend +cd /d "%BACKEND_DIR%" +set "DATABASE_URL=sqlite:///./aivideo.sqlite3" +set "CELERY_TASK_ALWAYS_EAGER=true" +set "STORAGE_PROVIDER=local" +set "LOCAL_STORAGE_PATH=storage_data" +set "STORAGE_PUBLIC_BASE_URL=http://127.0.0.1:8000/storage" +"%VENV_PYTHON%" -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 +goto :eof + +:run_frontend +cd /d "%ROOT%" +npm run dev +goto :eof