fix: bilibili cookie path resolution and frontend baseURL on Windows#326
Open
zuiyi001 wants to merge 1 commit into
Open
fix: bilibili cookie path resolution and frontend baseURL on Windows#326zuiyi001 wants to merge 1 commit into
zuiyi001 wants to merge 1 commit into
Conversation
- 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
There was a problem hiding this comment.
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
baseURLhandling to use a relative/apiprefix. - Update the Bilibili downloader to pass a cookies file to
yt-dlpwhen present. - Add ignores for sensitive
cookies.txtand 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, |
| @@ -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", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two issues prevent BiliNote from working correctly on a fresh Windows setup:
Cookie not passed to yt-dlp (412 error): In
bilibili_downloader.py, the cookie file path is resolved usingPath(__file__).parent, which points to thedownloaders/subdirectory instead of the backend root. Whendownload()callsself.get_cookie_path(), the path resolves to a non-existent file, so yt-dlp downloads without authentication and gets a 412 error.Frontend API calls fail (baseURL undefined): In
request.ts,baseURLreads fromVITE_API_BASE_URLenvironment variable. On a fresh dev install this env var is not set, causing all API calls to hithttp://localhost:3015/undefined/...instead of the correct/api/...path.Changes
backend/app/downloaders/bilibili_downloader.py: Use absolute path viaBILIBILI_COOKIES_FILEenv var (or fallback to backend root) instead of relativePath(__file__).parentresolution.BillNote_frontend/src/utils/request.ts: HardcodebaseURLto'/api'to match the Vite proxy config, removing dependency on an env var that is not set by default..gitignore: Excludecookies.txt(contains sensitive login credentials) and local debug scripts.How to Test
backend/cookies.txt(Netscape format)python -m uvicorn main:app --host 0.0.0.0 --port 8483npm run dev