Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
55fcf23d
Commit
55fcf23d
authored
Oct 31, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'sec_fixes/negate' into master
parents
1b0b4c4c
d2617322
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
33 deletions
+31
-33
gdrive.py
cps/gdrive.py
+31
-33
No files found.
cps/gdrive.py
View file @
55fcf23d
...
...
@@ -123,38 +123,36 @@ def revoke_watch_gdrive():
@
gdrive
.
route
(
"/gdrive/watch/callback"
,
methods
=
[
'GET'
,
'POST'
])
def
on_received_watch_confirmation
():
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'
))
log
.
debug
(
'
%
r'
,
request
.
headers
)
if
request
.
headers
.
get
(
'X-Goog-Channel-Token'
)
==
gdrive_watch_callback_token
\
and
request
.
headers
.
get
(
'X-Goog-Resource-State'
)
==
'change'
\
and
request
.
data
:
data
=
request
.
data
def
updateMetaData
():
log
.
info
(
'Change received from gdrive'
)
log
.
debug
(
'
%
r'
,
data
)
try
:
j
=
json
.
loads
(
data
)
log
.
info
(
'Getting change details'
)
response
=
gdriveutils
.
getChangeById
(
gdriveutils
.
Gdrive
.
Instance
()
.
drive
,
j
[
'id'
])
log
.
debug
(
'
%
r'
,
response
)
if
response
:
if
sys
.
version_info
<
(
3
,
0
):
dbpath
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
"metadata.db"
)
else
:
dbpath
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
"metadata.db"
)
.
encode
()
if
not
response
[
'deleted'
]
and
response
[
'file'
][
'title'
]
==
'metadata.db'
\
and
response
[
'file'
][
'md5Checksum'
]
!=
hashlib
.
md5
(
dbpath
):
tmpDir
=
tempfile
.
gettempdir
()
log
.
info
(
'Database file updated'
)
copyfile
(
dbpath
,
os
.
path
.
join
(
tmpDir
,
"metadata.db_"
+
str
(
current_milli_time
())))
log
.
info
(
'Backing up existing and downloading updated metadata.db'
)
gdriveutils
.
downloadFile
(
None
,
"metadata.db"
,
os
.
path
.
join
(
tmpDir
,
"tmp_metadata.db"
))
log
.
info
(
'Setting up new DB'
)
# prevent error on windows, as os.rename does on exisiting files
move
(
os
.
path
.
join
(
tmpDir
,
"tmp_metadata.db"
),
dbpath
)
calibre_db
.
reconnect_db
(
config
,
ub
.
app_DB_path
)
except
Exception
as
e
:
log
.
exception
(
e
)
updateMetaData
()
log
.
debug
(
'
%
r'
,
request
.
data
)
log
.
info
(
'Change received from gdrive'
)
try
:
j
=
json
.
loads
(
request
.
data
)
log
.
info
(
'Getting change details'
)
response
=
gdriveutils
.
getChangeById
(
gdriveutils
.
Gdrive
.
Instance
()
.
drive
,
j
[
'id'
])
log
.
debug
(
'
%
r'
,
response
)
if
response
:
if
sys
.
version_info
<
(
3
,
0
):
dbpath
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
"metadata.db"
)
else
:
dbpath
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
"metadata.db"
)
.
encode
()
if
not
response
[
'deleted'
]
and
response
[
'file'
][
'title'
]
==
'metadata.db'
\
and
response
[
'file'
][
'md5Checksum'
]
!=
hashlib
.
md5
(
dbpath
):
tmpDir
=
tempfile
.
gettempdir
()
log
.
info
(
'Database file updated'
)
copyfile
(
dbpath
,
os
.
path
.
join
(
tmpDir
,
"metadata.db_"
+
str
(
current_milli_time
())))
log
.
info
(
'Backing up existing and downloading updated metadata.db'
)
gdriveutils
.
downloadFile
(
None
,
"metadata.db"
,
os
.
path
.
join
(
tmpDir
,
"tmp_metadata.db"
))
log
.
info
(
'Setting up new DB'
)
# prevent error on windows, as os.rename does on exisiting files
move
(
os
.
path
.
join
(
tmpDir
,
"tmp_metadata.db"
),
dbpath
)
calibre_db
.
reconnect_db
(
config
,
ub
.
app_DB_path
)
except
Exception
as
e
:
log
.
exception
(
e
)
return
''
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment