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
2a78a02e
Commit
2a78a02e
authored
Sep 17, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cosmetics
parent
34e9ef35
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
171 additions
and
175 deletions
+171
-175
archive.js
cps/static/js/archive.js
+48
-40
io.js
cps/static/js/io.js
+4
-4
kthoom.js
cps/static/js/kthoom.js
+109
-121
untar.js
cps/static/js/untar.js
+10
-10
No files found.
cps/static/js/archive.js
View file @
2a78a02e
...
@@ -15,7 +15,7 @@ bitjs.archive = bitjs.archive || {};
...
@@ -15,7 +15,7 @@ bitjs.archive = bitjs.archive || {};
// ===========================================================================
// ===========================================================================
// Stolen from Closure because it's the best way to do Java-like inheritance.
// Stolen from Closure because it's the best way to do Java-like inheritance.
bitjs
.
base
=
function
(
me
,
opt
_m
ethodName
,
var_args
)
{
bitjs
.
base
=
function
(
me
,
opt
M
ethodName
,
var_args
)
{
var
caller
=
arguments
.
callee
.
caller
;
var
caller
=
arguments
.
callee
.
caller
;
if
(
caller
.
superClass_
)
{
if
(
caller
.
superClass_
)
{
// This is a constructor. Call the superclass constructor.
// This is a constructor. Call the superclass constructor.
...
@@ -27,10 +27,10 @@ bitjs.archive = bitjs.archive || {};
...
@@ -27,10 +27,10 @@ bitjs.archive = bitjs.archive || {};
var
foundCaller
=
false
;
var
foundCaller
=
false
;
for
(
var
ctor
=
me
.
constructor
;
for
(
var
ctor
=
me
.
constructor
;
ctor
;
ctor
=
ctor
.
superClass_
&&
ctor
.
superClass_
.
constructor
)
{
ctor
;
ctor
=
ctor
.
superClass_
&&
ctor
.
superClass_
.
constructor
)
{
if
(
ctor
.
prototype
[
opt
_m
ethodName
]
===
caller
)
{
if
(
ctor
.
prototype
[
opt
M
ethodName
]
===
caller
)
{
foundCaller
=
true
;
foundCaller
=
true
;
}
else
if
(
foundCaller
)
{
}
else
if
(
foundCaller
)
{
return
ctor
.
prototype
[
opt
_m
ethodName
].
apply
(
me
,
args
);
return
ctor
.
prototype
[
opt
M
ethodName
].
apply
(
me
,
args
);
}
}
}
}
...
@@ -38,12 +38,12 @@ bitjs.archive = bitjs.archive || {};
...
@@ -38,12 +38,12 @@ bitjs.archive = bitjs.archive || {};
// then one of two things happened:
// then one of two things happened:
// 1) The caller is an instance method.
// 1) The caller is an instance method.
// 2) This method was not called by the right caller.
// 2) This method was not called by the right caller.
if
(
me
[
opt
_m
ethodName
]
===
caller
)
{
if
(
me
[
opt
M
ethodName
]
===
caller
)
{
return
me
.
constructor
.
prototype
[
opt
_m
ethodName
].
apply
(
me
,
args
);
return
me
.
constructor
.
prototype
[
opt
M
ethodName
].
apply
(
me
,
args
);
}
else
{
}
else
{
throw
Error
(
throw
Error
(
'goog.base called from a method of one name '
+
"goog.base called from a method of one name "
+
'to a method of a different name'
);
"to a method of a different name"
);
}
}
};
};
bitjs
.
inherits
=
function
(
childCtor
,
parentCtor
)
{
bitjs
.
inherits
=
function
(
childCtor
,
parentCtor
)
{
...
@@ -75,12 +75,12 @@ bitjs.archive = bitjs.archive || {};
...
@@ -75,12 +75,12 @@ bitjs.archive = bitjs.archive || {};
* The UnarchiveEvent types.
* The UnarchiveEvent types.
*/
*/
bitjs
.
archive
.
UnarchiveEvent
.
Type
=
{
bitjs
.
archive
.
UnarchiveEvent
.
Type
=
{
START
:
'start'
,
START
:
"start"
,
PROGRESS
:
'progress'
,
PROGRESS
:
"progress"
,
EXTRACT
:
'extract'
,
EXTRACT
:
"extract"
,
FINISH
:
'finish'
,
FINISH
:
"finish"
,
INFO
:
'info'
,
INFO
:
"info"
,
ERROR
:
'error'
ERROR
:
"error"
};
};
/**
/**
...
@@ -141,12 +141,12 @@ bitjs.archive = bitjs.archive || {};
...
@@ -141,12 +141,12 @@ bitjs.archive = bitjs.archive || {};
* Progress event.
* Progress event.
*/
*/
bitjs
.
archive
.
UnarchiveProgressEvent
=
function
(
bitjs
.
archive
.
UnarchiveProgressEvent
=
function
(
currentFilename
,
currentFilename
,
currentFileNumber
,
currentFileNumber
,
currentBytesUnarchivedInFile
,
currentBytesUnarchivedInFile
,
currentBytesUnarchived
,
currentBytesUnarchived
,
totalUncompressedBytesInArchive
,
totalUncompressedBytesInArchive
,
totalFilesInArchive
)
totalFilesInArchive
)
{
{
bitjs
.
base
(
this
,
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
PROGRESS
);
bitjs
.
base
(
this
,
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
PROGRESS
);
...
@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
...
@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
* Base class for all Unarchivers.
* Base class for all Unarchivers.
*
*
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
* @param {string} opt
_p
athToBitJS Optional string for where the BitJS files are located.
* @param {string} opt
P
athToBitJS Optional string for where the BitJS files are located.
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Unarchiver
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Unarchiver
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
/**
/**
* The ArrayBuffer object.
* The ArrayBuffer object.
* @type {ArrayBuffer}
* @type {ArrayBuffer}
...
@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
...
@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
* @type {string}
* @type {string}
* @private
* @private
*/
*/
this
.
pathToBitJS_
=
opt
_pathToBitJS
||
''
;
this
.
pathToBitJS_
=
opt
PathToBitJS
||
""
;
/**
/**
* A map from event type to an array of listeners.
* A map from event type to an array of listeners.
...
@@ -229,7 +229,7 @@ bitjs.archive = bitjs.archive || {};
...
@@ -229,7 +229,7 @@ bitjs.archive = bitjs.archive || {};
* @protected.
* @protected.
*/
*/
bitjs
.
archive
.
Unarchiver
.
prototype
.
getScriptFileName
=
function
()
{
bitjs
.
archive
.
Unarchiver
.
prototype
.
getScriptFileName
=
function
()
{
throw
'Subclasses of AbstractUnarchiver must overload getScriptFileName()'
;
throw
"Subclasses of AbstractUnarchiver must overload getScriptFileName()"
;
};
};
/**
/**
...
@@ -240,7 +240,7 @@ bitjs.archive = bitjs.archive || {};
...
@@ -240,7 +240,7 @@ bitjs.archive = bitjs.archive || {};
*/
*/
bitjs
.
archive
.
Unarchiver
.
prototype
.
addEventListener
=
function
(
type
,
listener
)
{
bitjs
.
archive
.
Unarchiver
.
prototype
.
addEventListener
=
function
(
type
,
listener
)
{
if
(
type
in
this
.
listeners_
)
{
if
(
type
in
this
.
listeners_
)
{
if
(
this
.
listeners_
[
type
].
indexOf
(
listener
)
==
-
1
)
{
if
(
this
.
listeners_
[
type
].
indexOf
(
listener
)
==
=
-
1
)
{
this
.
listeners_
[
type
].
push
(
listener
);
this
.
listeners_
[
type
].
push
(
listener
);
}
}
}
}
...
@@ -255,7 +255,7 @@ bitjs.archive = bitjs.archive || {};
...
@@ -255,7 +255,7 @@ bitjs.archive = bitjs.archive || {};
bitjs
.
archive
.
Unarchiver
.
prototype
.
removeEventListener
=
function
(
type
,
listener
)
{
bitjs
.
archive
.
Unarchiver
.
prototype
.
removeEventListener
=
function
(
type
,
listener
)
{
if
(
type
in
this
.
listeners_
)
{
if
(
type
in
this
.
listeners_
)
{
var
index
=
this
.
listeners_
[
type
].
indexOf
(
listener
);
var
index
=
this
.
listeners_
[
type
].
indexOf
(
listener
);
if
(
index
!=
-
1
)
{
if
(
index
!=
=
-
1
)
{
this
.
listeners_
[
type
].
splice
(
index
,
1
);
this
.
listeners_
[
type
].
splice
(
index
,
1
);
}
}
}
}
...
@@ -270,8 +270,10 @@ bitjs.archive = bitjs.archive || {};
...
@@ -270,8 +270,10 @@ bitjs.archive = bitjs.archive || {};
bitjs
.
archive
.
Unarchiver
.
prototype
.
handleWorkerEvent_
=
function
(
e
)
{
bitjs
.
archive
.
Unarchiver
.
prototype
.
handleWorkerEvent_
=
function
(
e
)
{
if
((
e
instanceof
bitjs
.
archive
.
UnarchiveEvent
||
e
.
type
)
&&
if
((
e
instanceof
bitjs
.
archive
.
UnarchiveEvent
||
e
.
type
)
&&
this
.
listeners_
[
e
.
type
]
instanceof
Array
)
{
this
.
listeners_
[
e
.
type
]
instanceof
Array
)
{
this
.
listeners_
[
e
.
type
].
forEach
(
function
(
listener
)
{
listener
(
e
)
});
this
.
listeners_
[
e
.
type
].
forEach
(
function
(
listener
)
{
if
(
e
.
type
==
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
FINISH
)
{
listener
(
e
);
});
if
(
e
.
type
===
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
FINISH
)
{
this
.
worker_
.
terminate
();
this
.
worker_
.
terminate
();
}
}
}
else
{
}
else
{
...
@@ -281,20 +283,20 @@ bitjs.archive = bitjs.archive || {};
...
@@ -281,20 +283,20 @@ bitjs.archive = bitjs.archive || {};
/**
/**
* Starts the unarchive in a separate Web Worker thread and returns immediately.
* Starts the unarchive in a separate Web Worker thread and returns immediately.
*/
*/
bitjs
.
archive
.
Unarchiver
.
prototype
.
start
=
function
()
{
bitjs
.
archive
.
Unarchiver
.
prototype
.
start
=
function
()
{
var
me
=
this
;
var
me
=
this
;
var
scriptFileName
=
this
.
pathToBitJS_
+
this
.
getScriptFileName
();
var
scriptFileName
=
this
.
pathToBitJS_
+
this
.
getScriptFileName
();
if
(
scriptFileName
)
{
if
(
scriptFileName
)
{
this
.
worker_
=
new
Worker
(
scriptFileName
);
this
.
worker_
=
new
Worker
(
scriptFileName
);
this
.
worker_
.
onerror
=
function
(
e
)
{
this
.
worker_
.
onerror
=
function
(
e
)
{
console
.
log
(
'Worker error: message = '
+
e
.
message
);
console
.
log
(
"Worker error: message = "
+
e
.
message
);
throw
e
;
throw
e
;
};
};
this
.
worker_
.
onmessage
=
function
(
e
)
{
this
.
worker_
.
onmessage
=
function
(
e
)
{
if
(
typeof
e
.
data
==
'string'
)
{
if
(
typeof
e
.
data
==
"string"
)
{
// Just log any strings the workers pump our way.
// Just log any strings the workers pump our way.
console
.
log
(
e
.
data
);
console
.
log
(
e
.
data
);
}
else
{
}
else
{
...
@@ -323,32 +325,38 @@ bitjs.archive = bitjs.archive || {};
...
@@ -323,32 +325,38 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @extends {bitjs.archive.Unarchiver}
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Unzipper
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Unzipper
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
};
bitjs
.
inherits
(
bitjs
.
archive
.
Unzipper
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
inherits
(
bitjs
.
archive
.
Unzipper
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Unzipper
.
prototype
.
getScriptFileName
=
function
()
{
return
'unzip.js'
};
bitjs
.
archive
.
Unzipper
.
prototype
.
getScriptFileName
=
function
()
{
return
"unzip.js"
;
};
/**
/**
* Unrarrer
* Unrarrer
* @extends {bitjs.archive.Unarchiver}
* @extends {bitjs.archive.Unarchiver}
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Unrarrer
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Unrarrer
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
};
bitjs
.
inherits
(
bitjs
.
archive
.
Unrarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
inherits
(
bitjs
.
archive
.
Unrarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Unrarrer
.
prototype
.
getScriptFileName
=
function
()
{
return
'unrar.js'
};
bitjs
.
archive
.
Unrarrer
.
prototype
.
getScriptFileName
=
function
()
{
return
"unrar.js"
;
};
/**
/**
* Untarrer
* Untarrer
* @extends {bitjs.archive.Unarchiver}
* @extends {bitjs.archive.Unarchiver}
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Untarrer
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Untarrer
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
};
bitjs
.
inherits
(
bitjs
.
archive
.
Untarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
inherits
(
bitjs
.
archive
.
Untarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Untarrer
.
prototype
.
getScriptFileName
=
function
()
{
return
'untar.js'
};
bitjs
.
archive
.
Untarrer
.
prototype
.
getScriptFileName
=
function
()
{
return
"untar.js"
;
};
})();
})();
cps/static/js/io.js
View file @
2a78a02e
...
@@ -417,14 +417,14 @@ bitjs.io = bitjs.io || {};
...
@@ -417,14 +417,14 @@ bitjs.io = bitjs.io || {};
*/
*/
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeNumber
=
function
(
num
,
numBytes
)
{
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeNumber
=
function
(
num
,
numBytes
)
{
if
(
numBytes
<
1
)
{
if
(
numBytes
<
1
)
{
throw
'Trying to write into too few bytes: '
+
numBytes
;
throw
"Trying to write into too few bytes: "
+
numBytes
;
}
}
if
(
num
<
0
)
{
if
(
num
<
0
)
{
throw
'Trying to write a negative number ('
+
num
+
throw
"Trying to write a negative number ("
+
num
+
') as an unsigned number to an ArrayBuffer'
;
") as an unsigned number to an ArrayBuffer"
;
}
}
if
(
num
>
(
Math
.
pow
(
2
,
numBytes
*
8
)
-
1
))
{
if
(
num
>
(
Math
.
pow
(
2
,
numBytes
*
8
)
-
1
))
{
throw
'Trying to write '
+
num
+
' into only '
+
numBytes
+
' bytes'
;
throw
"Trying to write "
+
num
+
" into only "
+
numBytes
+
" bytes"
;
}
}
// Roll 8-bits at a time into an array of bytes.
// Roll 8-bits at a time into an array of bytes.
...
...
cps/static/js/kthoom.js
View file @
2a78a02e
This diff is collapsed.
Click to expand it.
cps/static/js/untar.js
View file @
2a78a02e
...
@@ -42,7 +42,7 @@ var postProgress = function() {
...
@@ -42,7 +42,7 @@ var postProgress = function() {
var
readCleanString
=
function
(
bstr
,
numBytes
)
{
var
readCleanString
=
function
(
bstr
,
numBytes
)
{
var
str
=
bstr
.
readString
(
numBytes
);
var
str
=
bstr
.
readString
(
numBytes
);
var
zIndex
=
str
.
indexOf
(
String
.
fromCharCode
(
0
));
var
zIndex
=
str
.
indexOf
(
String
.
fromCharCode
(
0
));
return
zIndex
!=
-
1
?
str
.
substr
(
0
,
zIndex
)
:
str
;
return
zIndex
!=
=
-
1
?
str
.
substr
(
0
,
zIndex
)
:
str
;
};
};
// takes a ByteStream and parses out the local file information
// takes a ByteStream and parses out the local file information
...
@@ -61,7 +61,7 @@ var TarLocalFile = function(bstream) {
...
@@ -61,7 +61,7 @@ var TarLocalFile = function(bstream) {
this
.
linkname
=
readCleanString
(
bstream
,
100
);
this
.
linkname
=
readCleanString
(
bstream
,
100
);
this
.
maybeMagic
=
readCleanString
(
bstream
,
6
);
this
.
maybeMagic
=
readCleanString
(
bstream
,
6
);
if
(
this
.
maybeMagic
==
"ustar"
)
{
if
(
this
.
maybeMagic
==
=
"ustar"
)
{
this
.
version
=
readCleanString
(
bstream
,
2
);
this
.
version
=
readCleanString
(
bstream
,
2
);
this
.
uname
=
readCleanString
(
bstream
,
32
);
this
.
uname
=
readCleanString
(
bstream
,
32
);
this
.
gname
=
readCleanString
(
bstream
,
32
);
this
.
gname
=
readCleanString
(
bstream
,
32
);
...
@@ -71,10 +71,10 @@ var TarLocalFile = function(bstream) {
...
@@ -71,10 +71,10 @@ var TarLocalFile = function(bstream) {
if
(
this
.
prefix
.
length
)
{
if
(
this
.
prefix
.
length
)
{
this
.
name
=
this
.
prefix
+
this
.
name
;
this
.
name
=
this
.
prefix
+
this
.
name
;
}
}
bstream
.
readBytes
(
12
);
// 512 - 500
bstream
.
readBytes
(
12
);
// 512 - 500
}
else
{
}
else
{
bstream
.
readBytes
(
255
);
// 512 - 257
bstream
.
readBytes
(
255
);
// 512 - 257
}
}
// Done header, now rest of blocks are the file contents.
// Done header, now rest of blocks are the file contents.
...
@@ -86,7 +86,7 @@ var TarLocalFile = function(bstream) {
...
@@ -86,7 +86,7 @@ var TarLocalFile = function(bstream) {
info
(
" typeflag = "
+
this
.
typeflag
);
info
(
" typeflag = "
+
this
.
typeflag
);
// A regular file.
// A regular file.
if
(
this
.
typeflag
==
0
)
{
if
(
this
.
typeflag
==
=
0
)
{
info
(
" This is a regular file."
);
info
(
" This is a regular file."
);
var
sizeInBytes
=
parseInt
(
this
.
size
);
var
sizeInBytes
=
parseInt
(
this
.
size
);
this
.
fileData
=
new
Uint8Array
(
bstream
.
bytes
.
buffer
,
bstream
.
ptr
,
this
.
size
);
this
.
fileData
=
new
Uint8Array
(
bstream
.
bytes
.
buffer
,
bstream
.
ptr
,
this
.
size
);
...
@@ -101,8 +101,8 @@ var TarLocalFile = function(bstream) {
...
@@ -101,8 +101,8 @@ var TarLocalFile = function(bstream) {
if
(
remaining
>
0
&&
remaining
<
512
)
{
if
(
remaining
>
0
&&
remaining
<
512
)
{
bstream
.
readBytes
(
remaining
);
bstream
.
readBytes
(
remaining
);
}
}
}
else
if
(
this
.
typeflag
==
5
)
{
}
else
if
(
this
.
typeflag
==
=
5
)
{
info
(
" This is a directory."
)
info
(
" This is a directory."
)
;
}
}
};
};
...
@@ -122,7 +122,7 @@ var untar = function(arrayBuffer) {
...
@@ -122,7 +122,7 @@ var untar = function(arrayBuffer) {
var
localFiles
=
[];
var
localFiles
=
[];
// While we don't encounter an empty block, keep making TarLocalFiles.
// While we don't encounter an empty block, keep making TarLocalFiles.
while
(
bstream
.
peekNumber
(
4
)
!=
0
)
{
while
(
bstream
.
peekNumber
(
4
)
!=
=
0
)
{
var
oneLocalFile
=
new
TarLocalFile
(
bstream
);
var
oneLocalFile
=
new
TarLocalFile
(
bstream
);
if
(
oneLocalFile
&&
oneLocalFile
.
isValid
)
{
if
(
oneLocalFile
&&
oneLocalFile
.
isValid
)
{
localFiles
.
push
(
oneLocalFile
);
localFiles
.
push
(
oneLocalFile
);
...
@@ -132,7 +132,7 @@ var untar = function(arrayBuffer) {
...
@@ -132,7 +132,7 @@ var untar = function(arrayBuffer) {
totalFilesInArchive
=
localFiles
.
length
;
totalFilesInArchive
=
localFiles
.
length
;
// got all local files, now sort them
// got all local files, now sort them
localFiles
.
sort
(
function
(
a
,
b
)
{
localFiles
.
sort
(
function
(
a
,
b
)
{
var
aname
=
a
.
filename
.
toLowerCase
();
var
aname
=
a
.
filename
.
toLowerCase
();
var
bname
=
b
.
filename
.
toLowerCase
();
var
bname
=
b
.
filename
.
toLowerCase
();
return
aname
>
bname
?
1
:
-
1
;
return
aname
>
bname
?
1
:
-
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