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
6f0b3bbd
Commit
6f0b3bbd
authored
Mar 05, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for #812
parent
466af215
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
32 deletions
+67
-32
comic.py
cps/comic.py
+22
-9
kthoom.js
cps/static/js/kthoom.js
+33
-22
unzip.js
cps/static/js/unzip.js
+11
-0
uploadprogress.js
cps/static/js/uploadprogress.js
+1
-1
No files found.
cps/comic.py
View file @
6f0b3bbd
...
...
@@ -24,21 +24,34 @@ import uploader
def
extractCover
(
tmp_file_name
,
original_file_extension
):
cover_data
=
None
if
original_file_extension
.
upper
()
==
'.CBZ'
:
cf
=
zipfile
.
ZipFile
(
tmp_file_name
)
compressed_name
=
cf
.
namelist
()[
0
]
cover_data
=
cf
.
read
(
compressed_name
)
for
name
in
cf
.
namelist
():
ext
=
os
.
path
.
splitext
(
name
)
if
len
(
ext
)
>
1
:
extension
=
ext
[
1
]
.
lower
()
if
extension
==
'.jpg'
:
cover_data
=
cf
.
read
(
name
)
break
elif
original_file_extension
.
upper
()
==
'.CBT'
:
cf
=
tarfile
.
TarFile
(
tmp_file_name
)
compressed_name
=
cf
.
getnames
()[
0
]
cover_data
=
cf
.
extractfile
(
compressed_name
)
.
read
()
for
name
in
cf
.
getnames
():
ext
=
os
.
path
.
splitext
(
name
)
if
len
(
ext
)
>
1
:
extension
=
ext
[
1
]
.
lower
()
if
extension
==
'.jpg'
:
cover_data
=
cf
.
extractfile
(
name
)
.
read
()
break
prefix
=
os
.
path
.
dirname
(
tmp_file_name
)
tmp_cover_name
=
prefix
+
'/cover'
+
os
.
path
.
splitext
(
compressed_name
)[
1
]
image
=
open
(
tmp_cover_name
,
'wb'
)
image
.
write
(
cover_data
)
image
.
close
()
if
cover_data
:
tmp_cover_name
=
prefix
+
'/cover'
+
extension
image
=
open
(
tmp_cover_name
,
'wb'
)
image
.
write
(
cover_data
)
image
.
close
()
else
:
tmp_cover_name
=
None
return
tmp_cover_name
...
...
cps/static/js/kthoom.js
View file @
6f0b3bbd
...
...
@@ -99,14 +99,15 @@ kthoom.setSettings = function() {
};
var
createURLFromArray
=
function
(
array
,
mimeType
)
{
var
offset
=
array
.
byteOffset
,
len
=
array
.
byteLength
;
var
offset
=
array
.
byteOffset
;
var
len
=
array
.
byteLength
;
var
url
;
var
blob
;
if
(
mimeType
===
'image/xml+svg'
)
{
const
xmlStr
=
new
TextDecoder
(
'utf-8'
).
decode
(
array
);
return
'data:image/svg+xml;UTF-8,'
+
encodeURIComponent
(
xmlStr
);
}
}
// TODO: Move all this browser support testing to a common place
// and do it just once.
...
...
@@ -137,11 +138,13 @@ var createURLFromArray = function(array, mimeType) {
kthoom
.
ImageFile
=
function
(
file
)
{
this
.
filename
=
file
.
filename
;
var
fileExtension
=
file
.
filename
.
split
(
"."
).
pop
().
toLowerCase
();
var
mimeType
=
fileExtension
===
"png"
?
"image/png"
:
this
.
mimeType
=
fileExtension
===
"png"
?
"image/png"
:
(
fileExtension
===
"jpg"
||
fileExtension
===
"jpeg"
)
?
"image/jpeg"
:
fileExtension
===
"gif"
?
"image/gif"
:
fileExtension
==
'svg'
?
'image/xml+svg'
:
undefined
;
this
.
dataURI
=
createURLFromArray
(
file
.
fileData
,
mimeType
);
this
.
data
=
file
;
if
(
this
.
mimeType
!==
undefined
)
{
this
.
dataURI
=
createURLFromArray
(
file
.
fileData
,
this
.
mimeType
);
this
.
data
=
file
;
}
};
...
...
@@ -169,34 +172,42 @@ function loadFromArrayBuffer(ab) {
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
PROGRESS
,
function
(
e
)
{
var
percentage
=
e
.
currentBytesUnarchived
/
e
.
totalUncompressedBytesInArchive
;
totalImages
=
e
.
totalFilesInArchive
;
if
(
totalImages
===
0
)
{
totalImages
=
e
.
totalFilesInArchive
;
}
updateProgress
(
percentage
*
100
);
lastCompletion
=
percentage
*
100
;
});
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
EXTRACT
,
function
(
e
)
{
// convert DecompressedFile into a bunch of ImageFiles
// convert DecompressedFile into a bunch of ImageFiles
if
(
e
.
unarchivedFile
)
{
var
f
=
e
.
unarchivedFile
;
// add any new pages based on the filename
if
(
imageFilenames
.
indexOf
(
f
.
filename
)
===
-
1
)
{
imageFilenames
.
push
(
f
.
filename
);
imageFiles
.
push
(
new
kthoom
.
ImageFile
(
f
));
// add thumbnails to the TOC list
$
(
"#thumbnails"
).
append
(
"<li>"
+
"<a data-page='"
+
imageFiles
.
length
+
"'>"
+
"<img src='"
+
imageFiles
[
imageFiles
.
length
-
1
].
dataURI
+
"'/>"
+
"<span>"
+
imageFiles
.
length
+
"</span>"
+
"</a>"
+
"</li>"
);
var
test
=
new
kthoom
.
ImageFile
(
f
);
if
(
test
.
mimeType
!==
undefined
)
{
imageFilenames
.
push
(
f
.
filename
);
imageFiles
.
push
(
test
);
// add thumbnails to the TOC list
$
(
"#thumbnails"
).
append
(
"<li>"
+
"<a data-page='"
+
imageFiles
.
length
+
"'>"
+
"<img src='"
+
imageFiles
[
imageFiles
.
length
-
1
].
dataURI
+
"'/>"
+
"<span>"
+
imageFiles
.
length
+
"</span>"
+
"</a>"
+
"</li>"
);
// display first page if we haven't yet
if
(
imageFiles
.
length
===
currentImage
+
1
)
{
updatePage
(
lastCompletion
);
}
}
else
{
totalImages
--
;
}
}
}
// display first page if we haven't yet
if
(
imageFiles
.
length
===
currentImage
+
1
)
{
updatePage
(
lastCompletion
);
}
});
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
FINISH
,
function
()
{
...
...
cps/static/js/unzip.js
View file @
6f0b3bbd
...
...
@@ -113,6 +113,7 @@ ZipLocalFile.prototype.unzip = function() {
info
(
"ZIP v"
+
this
.
version
+
", store only: "
+
this
.
filename
+
" ("
+
this
.
compressedSize
+
" bytes)"
);
currentBytesUnarchivedInFile
=
this
.
compressedSize
;
currentBytesUnarchived
+=
this
.
compressedSize
;
this
.
fileData
=
zeroCompression
(
this
.
fileData
,
this
.
uncompressedSize
);
}
// version == 20, compression method == 8 (DEFLATE)
else
if
(
this
.
compressionMethod
==
8
)
{
...
...
@@ -493,6 +494,16 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
return
blockSize
;
}
function
zeroCompression
(
compressedData
,
numDecompressedBytes
)
{
var
bstream
=
new
bitjs
.
io
.
BitStream
(
compressedData
.
buffer
,
false
/* rtl */
,
compressedData
.
byteOffset
,
compressedData
.
byteLength
);
var
buffer
=
new
bitjs
.
io
.
ByteBuffer
(
numDecompressedBytes
);
buffer
.
insertBytes
(
bstream
.
readBytes
(
numDecompressedBytes
));
return
buffer
.
data
;
}
// {Uint8Array} compressedData A Uint8Array of the compressed file data.
// compression method 8
// deflate: http://tools.ietf.org/html/rfc1951
...
...
cps/static/js/uploadprogress.js
View file @
6f0b3bbd
...
...
@@ -170,7 +170,7 @@
replaceForm
:
function
(
html
)
{
var
newForm
;
var
formId
=
this
.
$form
.
attr
(
"id"
);
if
(
typeof
(
formId
)
!==
"undefined"
)
{
if
(
typeof
formId
!==
"undefined"
)
{
newForm
=
$
(
html
).
find
(
"#"
+
formId
);
}
else
{
newForm
=
$
(
html
).
find
(
"form"
);
...
...
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