Skip to content

fix: bilibili cookie path resolution and frontend baseURL on Windows#326

Open
zuiyi001 wants to merge 1 commit into
JefferyHcool:masterfrom
zuiyi001:master
Open

fix: bilibili cookie path resolution and frontend baseURL on Windows#326
zuiyi001 wants to merge 1 commit into
JefferyHcool:masterfrom
zuiyi001:master

Conversation

@zuiyi001
Copy link
Copy Markdown

Problem

Two issues prevent BiliNote from working correctly on a fresh Windows setup:

  1. Cookie not passed to yt-dlp (412 error): In bilibili_downloader.py, the cookie file path is resolved using Path(__file__).parent, which points to the downloaders/ subdirectory instead of the backend root. When download() calls self.get_cookie_path(), the path resolves to a non-existent file, so yt-dlp downloads without authentication and gets a 412 error.

  2. Frontend API calls fail (baseURL undefined): In request.ts, baseURL reads from VITE_API_BASE_URL environment variable. On a fresh dev install this env var is not set, causing all API calls to hit http://localhost:3015/undefined/... instead of the correct /api/... path.

Changes

  • backend/app/downloaders/bilibili_downloader.py: Use absolute path via BILIBILI_COOKIES_FILE env var (or fallback to backend root) instead of relative Path(__file__).parent resolution.
  • BillNote_frontend/src/utils/request.ts: Hardcode baseURL to '/api' to match the Vite proxy config, removing dependency on an env var that is not set by default.
  • .gitignore: Exclude cookies.txt (contains sensitive login credentials) and local debug scripts.

How to Test

  1. Place your Bilibili cookie file at backend/cookies.txt (Netscape format)
  2. Start backend: python -m uvicorn main:app --host 0.0.0.0 --port 8483
  3. Start frontend: npm run dev
  4. Submit a Bilibili video URL and verify it downloads and transcribes successfully without 412 errors.

- fix(bilibili_downloader): replace relative cookie path with absolute path
  to avoid Path(__file__).parent resolution inconsistency across call sites.
  cookies.txt is now loaded from absolute path via BILIBILI_COOKIES_FILE env var.

- fix(request.ts): hardcode baseURL to '/api' instead of reading from
  VITE_API_BASE_URL env var which was undefined in dev and caused API calls
  to fail on fresh installs.

- chore(.gitignore): exclude cookies.txt and local debug scripts

- chore(start_server.bat): add local dev server startup script for Windows
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve out-of-the-box Windows usability by ensuring (1) Bilibili downloads can use an authenticated cookies file and (2) the frontend consistently targets the backend API via the /api proxy path.

Changes:

  • Adjust frontend Axios baseURL handling to use a relative /api prefix.
  • Update the Bilibili downloader to pass a cookies file to yt-dlp when present.
  • Add ignores for sensitive cookies.txt and local-only debug artifacts; introduce a Windows backend startup batch script.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
BillNote_frontend/src/utils/request.ts Forces Axios requests to use /api (proxy/nginx) instead of env-based baseURL.
BillNote_frontend/package-lock.json Updates lockfile and adds @ant-design/x and related dependency metadata.
backend/start_server.bat Adds a Windows helper script for starting the backend.
backend/app/downloaders/bilibili_downloader.py Adds cookies support to yt-dlp options, but currently defaults cookies path to a machine-specific absolute path.
.gitignore Ignores cookies files and local debug/temporary scripts and logs.
Files not reviewed (1)
  • BillNote_frontend/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +19
# B站 cookies 文件路径(绝对路径,避免相对路径解析歧义)
BILIBILI_COOKIES_FILE = os.getenv("BILIBILI_COOKIES_FILE", r"I:\BiliNote\BiliNote_src\backend\cookies.txt")
Comment on lines +14 to +20
// 开发环境通过 vite proxy 转发到后端,生产环境可直接指向后端地址
// 所以 baseURL 始终使用相对路径 /api,由 vite proxy 或 nginx 处理转发
const baseURL = '/api';

// 创建实例
const request: AxiosInstance = axios.create({
baseURL: baseURL || '/api',
baseURL: baseURL,
Comment thread backend/start_server.bat
@@ -0,0 +1,9 @@
@echo off
chcp 65001 >nul
cd /d I:\BiliNote\BiliNote_src\backend
"url": "https://opencollective.com/ant-design"
},
"peerDependencies": {
"antd": "^6.1.1",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants