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
350f4e21
Commit
350f4e21
authored
Jul 16, 2016
by
wuqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add txt reader
add txt file reader,and add select for read the book
parent
9a8d795e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
236 additions
and
41 deletions
+236
-41
detail.html
cps/templates/detail.html
+17
-2
read.html
cps/templates/read.html
+9
-0
readtxt.html
cps/templates/readtxt.html
+152
-0
web.py
cps/web.py
+57
-38
app.py
vendor/flask/app.py
+1
-1
No files found.
cps/templates/detail.html
View file @
350f4e21
...
@@ -104,8 +104,23 @@
...
@@ -104,8 +104,23 @@
{% if g.user.kindle_mail %}
{% if g.user.kindle_mail %}
<a
href=
"{{url_for('send_to_kindle', book_id=entry.id)}}"
id=
"sendbtn"
class=
"btn btn-primary"
role=
"button"
><span
class=
"glyphicon glyphicon-send"
></span>
Send to Kindle
</a>
<a
href=
"{{url_for('send_to_kindle', book_id=entry.id)}}"
id=
"sendbtn"
class=
"btn btn-primary"
role=
"button"
><span
class=
"glyphicon glyphicon-send"
></span>
Send to Kindle
</a>
{% endif %}
{% endif %}
{% for format in entry.data if format.format|lower == 'epub' or format.format|lower == 'pdf' %}
{% for format in entry.data %}
<a
target=
"_blank"
href=
"{{url_for('read_book', book_id=entry.id)}}"
class=
"btn btn-primary"
role=
"button"
><span
class=
"glyphicon glyphicon-eye-open"
></span>
Read in browser
</a>
{%if format.format|lower == 'epub' or format.format|lower == 'txt' or format.format|lower == 'pdf' %}
<div
class=
"btn-group"
role=
"group"
>
<button
id=
"btnGroupDrop2"
type=
"button"
class=
"btn btn-primary dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
>
<span
class=
"glyphicon glyphicon-download"
></span>
Read in browser
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
aria-labelledby=
"btnGroupDrop2"
>
{% for format in entry.data %}
{%if format.format|lower == 'epub' or format.format|lower == 'txt' or format.format|lower == 'pdf' %}
<li><a
target=
"_blank"
href=
"{{ url_for('read_book', book_id=entry.id, format=format.format|lower) }}"
>
{{format.format}}
</a></li>
{% endif %}
{%endfor%}
</ul>
</div>
{% break %}
{% endif %}
{%endfor%}
{%endfor%}
...
...
cps/templates/read.html
View file @
350f4e21
...
@@ -24,6 +24,15 @@
...
@@ -24,6 +24,15 @@
// fileStorage.filePath = EPUBJS.filePath;
// fileStorage.filePath = EPUBJS.filePath;
window
.
reader
=
ePubReader
(
"{{ url_for('static', filename=bookid) }}/"
);
window
.
reader
=
ePubReader
(
"{{ url_for('static', filename=bookid) }}/"
);
//keybind
$
(
document
).
keydown
(
function
(
event
){
if
(
event
.
keyCode
==
37
){
window
.
reader
.
book
.
prevPage
();
}
if
(
event
.
keyCode
==
39
){
window
.
reader
.
book
.
nextPage
();
}
});
}
}
};
};
...
...
cps/templates/readtxt.html
0 → 100644
View file @
350f4e21
<!DOCTYPE html>
<html
class=
"no-js"
>
<head>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
>
<title>
Basic txt Reader
</title>
<meta
name=
"description"
content=
""
>
<meta
name=
"viewport"
content=
"width=device-width"
>
<meta
name=
"apple-mobile-web-app-capable"
content=
"yes"
>
<!-- EPUBJS Renderer -->
<!--<script src="../build/epub.js"></script>-->
<script
src=
"{{ url_for('static', filename='js/libs/jquery.min.js') }}"
></script>
<style
type=
"text/css"
>
body
{
overflow
:
hidden
;
}
#main
{
position
:
absolute
;
width
:
100%
;
height
:
100%
;
}
#area
{
width
:
80%
;
height
:
80%
;
margin
:
5%
auto
;
max-width
:
1250px
;
}
#area
iframe
{
border
:
none
;
}
#prev
{
left
:
40px
;
}
#next
{
right
:
40px
;
}
.arrow
{
position
:
absolute
;
top
:
50%
;
margin-top
:
-32px
;
font-size
:
64px
;
color
:
#E2E2E2
;
font-family
:
arial
,
sans-serif
;
font-weight
:
bold
;
cursor
:
pointer
;
-webkit-user-select
:
none
;
-moz-user-select
:
none
;
user-select
:
none
;
}
.arrow
:hover
{
color
:
#777
;
}
.arrow
:active
{
color
:
#000
;
}
xmp
,
pre
,
plaintext
{
display
:
block
;
font-family
:
-moz-fixed
;
white-space
:
pre
;
margin
:
1em
0
;
}
#area
{
overflow
:
hidden
;
}
pre
{
white-space
:
pre-wrap
;
word-wrap
:
break-word
;
font-family
:
-moz-fixed
;
column-count
:
2
;
-webkit-columns
:
2
;
-moz-columns
:
2
;
column-gap
:
20px
;
-moz-column-gap
:
20px
;
-webkit-column-gap
:
20px
;
position
:
relative
;
}
</style>
<script>
"use strict"
;
//var Book = ePub("https://s3.amazonaws.com/moby-dick/");
</script>
</head>
<body>
<div
id=
"main"
>
<div
id=
"prev"
class=
"arrow"
onclick=
"prevPage();"
>
‹
</div>
<div
id=
"area"
><pre
id=
"content"
class=
"content"
></pre></div>
<div
id=
"next"
class=
"arrow"
onclick=
"nextPage();"
>
›
</div>
</div>
<script>
$
(
document
).
ready
(
function
()
{
//to int
$
(
"#area"
).
width
(
$
(
"#area"
).
width
());
$
(
"#content"
).
width
(
$
(
"#content"
).
width
());
//bind text
$
(
"#content"
).
load
(
"{{ url_for('static', filename=txtfile) }}"
,
function
(
textStr
)
{
$
(
this
).
height
(
$
(
this
).
parent
().
height
()
*
0.95
);
$
(
this
).
text
(
textStr
);
});
//keybind
$
(
document
).
keydown
(
function
(
event
){
if
(
event
.
keyCode
==
37
){
prevPage
();
}
if
(
event
.
keyCode
==
39
){
nextPage
();
}
});
//bind mouse
$
(
window
).
bind
(
'mousewheel'
,
function
(
event
)
{
if
(
event
.
originalEvent
.
wheelDelta
>=
0
)
{
prevPage
();
}
else
{
nextPage
();
}
});
//page animate
var
origwidth
=
$
(
"#content"
)[
0
].
getBoundingClientRect
().
width
;
var
gap
=
20
;
function
prevPage
(){
if
(
$
(
"#content"
).
offset
().
left
>
0
){
return
;}
leftoff
=
$
(
"#content"
).
offset
().
left
;
leftoff
=
leftoff
+
origwidth
+
gap
;
$
(
"#content"
).
offset
({
left
:
leftoff
});
}
function
nextPage
(){
leftoff
=
$
(
"#content"
).
offset
().
left
;
leftoff
=
leftoff
-
origwidth
-
gap
;
$
(
"#content"
).
offset
({
left
:
leftoff
});
}
});
</script>
</body>
</html>
\ No newline at end of file
cps/web.py
View file @
350f4e21
...
@@ -26,13 +26,16 @@ import json
...
@@ -26,13 +26,16 @@ import json
import
urllib
import
urllib
import
datetime
import
datetime
from
uuid
import
uuid4
from
uuid
import
uuid4
import
os.path
import
shutil
import
re
try
:
try
:
from
wand.image
import
Image
from
wand.image
import
Image
use_generic_pdf_cover
=
False
use_generic_pdf_cover
=
False
except
ImportError
,
e
:
except
ImportError
,
e
:
use_generic_pdf_cover
=
True
use_generic_pdf_cover
=
True
from
shutil
import
copyfile
from
shutil
import
copyfile
from
cgi
import
escape
app
=
(
Flask
(
__name__
))
app
=
(
Flask
(
__name__
))
formatter
=
logging
.
Formatter
(
formatter
=
logging
.
Formatter
(
...
@@ -492,49 +495,65 @@ def author(name):
...
@@ -492,49 +495,65 @@ def author(name):
def
get_cover
(
cover_path
):
def
get_cover
(
cover_path
):
return
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
cover_path
),
"cover.jpg"
)
return
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
cover_path
),
"cover.jpg"
)
@
app
.
route
(
"/read/<int:book_id>"
)
@
app
.
route
(
"/read/<int:book_id>
/<format>
"
)
@
login_required
@
login_required
def
read_book
(
book_id
):
def
read_book
(
book_id
,
format
):
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
book_dir
=
os
.
path
.
join
(
config
.
MAIN_DIR
,
"cps"
,
"static"
,
str
(
book_id
))
book_dir
=
os
.
path
.
join
(
config
.
MAIN_DIR
,
"cps"
,
"static"
,
str
(
book_id
))
if
not
os
.
path
.
exists
(
book_dir
):
if
not
os
.
path
.
exists
(
book_dir
):
os
.
mkdir
(
book_dir
)
os
.
mkdir
(
book_dir
)
for
data
in
book
.
data
:
if
format
.
lower
()
==
"epub"
:
if
data
.
format
.
lower
()
==
"epub"
:
epub_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".epub"
epub_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
data
.
name
)
+
".epub"
if
not
os
.
path
.
isfile
(
epub_file
):
if
not
os
.
path
.
isfile
(
epub_file
):
raise
ValueError
(
'Error opening eBook. File does not exist: '
,
epub_file
)
raise
ValueError
(
'Error opening eBook. File does not exist: '
,
epub_file
)
zfile
=
zipfile
.
ZipFile
(
epub_file
)
zfile
=
zipfile
.
ZipFile
(
epub_file
)
for
name
in
zfile
.
namelist
():
for
name
in
zfile
.
namelist
():
(
dirName
,
fileName
)
=
os
.
path
.
split
(
name
)
(
dirName
,
fileName
)
=
os
.
path
.
split
(
name
)
newDir
=
os
.
path
.
join
(
book_dir
,
dirName
)
newDir
=
os
.
path
.
join
(
book_dir
,
dirName
)
if
not
os
.
path
.
exists
(
newDir
):
if
not
os
.
path
.
exists
(
newDir
):
try
:
try
:
os
.
makedirs
(
newDir
)
os
.
makedirs
(
newDir
)
except
OSError
as
exception
:
except
OSError
as
exception
:
if
exception
.
errno
==
errno
.
EEXIST
:
if
exception
.
errno
==
errno
.
EEXIST
:
pass
pass
else
:
else
:
raise
raise
if
fileName
:
if
fileName
:
fd
=
open
(
os
.
path
.
join
(
newDir
,
fileName
),
"wb"
)
fd
=
open
(
os
.
path
.
join
(
newDir
,
fileName
),
"wb"
)
fd
.
write
(
zfile
.
read
(
name
))
fd
.
write
(
zfile
.
read
(
name
))
fd
.
close
()
fd
.
close
()
zfile
.
close
()
zfile
.
close
()
return
render_template
(
'read.html'
,
bookid
=
book_id
,
title
=
"Read a Book"
)
return
render_template
(
'read.html'
,
bookid
=
book_id
,
title
=
"Read a Book"
)
elif
format
.
lower
()
==
"pdf"
:
elif
data
.
format
.
lower
()
==
"pdf"
:
pdf_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".pdf"
pdf_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
data
.
name
)
+
".pdf"
tmp_file
=
os
.
path
.
join
(
book_dir
,
urllib
.
quote
(
book
.
data
[
0
]
.
name
))
+
".pdf"
tmp_file
=
os
.
path
.
join
(
book_dir
,
urllib
.
quote
(
data
.
name
))
+
".pdf"
copyfile
(
pdf_file
,
tmp_file
)
copyfile
(
pdf_file
,
tmp_file
)
all_name
=
str
(
book_id
)
+
"/"
+
urllib
.
quote
(
book
.
data
[
0
]
.
name
)
+
".pdf"
all_name
=
str
(
book_id
)
+
"/"
+
urllib
.
quote
(
data
.
name
)
+
".pdf"
return
render_template
(
'readpdf.html'
,
pdffile
=
all_name
,
title
=
"Read a Book"
)
return
render_template
(
'readpdf.html'
,
pdffile
=
all_name
,
title
=
"Read a Book"
)
elif
format
.
lower
()
==
"txt"
:
#change txt to epub
txt_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".txt"
tmp_file
=
os
.
path
.
join
(
book_dir
,
urllib
.
quote
(
book
.
data
[
0
]
.
name
))
+
".txt"
copyfile
(
txt_file
,
tmp_file
)
all_name
=
str
(
book_id
)
+
"/"
+
urllib
.
quote
(
book
.
data
[
0
]
.
name
)
+
".txt"
return
render_template
(
'readtxt.html'
,
txtfile
=
all_name
,
title
=
"Read a Book"
)
else
:
else
:
for
data
in
book
.
data
:
if
format
.
lower
()
==
"epub"
:
if
data
.
format
.
lower
()
==
"epub"
:
return
render_template
(
'read.html'
,
bookid
=
book_id
,
title
=
"Read a Book"
)
return
render_template
(
'read.html'
,
bookid
=
book_id
,
title
=
"Read a Book"
)
elif
format
.
lower
()
==
"pdf"
:
elif
data
.
format
.
lower
()
==
"pdf"
:
all_name
=
str
(
book_id
)
+
"/"
+
urllib
.
quote
(
book
.
data
[
0
]
.
name
)
+
".pdf"
all_name
=
str
(
book_id
)
+
"/"
+
urllib
.
quote
(
data
.
name
)
+
".pdf"
tmp_file
=
os
.
path
.
join
(
book_dir
,
urllib
.
quote
(
book
.
data
[
0
]
.
name
))
+
".pdf"
return
render_template
(
'readpdf.html'
,
pdffile
=
all_name
,
title
=
"Read a Book"
)
if
os
.
path
.
exists
(
tmp_file
)
==
False
:
pdf_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".pdf"
copyfile
(
pdf_file
,
tmp_file
)
return
render_template
(
'readpdf.html'
,
pdffile
=
all_name
,
title
=
"Read a Book"
)
elif
format
.
lower
()
==
"txt"
:
all_name
=
str
(
book_id
)
+
"/"
+
urllib
.
quote
(
book
.
data
[
0
]
.
name
)
+
".txt"
tmp_file
=
os
.
path
.
join
(
book_dir
,
urllib
.
quote
(
book
.
data
[
0
]
.
name
))
+
".txt"
if
os
.
path
.
exists
(
all_name
)
==
False
:
txt_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".txt"
copyfile
(
txt_file
,
tmp_file
)
return
render_template
(
'readtxt.html'
,
txtfile
=
all_name
,
title
=
"Read a Book"
)
@
app
.
route
(
"/download/<int:book_id>/<format>"
)
@
app
.
route
(
"/download/<int:book_id>/<format>"
)
@
login_required
@
login_required
...
...
vendor/flask/app.py
View file @
350f4e21
...
@@ -265,7 +265,7 @@ class Flask(_PackageBoundObject):
...
@@ -265,7 +265,7 @@ class Flask(_PackageBoundObject):
#: Options that are passed directly to the Jinja2 environment.
#: Options that are passed directly to the Jinja2 environment.
jinja_options
=
ImmutableDict
(
jinja_options
=
ImmutableDict
(
extensions
=
[
'jinja2.ext.autoescape'
,
'jinja2.ext.with_'
]
extensions
=
[
'jinja2.ext.autoescape'
,
'jinja2.ext.with_'
,
'jinja2.ext.loopcontrols'
]
)
)
#: Default configuration parameters.
#: Default configuration parameters.
...
...
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