Skip to content

Commit 2cbe793

Browse files
committed
syncing across devices and into calibre working
1 parent bec8a9b commit 2cbe793

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,12 @@ docker compose up -d
170170

171171
## KOReader Setup
172172

173-
1. Go to: Settings > Cloud storage > Progress sync
174-
2. Set sync server to: `http://your-server:8080`
175-
3. Register or login with your credentials
176-
4. Enable "Auto sync" for automatic progress updates
173+
1. Open a book in KOReader
174+
2. Open the menu (swipe down from top) and tap the settings icon (wrench)
175+
3. Select **Progress sync** > **Custom sync server** > enter your server URL (e.g., `http://your-server:8080`)
176+
4. Select **Register** or **Login** and enter your credentials
177+
5. Select **Push progress from this device** to test
178+
6. *optional* Enable **Auto sync** for automatic progress updates when opening/closing books
177179

178180
## References
179181

auth.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import os
2+
import logging
23
import hashlib
34
import bcrypt
45
from fastapi import Header, HTTPException, Depends
56
from sqlalchemy.orm import Session
67
from database import get_db
78
from models import User
89

10+
logging.basicConfig(level=logging.DEBUG)
11+
logger = logging.getLogger(__name__)
12+
913
PASSWORD_SALT = os.getenv("PASSWORD_SALT", "default-salt-change-me").encode()
1014

1115

@@ -31,11 +35,20 @@ def get_current_user(
3135
x_auth_key: str = Header(None),
3236
db: Session = Depends(get_db),
3337
) -> User:
38+
key_hint = f"'{x_auth_key[:8]}...' len={len(x_auth_key)}" if x_auth_key else "None"
39+
logger.debug(f"Auth: user='{x_auth_user}' key={key_hint}")
40+
3441
if not x_auth_user or not x_auth_key:
3542
raise HTTPException(status_code=401, detail="Unauthorized")
3643

3744
user = db.query(User).filter(User.username == x_auth_user).first()
38-
if not user or not verify_password(x_auth_key, user.password_hash):
45+
if not user:
46+
logger.debug(f"User '{x_auth_user}' not found")
47+
raise HTTPException(status_code=401, detail="Unauthorized")
48+
49+
if not verify_password(x_auth_key, user.password_hash):
50+
logger.debug(f"Password mismatch for '{x_auth_user}'")
3951
raise HTTPException(status_code=401, detail="Unauthorized")
4052

53+
logger.debug(f"Auth OK for '{x_auth_user}'")
4154
return user

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from database import get_db, init_db
77
from models import User, Progress, UserCreate, ProgressUpdate, ProgressResponse
8-
from auth import hash_password, md5_hash, get_current_user
8+
from auth import hash_password, get_current_user
99

1010

1111
@asynccontextmanager
@@ -36,7 +36,8 @@ def create_user(user: UserCreate, db: Session = Depends(get_db)):
3636
if existing:
3737
raise HTTPException(status_code=402, detail="Username already exists")
3838

39-
db_user = User(username=user.username, password_hash=hash_password(md5_hash(user.password)))
39+
# KOReader sends password as MD5 hash during registration, so don't double-hash
40+
db_user = User(username=user.username, password_hash=hash_password(user.password))
4041
db.add(db_user)
4142
db.commit()
4243

0 commit comments

Comments
 (0)