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
7ab8a587
Commit
7ab8a587
authored
May 25, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
read PDF/TXT without temporary files (#197)
parent
1366b36c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
14 deletions
+22
-14
readpdf.html
cps/templates/readpdf.html
+1
-1
readtxt.html
cps/templates/readtxt.html
+1
-1
web.py
cps/web.py
+20
-12
No files found.
cps/templates/readpdf.html
View file @
7ab8a587
...
@@ -48,7 +48,7 @@ See https://github.com/adobe-type-tools/cmap-resources
...
@@ -48,7 +48,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<!--<script src="pdf.js"></script>-->
<!--<script src="pdf.js"></script>-->
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
var
DEFAULT_URL
=
"{{ url_for('s
tatic', filename=pdffile
) }}"
;
var
DEFAULT_URL
=
"{{ url_for('s
erve_book', book_id=pdffile,book_format='pdf'
) }}"
;
var
PDFWORKER_LOCATION
=
"{{ url_for('static', filename='js/libs/pdf.worker.js') }}"
;
var
PDFWORKER_LOCATION
=
"{{ url_for('static', filename='js/libs/pdf.worker.js') }}"
;
// var IMAGE_LOCATION="{{ url_for('static', filename='css/../images') }}";
// var IMAGE_LOCATION="{{ url_for('static', filename='css/../images') }}";
var
IMAGE_LOCATION
=
"{{ url_for('static', filename='/images/') }}"
;
var
IMAGE_LOCATION
=
"{{ url_for('static', filename='/images/') }}"
;
...
...
cps/templates/readtxt.html
View file @
7ab8a587
...
@@ -109,7 +109,7 @@
...
@@ -109,7 +109,7 @@
$
(
"#area"
).
width
(
$
(
"#area"
).
width
());
$
(
"#area"
).
width
(
$
(
"#area"
).
width
());
$
(
"#content"
).
width
(
$
(
"#content"
).
width
());
$
(
"#content"
).
width
(
$
(
"#content"
).
width
());
//bind text
//bind text
$
(
"#content"
).
load
(
"{{ url_for('s
tatic', filename=txtfile
) }}"
,
function
(
textStr
)
{
$
(
"#content"
).
load
(
"{{ url_for('s
erve_book', book_id=txtfile,book_format='txt'
) }}"
,
function
(
textStr
)
{
$
(
this
).
height
(
$
(
this
).
parent
().
height
()
*
0.95
);
$
(
this
).
height
(
$
(
this
).
parent
().
height
()
*
0.95
);
$
(
this
).
text
(
textStr
);
$
(
this
).
text
(
textStr
);
});
});
...
...
cps/web.py
View file @
7ab8a587
...
@@ -1581,6 +1581,24 @@ def get_cover(cover_path):
...
@@ -1581,6 +1581,24 @@ def get_cover(cover_path):
else
:
else
:
return
send_from_directory
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
cover_path
),
"cover.jpg"
)
return
send_from_directory
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
cover_path
),
"cover.jpg"
)
@
app
.
route
(
"/show/<book_id>/<book_format>"
)
@
login_required_if_no_ano
def
serve_book
(
book_id
,
book_format
):
book_format
=
book_format
.
split
(
"."
)[
0
]
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
data
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book
.
id
)
.
filter
(
db
.
Data
.
format
==
book_format
.
upper
())
.
first
()
app
.
logger
.
info
(
data
.
name
)
if
config
.
config_use_google_drive
:
headers
=
Headers
()
try
:
headers
[
"Content-Type"
]
=
mimetypes
.
types_map
[
'.'
+
book_format
]
except
KeyError
:
headers
[
"Content-Type"
]
=
"application/octet-stream"
df
=
gdriveutils
.
getFileFromEbooksFolder
(
Gdrive
.
Instance
()
.
drive
,
book
.
path
,
data
.
name
+
"."
+
book_format
)
return
do_gdrive_download
(
df
,
headers
)
else
:
return
send_from_directory
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
),
data
.
name
+
"."
+
book_format
)
@
app
.
route
(
"/opds/thumb_240_240/<path:book_id>"
)
@
app
.
route
(
"/opds/thumb_240_240/<path:book_id>"
)
@
app
.
route
(
"/opds/cover_240_240/<path:book_id>"
)
@
app
.
route
(
"/opds/cover_240_240/<path:book_id>"
)
...
@@ -1680,19 +1698,9 @@ def read_book(book_id, book_format):
...
@@ -1680,19 +1698,9 @@ def read_book(book_id, book_format):
zfile
.
close
()
zfile
.
close
()
return
render_title_template
(
'read.html'
,
bookid
=
book_id
,
title
=
_
(
u"Read a Book"
))
return
render_title_template
(
'read.html'
,
bookid
=
book_id
,
title
=
_
(
u"Read a Book"
))
elif
book_format
.
lower
()
==
"pdf"
:
elif
book_format
.
lower
()
==
"pdf"
:
all_name
=
str
(
book_id
)
+
"/"
+
book
.
data
[
0
]
.
name
+
".pdf"
return
render_title_template
(
'readpdf.html'
,
pdffile
=
book_id
,
title
=
_
(
u"Read a Book"
))
tmp_file
=
os
.
path
.
join
(
book_dir
,
book
.
data
[
0
]
.
name
)
+
".pdf"
if
not
os
.
path
.
exists
(
tmp_file
):
pdf_file
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".pdf"
copyfile
(
pdf_file
,
tmp_file
)
return
render_title_template
(
'readpdf.html'
,
pdffile
=
all_name
,
title
=
_
(
u"Read a Book"
))
elif
book_format
.
lower
()
==
"txt"
:
elif
book_format
.
lower
()
==
"txt"
:
all_name
=
str
(
book_id
)
+
"/"
+
book
.
data
[
0
]
.
name
+
".txt"
return
render_title_template
(
'readtxt.html'
,
txtfile
=
book_id
,
title
=
_
(
u"Read a Book"
))
tmp_file
=
os
.
path
.
join
(
book_dir
,
book
.
data
[
0
]
.
name
)
+
".txt"
if
not
os
.
path
.
exists
(
all_name
):
txt_file
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".txt"
copyfile
(
txt_file
,
tmp_file
)
return
render_title_template
(
'readtxt.html'
,
txtfile
=
all_name
,
title
=
_
(
u"Read a Book"
))
elif
book_format
.
lower
()
==
"cbr"
:
elif
book_format
.
lower
()
==
"cbr"
:
all_name
=
str
(
book_id
)
+
"/"
+
book
.
data
[
0
]
.
name
+
".cbr"
all_name
=
str
(
book_id
)
+
"/"
+
book
.
data
[
0
]
.
name
+
".cbr"
tmp_file
=
os
.
path
.
join
(
book_dir
,
book
.
data
[
0
]
.
name
)
+
".cbr"
tmp_file
=
os
.
path
.
join
(
book_dir
,
book
.
data
[
0
]
.
name
)
+
".cbr"
...
...
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