Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ db.sqlite3
db.sqlite3-journal
.idea/*
venv
*.code-workspace

2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ verify_ssl = true
[packages]
django-picklefield = "*"
lxml = "*"
python-telegram-bot = ">=10"
python-telegram-bot = ">=13.5"
Django = ">=1.10"
Pillow = ">=2.9.0"
APScheduler = ">=3.3.0"
Expand Down
12 changes: 10 additions & 2 deletions opds_catalog/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from constance import config
from PIL import Image

from opds_catalog.middleware import BasicAuthMiddleware

def getFileName(book):
if config.SOPDS_TITLE_AS_FILENAME:
transname = utils.translit(book.title + '.' + book.format)
Expand Down Expand Up @@ -143,8 +145,14 @@ def Download(request, book_id, zip_flag):
""" Загрузка файла книги """
book = Book.objects.get(id=book_id)

if config.SOPDS_AUTH and request.user.is_authenticated:
bookshelf.objects.get_or_create(user=request.user, book=book)
if config.SOPDS_AUTH:
if not request.user.is_authenticated:
bau = BasicAuthMiddleware()
request = bau.process_request(request)
if not hasattr(request, 'user'):
return request
if request.user.is_authenticated:
bookshelf.objects.get_or_create(user=request.user, book=book)

full_path=os.path.join(config.SOPDS_ROOT_LIB,book.path)

Expand Down
2 changes: 1 addition & 1 deletion opds_catalog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __call__(self,request,*args,**kwargs):
bau = BasicAuthMiddleware()
result=bau.process_request(self.request)

if result!=None:
if (result != None) and (not hasattr(result, 'user')):
return result

return super().__call__(request,*args,**kwargs)
Expand Down
265 changes: 133 additions & 132 deletions opds_catalog/management/commands/sopds_telebot.py

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions opds_catalog/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def process_request(self,request):
except KeyError:
return self.unauthed()

(auth_meth, auth_data) = authentication.split(' ',1)
try:
(auth_meth, auth_data) = authentication.split(' ',1)
except ValueError:
return self.unauthed()

if 'basic' != auth_meth.lower():
return self.unauthed()
auth_data = base64.b64decode(auth_data.strip()).decode('utf-8')
Expand All @@ -45,7 +49,7 @@ def process_request(self,request):
if user and user.is_active:
request.user = user
auth.login(request, user)
return None
return request

return self.unauthed()

Expand Down
6 changes: 5 additions & 1 deletion sopds_web_backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ def SearchBooksView(request):
args['books']=items
args['current'] = 'search'
args['cache_id']='%s:%s:%s'%(searchterms,searchtype,op.page_num)
args['cache_t']=config.SOPDS_CACHE_TIME
# changes on bookshelf should be refreshed immediatelly
if searchtype == 'u':
args['cache_t'] = 0
else:
args['cache_t'] = config.SOPDS_CACHE_TIME

return render(request,'sopds_books.html', args)

Expand Down