nexus33rd commited on
Commit
fd61a2a
·
verified ·
1 Parent(s): fec9f69

Upload 17 files

Browse files
Files changed (2) hide show
  1. app.py +13 -3
  2. entrypoint.sh +22 -3
app.py CHANGED
@@ -53,16 +53,26 @@ DOWNLOAD_PATH = env("QBITTORRENT_SAVE_PATH", "/downloads")
53
 
54
 
55
  def get_client() -> qbittorrentapi.Client:
 
 
56
  username = env("QBITTORRENT_USERNAME", "")
57
  password = env("QBITTORRENT_PASSWORD", "")
58
  client = qbittorrentapi.Client(
59
- host=env("QBITTORRENT_HOST", "127.0.0.1"),
60
- port=int(env("QBITTORRENT_PORT", "8080")),
61
  username=username,
62
  password=password,
63
  )
64
  if username and password:
65
- client.auth_log_in()
 
 
 
 
 
 
 
 
66
  return client
67
 
68
 
 
53
 
54
 
55
  def get_client() -> qbittorrentapi.Client:
56
+ host = env("QBITTORRENT_HOST", "127.0.0.1")
57
+ port = int(env("QBITTORRENT_PORT", "8080"))
58
  username = env("QBITTORRENT_USERNAME", "")
59
  password = env("QBITTORRENT_PASSWORD", "")
60
  client = qbittorrentapi.Client(
61
+ host=host,
62
+ port=port,
63
  username=username,
64
  password=password,
65
  )
66
  if username and password:
67
+ try:
68
+ client.auth_log_in()
69
+ except qbittorrentapi.LoginFailed:
70
+ # Docker deployments in this repo can allow the app subnet to bypass
71
+ # WebUI auth. Fall back to a session without explicit login so the UI
72
+ # still works while qBittorrent config is being repaired or migrated.
73
+ fallback_client = qbittorrentapi.Client(host=host, port=port)
74
+ fallback_client.app.version
75
+ return fallback_client
76
  return client
77
 
78
 
entrypoint.sh CHANGED
@@ -4,14 +4,33 @@ set -euo pipefail
4
  CONFIG_DIR="${QBT_PROFILE:-/config}"
5
  DOWNLOAD_DIR="${QBITTORRENT_SAVE_PATH:-/downloads}"
6
  DEFAULT_CONFIG="/defaults/qBittorrent.conf"
 
 
 
7
  WEB_PORT="${PORT:-5000}"
8
 
9
- mkdir -p "$CONFIG_DIR" "$DOWNLOAD_DIR" "$DOWNLOAD_DIR/incomplete"
10
 
11
- if [[ ! -f "$CONFIG_DIR/qBittorrent.conf" ]]; then
12
- cp "$DEFAULT_CONFIG" "$CONFIG_DIR/qBittorrent.conf"
 
 
 
 
 
 
 
 
13
  fi
14
 
 
 
 
 
 
 
 
 
15
  shutdown() {
16
  if [[ -n "${WEB_PID:-}" ]] && kill -0 "$WEB_PID" 2>/dev/null; then
17
  kill "$WEB_PID" 2>/dev/null || true
 
4
  CONFIG_DIR="${QBT_PROFILE:-/config}"
5
  DOWNLOAD_DIR="${QBITTORRENT_SAVE_PATH:-/downloads}"
6
  DEFAULT_CONFIG="/defaults/qBittorrent.conf"
7
+ ACTIVE_CONFIG_DIR="$CONFIG_DIR/qBittorrent/config"
8
+ ACTIVE_CONFIG="$ACTIVE_CONFIG_DIR/qBittorrent.conf"
9
+ LEGACY_CONFIG="$CONFIG_DIR/qBittorrent.conf"
10
  WEB_PORT="${PORT:-5000}"
11
 
12
+ mkdir -p "$CONFIG_DIR" "$ACTIVE_CONFIG_DIR" "$DOWNLOAD_DIR" "$DOWNLOAD_DIR/incomplete"
13
 
14
+ has_webui_config() {
15
+ local config_file="$1"
16
+ [[ -f "$config_file" ]] \
17
+ && grep -q '^WebUI\\Username=' "$config_file" \
18
+ && grep -q '^WebUI\\Password_PBKDF2=' "$config_file"
19
+ }
20
+
21
+ SOURCE_CONFIG="$DEFAULT_CONFIG"
22
+ if has_webui_config "$LEGACY_CONFIG"; then
23
+ SOURCE_CONFIG="$LEGACY_CONFIG"
24
  fi
25
 
26
+ # qBittorrent stores its real profile under <profile>/qBittorrent/config.
27
+ # Keep older /config/qBittorrent.conf mounts working by migrating them forward.
28
+ if ! has_webui_config "$ACTIVE_CONFIG"; then
29
+ cp "$SOURCE_CONFIG" "$ACTIVE_CONFIG"
30
+ fi
31
+
32
+ cp "$ACTIVE_CONFIG" "$LEGACY_CONFIG"
33
+
34
  shutdown() {
35
  if [[ -n "${WEB_PID:-}" ]] && kill -0 "$WEB_PID" 2>/dev/null; then
36
  kill "$WEB_PID" 2>/dev/null || true