Only register gdrive callback if gdrive is enabled

With enabled gdrive return on change if no watch callback is configured, instead of send request to google drive
This commit is contained in:
Ozzieisaacs 2020-12-11 15:53:45 +01:00
parent 388e46ee81
commit 88ea998f8b
3 changed files with 8 additions and 3 deletions

5
cps.py
View File

@ -31,7 +31,7 @@ else:
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor'))
from cps import create_app
from cps import create_app, config
from cps import web_server
from cps.opds import opds
from cps.web import web
@ -64,7 +64,8 @@ def main():
app.register_blueprint(about)
app.register_blueprint(shelf)
app.register_blueprint(admi)
app.register_blueprint(gdrive)
if config.config_use_google_drive:
app.register_blueprint(gdrive)
app.register_blueprint(editbook)
if kobo_available:
app.register_blueprint(kobo)

View File

@ -123,10 +123,12 @@ def revoke_watch_gdrive():
@gdrive.route("/gdrive/watch/callback", methods=['GET', 'POST'])
def on_received_watch_confirmation():
if not config.config_google_drive_watch_changes_response:
return ''
if request.headers.get('X-Goog-Channel-Token') != gdrive_watch_callback_token \
or request.headers.get('X-Goog-Resource-State') != 'change' \
or not request.data:
return redirect(url_for('admin.configuration'))
return '' # redirect(url_for('admin.configuration'))
log.debug('%r', request.headers)
log.debug('%r', request.data)

View File

@ -20,6 +20,8 @@ from __future__ import division, print_function, unicode_literals
import os
import json
import shutil
import chardet
import ssl
from flask import Response, stream_with_context
from sqlalchemy import create_engine