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
986f40b8
Commit
986f40b8
authored
Mar 30, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cosmetics
parent
78067b87
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
80 additions
and
78 deletions
+80
-78
db.py
cps/db.py
+1
-1
epub.py
cps/epub.py
+2
-2
helper.py
cps/helper.py
+3
-3
edit_books.js
cps/static/js/edit_books.js
+23
-20
get_meta.js
cps/static/js/get_meta.js
+33
-32
main.js
cps/static/js/main.js
+14
-15
shelforder.js
cps/static/js/shelforder.js
+2
-2
book_edit.html
cps/templates/book_edit.html
+1
-1
ub.py
cps/ub.py
+1
-2
No files found.
cps/db.py
View file @
986f40b8
...
...
@@ -264,7 +264,7 @@ class Books(Base):
class
Custom_Columns
(
Base
):
__tablename__
=
'custom_columns'
id
=
Column
(
Integer
,
primary_key
=
True
)
label
=
Column
(
String
)
name
=
Column
(
String
)
...
...
cps/epub.py
View file @
986f40b8
...
...
@@ -57,7 +57,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
epub_metadata
[
'description'
]
=
""
if
epub_metadata
[
'language'
]
==
"Unknown"
:
epub_metadata
[
'language'
]
=
=
""
epub_metadata
[
'language'
]
=
""
else
:
lang
=
epub_metadata
[
'language'
]
.
split
(
'-'
,
1
)[
0
]
.
lower
()
if
len
(
lang
)
==
2
:
...
...
@@ -87,7 +87,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
coverfile
=
extractCover
(
zip
,
filename
,
""
,
tmp_file_path
)
else
:
coverfile
=
extractCover
(
zip
,
coversection
[
0
],
coverpath
,
tmp_file_path
)
if
epub_metadata
[
'title'
]
is
None
:
title
=
original_file_name
else
:
...
...
cps/helper.py
View file @
986f40b8
...
...
@@ -277,12 +277,12 @@ def update_dir_stucture(book_id, calibrepath):
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"title_sort"
,
1
,
db
.
title_sort
)
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
path
=
os
.
path
.
join
(
calibrepath
,
book
.
path
)
#.replace('/',os.path.sep)).replace('\\',os.path.sep)
authordir
=
book
.
path
.
split
(
'/'
)[
0
]
new_authordir
=
get_valid_filename
(
book
.
authors
[
0
]
.
name
)
titledir
=
book
.
path
.
split
(
'/'
)[
1
]
new_titledir
=
get_valid_filename
(
book
.
title
)
+
" ("
+
str
(
book_id
)
+
")"
if
titledir
!=
new_titledir
:
new_title_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
path
),
new_titledir
)
os
.
rename
(
path
,
new_title_path
)
...
...
@@ -348,7 +348,7 @@ class Updater(threading.Thread):
if
web
.
gevent_server
:
web
.
gevent_server
.
stop
()
else
:
# stop tornado server
# stop tornado server
server
=
IOLoop
.
instance
()
server
.
add_callback
(
server
.
stop
)
self
.
status
=
7
...
...
cps/static/js/edit_books.js
View file @
986f40b8
...
...
@@ -17,8 +17,8 @@ function prefixed_source(prefix, query, cb, bhAdapter) {
});
}
function
get_path
(){
var
jsFileLocation
=
$
(
'script[src*=edit_books]'
).
attr
(
'src'
);
// the js file path
jsFileLocation
=
jsFileLocation
.
replace
(
'/static/js/edit_books.js'
,
''
);
// the js folder path
var
jsFileLocation
=
$
(
"script[src*=edit_books]"
).
attr
(
"src"
);
// the js file path
jsFileLocation
=
jsFileLocation
.
replace
(
"/static/js/edit_books.js"
,
''
);
// the js folder path
return
jsFileLocation
;
}
...
...
@@ -29,7 +29,7 @@ var authors = new Bloodhound({
},
queryTokenizer
:
Bloodhound
.
tokenizers
.
whitespace
,
remote
:
{
url
:
get_path
()
+
'/get_authors_json?q=%QUERY'
url
:
get_path
()
+
"/get_authors_json?q=%QUERY"
}
});
...
...
@@ -58,7 +58,8 @@ var promise = authors.initialize();
highlight
:
true
,
minLength
:
1
,
hint
:
true
},
{
name
:
'authors'
,
displayKey
:
'name'
,
name
:
"authors"
,
displayKey
:
"name"
,
source
:
authors_source
}
)
...
...
@@ -73,10 +74,9 @@ var series = new Bloodhound({
return
[
query
];
},
remote
:
{
url
:
get_path
()
+
'/get_series_json?q='
,
url
:
get_path
()
+
"/get_series_json?q="
,
replace
:
function
(
url
,
query
)
{
url_query
=
url
+
encodeURIComponent
(
query
);
return
url_query
;
return
url
+
encodeURIComponent
(
query
);
}
}
});
...
...
@@ -87,7 +87,8 @@ var promise = series.initialize();
highlight
:
true
,
minLength
:
0
,
hint
:
true
},
{
name
:
'series'
,
displayKey
:
'name'
,
name
:
"series"
,
displayKey
:
"name"
,
source
:
series
.
ttAdapter
()
}
)
...
...
@@ -99,9 +100,9 @@ var tags = new Bloodhound({
return
[
datum
.
name
];
},
queryTokenizer
:
function
(
query
)
{
tokens
=
query
.
split
(
","
);
var
tokens
=
query
.
split
(
","
);
tokens
=
[
tokens
[
tokens
.
length
-
1
].
trim
()];
return
tokens
return
tokens
;
},
remote
:
{
url
:
get_path
()
+
"/get_tags_json?q=%QUERY"
...
...
@@ -131,7 +132,8 @@ var promise = tags.initialize();
highlight
:
true
,
minLength
:
0
,
hint
:
true
},
{
name
:
'tags'
,
displayKey
:
'name'
,
name
:
"tags"
,
displayKey
:
"name"
,
source
:
tag_source
}
)
...
...
@@ -146,7 +148,7 @@ var languages = new Bloodhound({
return
[
query
];
},
remote
:
{
url
:
get_path
()
+
'/get_languages_json?q='
,
url
:
get_path
()
+
"/get_languages_json?q="
,
replace
:
function
(
url
,
query
)
{
url_query
=
url
+
encodeURIComponent
(
query
);
return
url_query
;
...
...
@@ -177,23 +179,24 @@ var promise = languages.initialize();
highlight
:
true
,
minLength
:
0
,
hint
:
true
},
{
name
:
'languages'
,
displayKey
:
'name'
,
name
:
"languages"
,
displayKey
:
"name"
,
source
:
language_source
}
)
});
$
(
'form'
).
on
(
'change input typeahead:selected'
,
function
(
data
){
form
=
$
(
'form'
).
serialize
();
$
(
"form"
).
on
(
"change input typeahead:selected"
,
function
(
data
){
var
form
=
$
(
"form"
).
serialize
();
$
.
getJSON
(
get_path
()
+
"/get_matching_tags"
,
form
,
function
(
data
)
{
$
(
'.tags_click'
).
each
(
function
()
{
if
(
$
.
inArray
(
parseInt
(
$
(
this
).
children
(
'input'
).
first
().
val
(),
10
),
data
.
tags
)
==
-
1
)
{
if
(
!
(
$
(
this
).
hasClass
(
'active'
)))
{
$
(
this
).
addClass
(
'disabled'
);
$
(
".tags_click"
).
each
(
function
()
{
if
(
$
.
inArray
(
parseInt
(
$
(
this
).
children
(
"input"
).
first
().
val
(),
10
),
data
.
tags
)
=
==
-
1
)
{
if
(
!
(
$
(
this
).
hasClass
(
"active"
)))
{
$
(
this
).
addClass
(
"disabled"
);
}
}
else
{
$
(
this
).
removeClass
(
'disabled'
);
$
(
this
).
removeClass
(
"disabled"
);
}
});
});
...
...
cps/static/js/get_meta.js
View file @
986f40b8
...
...
@@ -6,33 +6,33 @@
*/
$
(
document
).
ready
(
function
()
{
var
msg
=
i18n
_m
sg
;
var
msg
=
i18n
M
sg
;
var
douban
=
"https://api.douban.com"
;
var
db
_search
=
'/v2/book/search'
;
var
db_get_info
=
'/v2/book/'
;
var
db_get_info_by_isbn
=
'/v2/book/isbn/ '
;
var
db
_d
one
=
false
;
var
db
Search
=
"/v2/book/search"
;
var
db_get_info
=
"/v2/book/"
;
var
db_get_info_by_isbn
=
"/v2/book/isbn/ "
;
var
db
D
one
=
false
;
var
google
=
'https://www.googleapis.com/'
;
var
gg_search
=
'/books/v1/volumes'
;
var
gg_get_info
=
'/books/v1/volumes/'
;
var
google
=
"https://www.googleapis.com/"
;
var
gg_search
=
"/books/v1/volumes"
;
var
gg_get_info
=
"/books/v1/volumes/"
;
var
gg_done
=
false
;
var
db_results
=
[];
var
gg_results
=
[];
var
show_flag
=
0
;
String
.
prototype
.
replaceAll
=
function
(
s1
,
s2
)
{
return
this
.
replace
(
new
RegExp
(
s1
,
"gm"
),
s2
);
return
this
.
replace
(
new
RegExp
(
s1
,
"gm"
),
s2
);
};
gg_search_book
=
function
(
title
)
{
title
=
title
.
replaceAll
(
/
\s
+/
,
'+'
);
var
url
=
google
+
gg_search
+
'?q='
+
title
;
function
gg_search_book
(
title
)
{
title
=
title
.
replaceAll
(
/
\s
+/
,
"+"
);
var
url
=
google
+
gg_search
+
"?q="
+
title
;
$
.
ajax
({
url
:
url
,
url
,
type
:
"GET"
,
dataType
:
"jsonp"
,
jsonp
:
'callback'
,
jsonp
:
"callback"
,
success
:
function
(
data
)
{
gg_results
=
data
.
items
;
},
...
...
@@ -43,15 +43,16 @@ $(document).ready(function () {
});
}
get_meta
=
function
(
source
,
id
)
{
function
get_meta
(
source
,
id
)
{
var
meta
;
if
(
source
==
"google"
)
{
var
tags
;
if
(
source
===
"google"
)
{
meta
=
gg_results
[
id
];
$
(
"#description"
).
val
(
meta
.
volumeInfo
.
description
);
$
(
"#bookAuthor"
).
val
(
meta
.
volumeInfo
.
authors
.
join
(
' & '
));
$
(
"#bookAuthor"
).
val
(
meta
.
volumeInfo
.
authors
.
join
(
" & "
));
$
(
"#book_title"
).
val
(
meta
.
volumeInfo
.
title
);
if
(
meta
.
volumeInfo
.
categories
)
{
var
tags
=
meta
.
volumeInfo
.
categories
.
join
(
','
);
tags
=
meta
.
volumeInfo
.
categories
.
join
(
","
);
$
(
"#tags"
).
val
(
tags
);
}
if
(
meta
.
volumeInfo
.
averageRating
)
{
...
...
@@ -59,10 +60,10 @@ $(document).ready(function () {
}
return
;
}
if
(
source
==
"douban"
)
{
if
(
source
==
=
"douban"
)
{
meta
=
db_results
[
id
];
$
(
"#description"
).
val
(
meta
.
summary
);
$
(
"#bookAuthor"
).
val
(
meta
.
author
.
join
(
' & '
));
$
(
"#bookAuthor"
).
val
(
meta
.
author
.
join
(
" & "
));
$
(
"#book_title"
).
val
(
meta
.
title
);
var
tags
=
''
;
for
(
var
i
=
0
;
i
<
meta
.
tags
.
length
;
i
++
)
{
...
...
@@ -84,7 +85,7 @@ $(document).ready(function () {
}
db_search_book
=
function
(
title
)
{
var
url
=
douban
+
db
_s
earch
+
'?q='
+
title
+
'&fields=all&count=10'
;
var
url
=
douban
+
db
S
earch
+
'?q='
+
title
+
'&fields=all&count=10'
;
$
.
ajax
({
url
:
url
,
type
:
"GET"
,
...
...
@@ -97,18 +98,18 @@ $(document).ready(function () {
$
(
'#meta-info'
).
html
(
'<p class="text-danger">'
+
msg
.
search_error
+
'!</p>'
);
},
complete
:
function
()
{
db
_d
one
=
true
;
db
D
one
=
true
;
show_result
();
}
});
}
show_result
=
function
()
{
function
show_result
()
{
show_flag
++
;
if
(
show_flag
==
1
)
{
$
(
'#meta-info'
).
html
(
'<ul id="book-list" class="media-list"></ul>'
);
}
if
(
gg_done
&&
db
_d
one
)
{
if
(
gg_done
&&
db
D
one
)
{
if
(
!
gg_results
&&
!
db_results
)
{
$
(
'#meta-info'
).
html
(
'<p class="text-danger">'
+
msg
.
no_result
+
'</p>'
);
return
;
...
...
@@ -140,7 +141,7 @@ $(document).ready(function () {
}
gg_done
=
false
;
}
if
(
db
_d
one
&&
db_results
.
length
>
0
)
{
if
(
db
D
one
&&
db_results
.
length
>
0
)
{
for
(
var
i
=
0
;
i
<
db_results
.
length
;
i
++
)
{
var
book
=
db_results
[
i
];
var
book_html
=
'<li class="media">'
+
...
...
@@ -155,24 +156,24 @@ $(document).ready(function () {
'<p>'
+
msg
.
description
+
':'
+
book
.
summary
+
'</p>'
+
'<p>'
+
msg
.
source
+
':<a href="https://book.douban.com" target="_blank">Douban Books</a></p>'
+
'</div>'
+
'</li>'
;
"</li>"
;
$
(
"#book-list"
).
append
(
book_html
);
}
db
_d
one
=
false
;
db
D
one
=
false
;
}
}
$
(
'#do-search'
).
click
(
function
()
{
var
keyword
=
$
(
'#keyword'
).
val
();
$
(
"#do-search"
).
click
(
function
()
{
var
keyword
=
$
(
"#keyword"
).
val
();
if
(
keyword
)
{
do_search
(
keyword
);
}
});
$
(
'#get_meta'
).
click
(
function
()
{
var
book_title
=
$
(
'#book_title'
).
val
();
$
(
"#get_meta"
).
click
(
function
()
{
var
book_title
=
$
(
"#book_title"
).
val
();
if
(
book_title
)
{
$
(
'#keyword'
).
val
(
book_title
);
$
(
"#keyword"
).
val
(
book_title
);
do_search
(
book_title
);
}
});
...
...
cps/static/js/main.js
View file @
986f40b8
...
...
@@ -3,7 +3,7 @@ var updateTimerID;
var
updateText
;
$
(
function
()
{
$
(
'.discover .row'
).
isotope
({
$
(
".discover .row"
).
isotope
({
// options
itemSelector
:
".book"
,
layoutMode
:
"fitRows"
...
...
@@ -20,28 +20,28 @@ $(function() {
extraScrollPx
:
300
,
// selector for all items you'll retrieve
},
function
(
data
){
$
(
".load-more .row"
).
isotope
(
'appended'
,
$
(
data
),
null
);
$
(
".load-more .row"
).
isotope
(
"appended"
,
$
(
data
),
null
);
});
$
(
'#sendbtn'
).
click
(
function
(){
$
(
"#sendbtn"
).
click
(
function
(){
var
$this
=
$
(
this
);
$this
.
text
(
"Please wait..."
);
$this
.
addClass
(
"disabled"
);
});
$
(
"#restart"
).
click
(
function
()
{
$
.
ajax
({
dataType
:
'json'
,
dataType
:
"json"
,
url
:
window
.
location
.
pathname
+
"/../../shutdown"
,
data
:
{
"parameter"
:
0
},
success
:
function
(
data
)
{
$
(
'#spinner'
).
show
();
$
(
"#spinner"
).
show
();
displaytext
=
data
.
text
;
setTimeout
(
restartTimer
,
3000
);}
});
});
$
(
"#shutdown"
).
click
(
function
()
{
$
.
ajax
({
dataType
:
'json'
,
dataType
:
"json"
,
url
:
window
.
location
.
pathname
+
"/../../shutdown"
,
data
:
{
"parameter"
:
1
},
success
:
function
(
data
)
{
...
...
@@ -50,13 +50,13 @@ $(function() {
});
$
(
"#check_for_update"
).
click
(
function
()
{
var
button_text
=
$
(
"#check_for_update"
).
html
();
$
(
"#check_for_update"
).
html
(
'...'
);
$
(
"#check_for_update"
).
html
(
"..."
);
$
.
ajax
({
dataType
:
'json'
,
dataType
:
"json"
,
url
:
window
.
location
.
pathname
+
"/../../get_update_status"
,
success
:
function
(
data
)
{
$
(
"#check_for_update"
).
html
(
button_text
);
if
(
data
.
status
==
true
)
{
if
(
data
.
status
==
=
true
)
{
$
(
"#check_for_update"
).
addClass
(
"hidden"
);
$
(
"#perform_update"
).
removeClass
(
"hidden"
);
$
(
"#update_info"
).
removeClass
(
"hidden"
);
...
...
@@ -82,13 +82,12 @@ $(function() {
success
:
function
(
data
)
{
updateText
=
data
.
text
;
$
(
"#UpdateprogressDialog #Updatecontent"
).
html
(
updateText
[
data
.
status
]);
console
.
log
(
data
.
status
);
//
console.log(data.status);
updateTimerID
=
setInterval
(
updateTimer
,
2000
);}
});
});
});
function
restartTimer
()
{
$
(
"#spinner"
).
hide
();
$
(
"#RestartDialog"
).
modal
(
"hide"
);
...
...
@@ -103,10 +102,10 @@ function updateTimer() {
$
(
"#UpdateprogressDialog #Updatecontent"
).
html
(
updateText
[
data
.
status
]);
if
(
data
.
status
>
6
){
clearInterval
(
updateTimerID
);
$
(
'#spinner2'
).
hide
();
$
(
'#UpdateprogressDialog #updateFinished'
).
removeClass
(
'hidden'
);
$
(
"#check_for_update"
).
removeClass
(
'hidden'
);
$
(
"#perform_update"
).
addClass
(
'hidden'
);
$
(
"#spinner2"
).
hide
();
$
(
"#UpdateprogressDialog #updateFinished"
).
removeClass
(
"hidden"
);
$
(
"#check_for_update"
).
removeClass
(
"hidden"
);
$
(
"#perform_update"
).
addClass
(
"hidden"
);
}
},
error
:
function
()
{
...
...
cps/static/js/shelforder.js
View file @
986f40b8
Sortable
.
create
(
sortTrue
,
{
var
sortable
=
Sortable
.
create
(
sortTrue
,
{
group
:
"sorting"
,
sort
:
true
});
...
...
@@ -9,7 +9,7 @@ function sendData(path){
var
maxElements
;
var
tmp
=
[];
elements
=
S
ortable
.
utils
.
find
(
sortTrue
,
"div"
);
elements
=
s
ortable
.
utils
.
find
(
sortTrue
,
"div"
);
maxElements
=
elements
.
length
;
var
form
=
document
.
createElement
(
"form"
);
...
...
cps/templates/book_edit.html
View file @
986f40b8
...
...
@@ -138,7 +138,7 @@
{% block js %}
<script>
var
i18n
_m
sg
=
{
var
i18n
M
sg
=
{
'loading'
:
{{
_
(
'Loading...'
)
|
safe
|
tojson
}},
'search_error'
:
{{
_
(
'Search error!'
)
|
safe
|
tojson
}},
'no_result'
:
{{
_
(
'No Result! Please try anonther keyword.'
)
|
safe
|
tojson
}},
...
...
cps/ub.py
View file @
986f40b8
...
...
@@ -508,7 +508,6 @@ def create_anonymous_user():
session
.
commit
()
except
Exception
:
session
.
rollback
()
pass
# Generate User admin with admin123 password, and access to everything
...
...
@@ -525,7 +524,7 @@ def create_admin_user():
session
.
add
(
user
)
try
:
session
.
commit
()
except
Exception
as
e
:
except
Exception
:
session
.
rollback
()
pass
...
...
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