Skip to content

Commit 8822e5e

Browse files
committed
Added an option to receive always a random device id
1 parent 54622ce commit 8822e5e

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@ This is a simple implementation of the KOReader (https://github.com/koreader/kor
2222
## Or via Docker
2323

2424
```bash
25-
> docker build --rm=true --tag=kosync .
25+
> docker build --rm=true --tag=kosync:latest .
2626

2727
> docker-compose up -d
2828

2929
```
3030

31+
## Environment Variables
32+
33+
* RECEIVE_RANDOM_DEVICE_ID ("True"|"False")
34+
35+
Set it true to retrieve always a random device id to force a progress sync.
36+
This is usefull if you only sync your progress from only one device and
37+
usually delete the *.sdr files with some cleaning tools.
38+
39+
3140
## Dockerhub
3241

3342
There is also a dockerhub image available if you are not able to build yourself the image.
@@ -41,6 +50,10 @@ For linux/amd64 you can use `docker pull b1n4ryj4n/koreader-sync` and for linux/
4150

4251
## Changelog
4352

53+
## [0.0.3] - 2021-03-20
54+
### Added
55+
- Added an environment variable option to receive always a random device id
56+
4457
## [0.0.2] - 2021-02-21
4558
### Added
4659
- Merged ["Dockerfile: use multi-stage build to optimize image size"](https://github.com/b1n4ryj4n/koreader-sync/pull/3)

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
version: '3'
22
services:
33
kosync:
4-
image: kosync
4+
image: kosync:latest
55
container_name: kosync
66
ports:
77
- 8081:8081
88
volumes:
99
- ./data:/app/data
10+
environment:
11+
- RECEIVE_RANDOM_DEVICE_ID=False
1012
restart: always

kosync.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# -*- coding: utf-8 -*-
22
import time
3+
import uuid
4+
from distutils.util import strtobool
5+
from os import getenv
36
from typing import Optional
47

8+
from dotenv import load_dotenv
59
from fastapi import FastAPI, Header
610
from fastapi.responses import JSONResponse
711
from pydantic import BaseModel
8-
from tinydb import TinyDB, Query
12+
from tinydb import Query, TinyDB
913

1014
app = FastAPI(openapi_url=None, redoc_url=None)
11-
db = TinyDB('data/db.json')
12-
users = db.table('users')
13-
documents = db.table('documents')
14-
15+
db = TinyDB("data/db.json")
16+
users = db.table("users")
17+
documents = db.table("documents")
18+
load_dotenv()
1519

1620
class KosyncUser(BaseModel):
1721
username: Optional[str] = None
@@ -110,10 +114,16 @@ def get_progress(document: Optional[str] = None, x_auth_user: Optional[str] = He
110114
# get document progress if user has the document
111115
result = documents.get((QDocument.username == x_auth_user) & (QDocument.document == document))
112116
if result:
117+
rrdi = bool(strtobool(getenv("RECEIVE_RANDOM_DEVICE_ID", "False")))
118+
if rrdi == False:
119+
device_id = result["device_id"]
120+
else:
121+
device_id = uuid.uuid1()
122+
device_id = str(device_id.hex).upper()
113123
return JSONResponse(status_code=200,
114124
content={'username': x_auth_user, 'document': result["document"],
115125
'progress': result["progress"], 'percentage': result["percentage"],
116-
'device': result["device"], 'device_id': result["device_id"],
126+
'device': result["device"], 'device_id': device_id,
117127
'timestamp': result["timestamp"]})
118128
else:
119129
return JSONResponse(status_code=401, content={"message": f"Unauthorized"})

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fastapi==0.68.1
22
tinydb==4.5.1
3-
uvicorn==0.15.0
3+
uvicorn==0.15.0
4+
python-dotenv==0.19.2

0 commit comments

Comments
 (0)