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
6ab8d033
Commit
6ab8d033
authored
Mar 08, 2017
by
Jack Darlington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for editing book cover with drive + fixed found bug that has_cover not set
parent
dd38a2a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
gdriveutils.py
cps/gdriveutils.py
+26
-0
web.py
cps/web.py
+11
-3
No files found.
cps/gdriveutils.py
View file @
6ab8d033
...
...
@@ -238,6 +238,32 @@ def copyToDrive(drive, uploadFile, createRoot, replaceFiles,
driveFile
.
SetContentFile
(
os
.
path
.
join
(
prevDir
,
uploadFile
))
driveFile
.
Upload
()
def
uploadFileToEbooksFolder
(
drive
,
destFile
,
f
):
if
not
drive
:
drive
=
getDrive
()
if
drive
.
auth
.
access_token_expired
:
drive
.
auth
.
Refresh
()
parent
=
getEbooksFolder
(
drive
)
splitDir
=
destFile
.
split
(
'/'
)
for
i
,
x
in
enumerate
(
splitDir
):
if
i
==
len
(
splitDir
)
-
1
:
existingFiles
=
drive
.
ListFile
({
'q'
:
"title = '
%
s' and '
%
s' in parents and trashed = false"
%
(
x
,
parent
[
'id'
])})
.
GetList
()
if
len
(
existingFiles
)
>
0
:
driveFile
=
existingFiles
[
0
]
else
:
driveFile
=
drive
.
CreateFile
({
'title'
:
x
,
'parents'
:
[{
"kind"
:
"drive#fileLink"
,
'id'
:
parent
[
'id'
]}],
})
driveFile
.
SetContentFile
(
f
)
driveFile
.
Upload
()
else
:
existingFolder
=
drive
.
ListFile
({
'q'
:
"title = '
%
s' and '
%
s' in parents and trashed = false"
%
(
x
,
parent
[
'id'
])})
.
GetList
()
if
len
(
existingFolder
)
==
0
:
parent
=
drive
.
CreateFile
({
'title'
:
x
,
'parents'
:
[{
"kind"
:
"drive#fileLink"
,
'id'
:
parent
[
'id'
]}],
"mimeType"
:
"application/vnd.google-apps.folder"
})
parent
.
Upload
()
else
:
parent
=
existingFolder
[
0
]
def
watchChange
(
drive
,
channel_id
,
channel_type
,
channel_address
,
channel_token
=
None
,
expiration
=
None
):
if
not
drive
:
...
...
cps/web.py
View file @
6ab8d033
...
...
@@ -2382,9 +2382,17 @@ def edit_book(book_id):
if
to_save
[
"cover_url"
]
and
os
.
path
.
splitext
(
to_save
[
"cover_url"
])[
1
]
.
lower
()
==
".jpg"
:
img
=
requests
.
get
(
to_save
[
"cover_url"
])
f
=
open
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
,
"cover.jpg"
),
"wb"
)
f
.
write
(
img
.
content
)
f
.
close
()
if
config
.
config_use_google_drive
:
tmpDir
=
tempfile
.
gettempdir
()
f
=
open
(
os
.
path
.
join
(
tmpDir
,
"uploaded_cover.jpg"
),
"wb"
)
f
.
write
(
img
.
content
)
f
.
close
()
gdriveutils
.
uploadFileToEbooksFolder
(
Gdrive
.
Instance
()
.
drive
,
os
.
path
.
join
(
book
.
path
,
'cover.jpg'
),
os
.
path
.
join
(
tmpDir
,
f
.
name
))
else
:
f
=
open
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
,
"cover.jpg"
),
"wb"
)
f
.
write
(
img
.
content
)
f
.
close
()
book
.
has_cover
=
1
if
book
.
series_index
!=
to_save
[
"series_index"
]:
book
.
series_index
=
to_save
[
"series_index"
]
...
...
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