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
d59be5fa
Commit
d59be5fa
authored
Apr 03, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cosmetics
Bugfix upload
parent
ab534b21
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
45 deletions
+51
-45
get_meta.js
cps/static/js/get_meta.js
+42
-38
web.py
cps/web.py
+9
-7
No files found.
cps/static/js/get_meta.js
View file @
d59be5fa
...
...
@@ -4,6 +4,7 @@
* Google Books api document: https://developers.google.com/books/docs/v1/using
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
*/
/* global i18nMsg */
$
(
document
).
ready
(
function
()
{
var
msg
=
i18nMsg
;
...
...
@@ -26,36 +27,39 @@ $(document).ready(function () {
};
function
showResult
()
{
var
book
;
var
i
;
var
bookHtml
;
showFlag
++
;
if
(
showFlag
===
1
)
{
$
(
"#meta-info"
).
html
(
'<ul id="book-list" class="media-list"></ul>'
);
$
(
"#meta-info"
).
html
(
"<ul id=
\"
book-list
\"
class=
\"
media-list
\"
></ul>"
);
}
if
(
ggDone
&&
dbDone
)
{
if
(
!
ggResults
&&
!
dbResults
)
{
$
(
"#meta-info"
).
html
(
'<p class="text-danger">'
+
msg
.
no_result
+
"</p>"
);
$
(
"#meta-info"
).
html
(
"<p class=
\"
text-danger
\"
>"
+
msg
.
no_result
+
"</p>"
);
return
;
}
}
if
(
ggDone
&&
ggResults
.
length
>
0
)
{
for
(
var
i
=
0
;
i
<
ggResults
.
length
;
i
++
)
{
var
book
=
ggResults
[
i
];
for
(
i
=
0
;
i
<
ggResults
.
length
;
i
++
)
{
book
=
ggResults
[
i
];
var
bookCover
;
if
(
book
.
volumeInfo
.
imageLinks
)
{
bookCover
=
book
.
volumeInfo
.
imageLinks
.
thumbnail
;
}
else
{
bookCover
=
"/static/generic_cover.jpg"
;
}
var
bookHtml
=
'<li class="media">'
+
'<img class="pull-left img-responsive" data-toggle="modal" data-target="#metaModal" src="'
+
bookCover
+
'" alt="Cover" style="width:100px;height:150px" onclick=
\'
javascript:get_meta("google",'
+
i
+
')
\'
>'
+
'<div class="media-body">'
+
'<h4 class="media-heading"><a href="https://books.google.com/books?id='
+
book
.
id
+
'" target="_blank">'
+
book
.
volumeInfo
.
title
+
'</a></h4>'
+
bookHtml
=
"<li class=
\"
media
\"
>"
+
"<img class=
\"
pull-left img-responsive
\"
data-toggle=
\"
modal
\"
data-target=
\"
#metaModal
\"
src=
\"
"
+
bookCover
+
"
\"
alt=
\"
Cover
\"
style=
\"
width:100px;height:150px
\"
onclick='javascript:getMeta(
\"
google
\"
,"
+
i
+
")
\\
>
\"
"
+
"<div class=
\"
media-body
\"
>"
+
"<h4 class=
\"
media-heading
\"
><a href=
\"
https://books.google.com/books?id="
+
book
.
id
+
"
\"
target=
\"
_blank
\"
>"
+
book
.
volumeInfo
.
title
+
"</a></h4>"
+
"<p>"
+
msg
.
author
+
":"
+
book
.
volumeInfo
.
authors
+
"</p>"
+
"<p>"
+
msg
.
publisher
+
":"
+
book
.
volumeInfo
.
publisher
+
"</p>"
+
"<p>"
+
msg
.
description
+
":"
+
book
.
volumeInfo
.
description
+
"</p>"
+
"<p>"
+
msg
.
source
+
':<a href="https://books.google.com" target="_blank">Google Books</a></p>'
+
"<p>"
+
msg
.
source
+
":<a href=
\"
https://books.google.com
\"
target=
\"
_blank
\"
>Google Books</a></p>"
+
"</div>"
+
"</li>"
;
$
(
"#book-list"
).
append
(
bookHtml
);
...
...
@@ -63,19 +67,19 @@ $(document).ready(function () {
ggDone
=
false
;
}
if
(
dbDone
&&
dbResults
.
length
>
0
)
{
for
(
var
i
=
0
;
i
<
dbResults
.
length
;
i
++
)
{
var
book
=
dbResults
[
i
];
var
bookHtml
=
'<li class="media">'
+
'<img class="pull-left img-responsive" data-toggle="modal" data-target="#metaModal" src="'
+
book
.
image
+
'" alt="Cover" style="width:100px;height: 150px" onclick=
\'
javascript:get_meta("douban",'
+
i
+
')
\'
>'
+
'<div class="media-body">'
+
'<h4 class="media-heading"><a href="https://book.douban.com/subject/'
+
book
.
id
+
'" target="_blank">'
+
book
.
title
+
"</a></h4>"
+
for
(
i
=
0
;
i
<
dbResults
.
length
;
i
++
)
{
book
=
dbResults
[
i
];
bookHtml
=
"<li class=
\"
media
\"
>"
+
"<img class=
\"
pull-left img-responsive
\"
data-toggle=
\"
modal
\"
data-target=
\"
#metaModal
\"
src=
\"
"
+
book
.
image
+
"
\"
alt=
\"
Cover
\"
style=
\"
width:100px;height: 150px
\"
onclick='javascript:getMeta(
\"
douban
\"
,"
+
i
+
")
\\
'>"
+
"<div class=
\"
media-body
\"
>"
+
"<h4 class=
\"
media-heading
\"
><a href=
\"
https://book.douban.com/subject/"
+
book
.
id
+
"
\"
target=
\"
_blank
\"
>"
+
book
.
title
+
"</a></h4>"
+
"<p>"
+
msg
.
author
+
":"
+
book
.
author
+
"</p>"
+
"<p>"
+
msg
.
publisher
+
":"
+
book
.
publisher
+
"</p>"
+
"<p>"
+
msg
.
description
+
":"
+
book
.
summary
+
"</p>"
+
"<p>"
+
msg
.
source
+
':<a href="https://book.douban.com" target="_blank">Douban Books</a></p>'
+
"<p>"
+
msg
.
source
+
":<a href=
\"
https://book.douban.com
\"
target=
\"
_blank
\"
>Douban Books</a></p>"
+
"</div>"
+
"</li>"
;
$
(
"#book-list"
).
append
(
bookHtml
);
...
...
@@ -92,17 +96,17 @@ $(document).ready(function () {
type
:
"GET"
,
dataType
:
"jsonp"
,
jsonp
:
"callback"
,
success
:
function
(
data
)
{
success
(
data
)
{
ggResults
=
data
.
items
;
},
complete
:
function
()
{
complete
()
{
ggDone
=
true
;
showResult
();
}
});
}
function
get
_m
eta
(
source
,
id
)
{
function
get
M
eta
(
source
,
id
)
{
var
meta
;
var
tags
;
if
(
source
===
"google"
)
{
...
...
@@ -134,16 +138,6 @@ $(document).ready(function () {
}
}
function
doSearch
(
keyword
)
{
showFlag
=
0
;
$
(
"#meta-info"
).
text
(
msg
.
loading
);
// var keyword = $("#keyword").val();
if
(
keyword
)
{
dbSearchBook
(
keyword
);
ggSearchBook
(
keyword
);
}
}
function
dbSearchBook
(
title
)
{
var
url
=
douban
+
dbSearch
+
"?q="
+
title
+
"&fields=all&count=10"
;
$
.
ajax
({
...
...
@@ -151,19 +145,29 @@ $(document).ready(function () {
type
:
"GET"
,
dataType
:
"jsonp"
,
jsonp
:
"callback"
,
success
:
function
(
data
)
{
success
(
data
)
{
dbResults
=
data
.
books
;
},
error
:
function
()
{
error
()
{
$
(
"#meta-info"
).
html
(
'<p class="text-danger">'
+
msg
.
search_error
+
"!</p>"
);
},
complete
:
function
()
{
complete
()
{
dbDone
=
true
;
showResult
();
}
});
}
function
doSearch
(
keyword
)
{
showFlag
=
0
;
$
(
"#meta-info"
).
text
(
msg
.
loading
);
// var keyword = $("#keyword").val();
if
(
keyword
)
{
dbSearchBook
(
keyword
);
ggSearchBook
(
keyword
);
}
}
$
(
"#do-search"
).
click
(
function
()
{
var
keyword
=
$
(
"#keyword"
).
val
();
if
(
keyword
)
{
...
...
cps/web.py
View file @
d59be5fa
...
...
@@ -2688,13 +2688,15 @@ def upload():
author_names
.
append
(
author
.
name
)
if
config
.
config_use_google_drive
:
updateGdriveCalibreFromLocal
()
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
if
current_user
.
role_edit
()
or
current_user
.
role_admin
():
return
render_title_template
(
'book_edit.html'
,
book
=
db_book
,
authors
=
author_names
,
cc
=
cc
,
title
=
_
(
u"edit metadata"
))
book_in_shelfs
=
[]
return
render_title_template
(
'detail.html'
,
entry
=
db_book
,
cc
=
cc
,
title
=
db_book
.
title
,
books_shelfs
=
book_in_shelfs
,
)
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
if
current_user
.
role_edit
()
or
current_user
.
role_admin
():
return
render_title_template
(
'book_edit.html'
,
book
=
db_book
,
authors
=
author_names
,
cc
=
cc
,
title
=
_
(
u"edit metadata"
))
book_in_shelfs
=
[]
return
render_title_template
(
'detail.html'
,
entry
=
db_book
,
cc
=
cc
,
title
=
db_book
.
title
,
books_shelfs
=
book_in_shelfs
,
)
else
:
return
redirect
(
url_for
(
"index"
))
def
start_gevent
():
from
gevent.wsgi
import
WSGIServer
...
...
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