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
222797e6
Unverified
Commit
222797e6
authored
Nov 21, 2019
by
zhiyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support douban book search using apikey
parent
d1afdb4a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
19 deletions
+58
-19
get_meta.js
cps/static/js/get_meta.js
+52
-17
book_edit.html
cps/templates/book_edit.html
+3
-2
search.html
cps/templates/search.html
+3
-0
No files found.
cps/static/js/get_meta.js
View file @
222797e6
...
@@ -19,15 +19,15 @@
...
@@ -19,15 +19,15 @@
* Google Books api document: https://developers.google.com/books/docs/v1/using
* 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)
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
*/
*/
/* global _, i18nMsg, tinymce */
/* global _, i18nMsg, tinymce */
//
var dbResults = [];
var
dbResults
=
[];
var
ggResults
=
[];
var
ggResults
=
[];
$
(
function
()
{
$
(
function
()
{
var
msg
=
i18nMsg
;
var
msg
=
i18nMsg
;
/*
var douban = "https://api.douban.com";
var
douban
=
"https://api.douban.com"
;
var dbSearch = "/v2/book/search";
*/
var
dbSearch
=
"/v2/book/search"
;
//
var dbDone = true;
var
dbDone
=
true
;
var
google
=
"https://www.googleapis.com"
;
var
google
=
"https://www.googleapis.com"
;
var
ggSearch
=
"/books/v1/volumes"
;
var
ggSearch
=
"/books/v1/volumes"
;
...
@@ -43,12 +43,22 @@ $(function () {
...
@@ -43,12 +43,22 @@ $(function () {
function
populateForm
(
book
)
{
function
populateForm
(
book
)
{
tinymce
.
get
(
"description"
).
setContent
(
book
.
description
);
tinymce
.
get
(
"description"
).
setContent
(
book
.
description
);
var
uniqueTags
=
[];
$
.
each
(
book
.
tags
,
function
(
i
,
el
)
{
if
(
$
.
inArray
(
el
,
uniqueTags
)
===
-
1
)
uniqueTags
.
push
(
el
);
});
$
(
"#bookAuthor"
).
val
(
book
.
authors
);
$
(
"#bookAuthor"
).
val
(
book
.
authors
);
$
(
"#book_title"
).
val
(
book
.
title
);
$
(
"#book_title"
).
val
(
book
.
title
);
$
(
"#tags"
).
val
(
book
.
t
ags
.
join
(
","
));
$
(
"#tags"
).
val
(
uniqueT
ags
.
join
(
","
));
$
(
"#rating"
).
data
(
"rating"
).
setValue
(
Math
.
round
(
book
.
rating
));
$
(
"#rating"
).
data
(
"rating"
).
setValue
(
Math
.
round
(
book
.
rating
));
$
(
".cover img"
).
attr
(
"src"
,
book
.
cover
);
$
(
".cover img"
).
attr
(
"src"
,
book
.
cover
);
$
(
"#cover_url"
).
val
(
book
.
cover
);
$
(
"#cover_url"
).
val
(
book
.
cover
);
$
(
"#pubdate"
).
val
(
book
.
publishedDate
);
$
(
"#publisher"
).
val
(
book
.
publisher
)
if
(
book
.
series
!=
undefined
)
{
$
(
"#series"
).
val
(
book
.
series
)
}
}
}
function
showResult
()
{
function
showResult
()
{
...
@@ -56,10 +66,24 @@ $(function () {
...
@@ -56,10 +66,24 @@ $(function () {
if
(
showFlag
===
1
)
{
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
)
{
if
(
!
ggDone
&&
!
dbDone
)
{
$
(
"#meta-info"
).
html
(
"<p class=
\"
text-danger
\"
>"
+
msg
.
no_result
+
"</p>"
);
$
(
"#meta-info"
).
html
(
"<p class=
\"
text-danger
\"
>"
+
msg
.
no_result
+
"</p>"
);
return
;
return
;
}
}
function
formatDate
(
date
)
{
var
d
=
new
Date
(
date
),
month
=
''
+
(
d
.
getMonth
()
+
1
),
day
=
''
+
d
.
getDate
(),
year
=
d
.
getFullYear
();
if
(
month
.
length
<
2
)
month
=
'0'
+
month
;
if
(
day
.
length
<
2
)
day
=
'0'
+
day
;
return
[
year
,
month
,
day
].
join
(
'-'
);
}
if
(
ggDone
&&
ggResults
.
length
>
0
)
{
if
(
ggDone
&&
ggResults
.
length
>
0
)
{
ggResults
.
forEach
(
function
(
result
)
{
ggResults
.
forEach
(
function
(
result
)
{
var
book
=
{
var
book
=
{
...
@@ -72,8 +96,7 @@ $(function () {
...
@@ -72,8 +96,7 @@ $(function () {
tags
:
result
.
volumeInfo
.
categories
||
[],
tags
:
result
.
volumeInfo
.
categories
||
[],
rating
:
result
.
volumeInfo
.
averageRating
||
0
,
rating
:
result
.
volumeInfo
.
averageRating
||
0
,
cover
:
result
.
volumeInfo
.
imageLinks
?
cover
:
result
.
volumeInfo
.
imageLinks
?
result
.
volumeInfo
.
imageLinks
.
thumbnail
:
result
.
volumeInfo
.
imageLinks
.
thumbnail
:
"/static/generic_cover.jpg"
,
"/static/generic_cover.jpg"
,
url
:
"https://books.google.com/books?id="
+
result
.
id
,
url
:
"https://books.google.com/books?id="
+
result
.
id
,
source
:
{
source
:
{
id
:
"google"
,
id
:
"google"
,
...
@@ -91,19 +114,30 @@ $(function () {
...
@@ -91,19 +114,30 @@ $(function () {
});
});
ggDone
=
false
;
ggDone
=
false
;
}
}
/*
if (dbDone && dbResults.length > 0) {
if
(
dbDone
&&
dbResults
.
length
>
0
)
{
dbResults
.
forEach
(
function
(
result
)
{
dbResults
.
forEach
(
function
(
result
)
{
if
(
result
.
series
){
var
series_title
=
result
.
series
.
title
}
var
date_fomers
=
result
.
pubdate
.
split
(
"-"
)
var
publishedYear
=
parseInt
(
date_fomers
[
0
])
var
publishedMonth
=
parseInt
(
date_fomers
[
1
])
var
publishedDate
=
new
Date
(
publishedYear
,
publishedMonth
-
1
,
1
)
publishedDate
=
formatDate
(
publishedDate
)
var
book
=
{
var
book
=
{
id
:
result
.
id
,
id
:
result
.
id
,
title
:
result
.
title
,
title
:
result
.
title
,
authors
:
result
.
author
||
[],
authors
:
result
.
author
||
[],
description
:
result
.
summary
,
description
:
result
.
summary
,
publisher
:
result
.
publisher
||
""
,
publisher
:
result
.
publisher
||
""
,
publishedDate:
result.pubd
ate || "",
publishedDate
:
publishedD
ate
||
""
,
tags
:
result
.
tags
.
map
(
function
(
tag
)
{
tags
:
result
.
tags
.
map
(
function
(
tag
)
{
return tag.title;
return
tag
.
title
.
toLowerCase
().
replace
(
/,/g
,
"_"
)
;
}),
}),
rating
:
result
.
rating
.
average
||
0
,
rating
:
result
.
rating
.
average
||
0
,
series
:
series_title
||
""
,
cover
:
result
.
image
,
cover
:
result
.
image
,
url
:
"https://book.douban.com/subject/"
+
result
.
id
,
url
:
"https://book.douban.com/subject/"
+
result
.
id
,
source
:
{
source
:
{
...
@@ -125,7 +159,7 @@ $(function () {
...
@@ -125,7 +159,7 @@ $(function () {
$
(
"#book-list"
).
append
(
$book
);
$
(
"#book-list"
).
append
(
$book
);
});
});
dbDone
=
false
;
dbDone
=
false
;
}
*/
}
}
}
function
ggSearchBook
(
title
)
{
function
ggSearchBook
(
title
)
{
...
@@ -148,9 +182,10 @@ $(function () {
...
@@ -148,9 +182,10 @@ $(function () {
});
});
}
}
/*function dbSearchBook (title) {
function
dbSearchBook
(
title
)
{
apikey
=
"0df993c66c0c636e29ecbb5344252a4a"
$
.
ajax
({
$
.
ajax
({
url: douban + dbSearch + "?q=" + title + "&fields=all&count=10",
url
:
douban
+
dbSearch
+
"?
apikey="
+
apikey
+
"&
q="
+
title
+
"&fields=all&count=10"
,
type
:
"GET"
,
type
:
"GET"
,
dataType
:
"jsonp"
,
dataType
:
"jsonp"
,
jsonp
:
"callback"
,
jsonp
:
"callback"
,
...
@@ -166,13 +201,13 @@ $(function () {
...
@@ -166,13 +201,13 @@ $(function () {
$
(
"#show-douban"
).
trigger
(
"change"
);
$
(
"#show-douban"
).
trigger
(
"change"
);
}
}
});
});
}
*/
}
function
doSearch
(
keyword
)
{
function
doSearch
(
keyword
)
{
showFlag
=
0
;
showFlag
=
0
;
$
(
"#meta-info"
).
text
(
msg
.
loading
);
$
(
"#meta-info"
).
text
(
msg
.
loading
);
if
(
keyword
)
{
if
(
keyword
)
{
//
dbSearchBook(keyword);
dbSearchBook
(
keyword
);
ggSearchBook
(
keyword
);
ggSearchBook
(
keyword
);
}
}
}
}
...
...
cps/templates/book_edit.html
View file @
222797e6
...
@@ -219,8 +219,8 @@
...
@@ -219,8 +219,8 @@
</div>
</div>
<div
class=
"modal-body"
>
<div
class=
"modal-body"
>
<div
class=
"text-center padded-bottom"
>
<div
class=
"text-center padded-bottom"
>
<
!--
input type="checkbox" id="show-douban" class="pill" data-control="douban" checked>
<input
type=
"checkbox"
id=
"show-douban"
class=
"pill"
data-control=
"douban"
checked
>
<label for="show-douban">Douban <span class="glyphicon glyphicon-ok"></span></label
--
>
<label
for=
"show-douban"
>
Douban
<span
class=
"glyphicon glyphicon-ok"
></span></label>
<input
type=
"checkbox"
id=
"show-google"
class=
"pill"
data-control=
"google"
checked
>
<input
type=
"checkbox"
id=
"show-google"
class=
"pill"
data-control=
"google"
checked
>
<label
for=
"show-google"
>
Google
<span
class=
"glyphicon glyphicon-ok"
></span></label>
<label
for=
"show-google"
>
Google
<span
class=
"glyphicon glyphicon-ok"
></span></label>
...
@@ -288,6 +288,7 @@
...
@@ -288,6 +288,7 @@
<script
src=
"{{ url_for('static', filename='js/edit_books.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/edit_books.js') }}"
></script>
{% endblock %}
{% endblock %}
{% block header %}
{% block header %}
<meta
name=
"referrer"
content=
"never"
>
<link
href=
"{{ url_for('static', filename='css/libs/typeahead.css') }}"
rel=
"stylesheet"
media=
"screen"
>
<link
href=
"{{ url_for('static', filename='css/libs/typeahead.css') }}"
rel=
"stylesheet"
media=
"screen"
>
<link
href=
"{{ url_for('static', filename='css/libs/bootstrap-datepicker3.min.css') }}"
rel=
"stylesheet"
media=
"screen"
>
<link
href=
"{{ url_for('static', filename='css/libs/bootstrap-datepicker3.min.css') }}"
rel=
"stylesheet"
media=
"screen"
>
{% endblock %}
{% endblock %}
cps/templates/search.html
View file @
222797e6
{% extends "layout.html" %}
{% extends "layout.html" %}
{% block header %}
<meta
name=
"referrer"
content=
"never"
>
{% endblock %}
{% block body %}
{% block body %}
<div
class=
"discover"
>
<div
class=
"discover"
>
{% if entries|length
<
1
%}
{% if entries|length
<
1
%}
...
...
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