Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

GEMINI_API_KEY=your_google_ai_studio_key
DEEPSEEK_API_KEY=your_deepseek_api_key
SERVER=TRUE
# Local mode is the default. Set TRUE only in the server deployment .env.
SERVER=FALSE
WEB_LOGIN=deltaaa
WEB_PASSWORD=deltaaa00!
# Optional stable session signing secret; otherwise generated in instance/.
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __getattr__(self, name):

requests = _PooledRequests()

WORKER_URL = (os.environ.get("YTDLP_URL") or "http://yt-dlp-worker:8080").rstrip('/')
WORKER_URL = (os.environ.get("YTDLP_URL") or "http://127.0.0.1:8080").rstrip('/')


def _available_fonts():
Expand Down
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,19 @@ if png is not None:
| --- | --- |
| `GEMINI_API_KEY` | Server key for Gemini/Gemma models |
| `DEEPSEEK_API_KEY` | Server key for DeepSeek models |
| `SERVER` | Exact `TRUE` enables Waitress and web authentication |
| `SERVER` | Defaults to local mode (`FALSE`). Exact `TRUE` enables Waitress and web authentication |
| `WEB_LOGIN` | Login name; default `deltaaa` |
| `WEB_PASSWORD` | Login password; default `deltaaa00!` |
| `WEB_SECRET_KEY` | Optional stable session-signing secret |
| `WEB_AUTH_SECRET_FILE` | Native deployment override for the generated secret file |
| `PORT` | Native service port; web default `5000`, worker default `8080` |
| `YTDLP_URL` | Web-to-worker URL; default `http://yt-dlp-worker:8080` |
| `YTDLP_URL` | Native default `http://127.0.0.1:8080`; Docker Compose sets `http://yt-dlp-worker:8080` |

Local mode is enabled by default, including in `example.env`. Its YouTube callback
uses the current local host and port (`localhost:3000` with Compose, or
`localhost:5000` for a native web launch), ignoring a leftover hosted callback.
The server keeps `SERVER=TRUE` and its public `YOUTUBE_REDIRECT_URI` in its own
`.env`; these deployment values survive GitHub Actions updates.

Login sessions are valid for up to a year. Changing the credentials or signing secret invalidates existing sessions. Without `WEB_SECRET_KEY`, a secret is generated in `instance/web-session-secret`; keep that file across native restarts or retain the Compose session volume. For Compose, add an explicit environment entry to use `WEB_AUTH_SECRET_FILE`. Compose already fixes `YTDLP_URL` to the private worker address; edit that entry only if you change the service layout.

Expand Down
19 changes: 19 additions & 0 deletions tests/test_youtube_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,22 @@ def test_csrf_rejection_identifies_safe_to_retry_requests(web, tmp_path):
response = client.post('/api/youtube/disconnect', headers={'X-YouTube-CSRF': 'stale'})
assert response.status_code == 403 and response.json['code'] == 'youtube_csrf_invalid'
assert client.post('/api/youtube/disconnect', headers=headers).status_code == 200


@pytest.mark.parametrize('origin', ['http://localhost:3000', 'http://127.0.0.1:5000'])
def test_local_mode_uses_local_callback_even_with_hosted_override(web, monkeypatch, origin):
web.app.config['WEB_AUTH_ENABLED'] = False
web.app.config['YOUTUBE_REDIRECT_URI'] = 'https://hosted.example/api/youtube/callback'
monkeypatch.setenv('YOUTUBE_REDIRECT_URI', 'https://old-host.example/api/youtube/callback')
with web.app.test_request_context(base_url=origin):
assert web.youtube_uploads.callback_uri() == origin + '/api/youtube/callback'


def test_server_mode_keeps_external_callback_behind_reverse_proxy(web, monkeypatch):
web.app.config['WEB_AUTH_ENABLED'] = True
monkeypatch.setenv('YOUTUBE_REDIRECT_URI', 'https://auto-map.duckdns.org/api/youtube/callback')
with web.app.test_request_context(base_url='http://localhost:5000'):
assert web.youtube_uploads.callback_uri() == 'https://auto-map.duckdns.org/api/youtube/callback'
web.app.config['YOUTUBE_REDIRECT_URI'] = 'https://configured.example/api/youtube/callback'
with web.app.test_request_context(base_url='http://localhost:5000'):
assert web.youtube_uploads.callback_uri() == 'https://configured.example/api/youtube/callback'
4 changes: 4 additions & 0 deletions youtube_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def load_secret(self, path):
raise ValueError('Saved YouTube credentials cannot be opened. Connect your account again.') from None

def callback_uri(self):
# Local launches must return to their own host/port, even if a hosted
# callback was left in the environment from another deployment.
if not self.app.config.get('WEB_AUTH_ENABLED', False):
return url_for('youtube_callback', _external=True)
return (self.app.config.get('YOUTUBE_REDIRECT_URI') or os.environ.get('YOUTUBE_REDIRECT_URI')
or url_for('youtube_callback', _external=True))

Expand Down
Loading