Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
console
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
console
Commits
7d487b3b
Commit
7d487b3b
authored
Jan 06, 2017
by
wudizhanche1000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解压
parent
ad895998
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
4 deletions
+103
-4
.gitignore
.gitignore
+1
-0
models/package.ts
models/package.ts
+6
-0
node_modules/@types/is-zip/index.d.ts
node_modules/@types/is-zip/index.d.ts
+12
-0
package.json
package.json
+3
-0
routes/packages.ts
routes/packages.ts
+80
-3
server.ts
server.ts
+1
-1
No files found.
.gitignore
View file @
7d487b3b
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
node-debug.log
node-debug.log
!/node_modules/@types/
!/node_modules/@types/
!/node_modules/@types/mongorito/
!/node_modules/@types/mongorito/
!/node_modules/@types/is-zip/
!systemjs.config.js
!systemjs.config.js
/mongodb_config.json
/mongodb_config.json
...
...
models/package.ts
View file @
7d487b3b
...
@@ -16,6 +16,8 @@ export interface Action {
...
@@ -16,6 +16,8 @@ export interface Action {
export
class
Package
extends
Model
{
export
class
Package
extends
Model
{
@
field
appId
:
string
;
@
field
@
field
version
:
string
;
version
:
string
;
@
field
@
field
...
@@ -24,4 +26,8 @@ export class Package extends Model {
...
@@ -24,4 +26,8 @@ export class Package extends Model {
platform
:
Platform
[];
platform
:
Platform
[];
@
field
@
field
actions
:
{[
key
:
string
]:
Action
};
actions
:
{[
key
:
string
]:
Action
};
static
async
findAllByApp
(
appId
:
string
)
{
return
await
Package
.
find
({
appId
:
appId
});
}
}
}
node_modules/@types/is-zip/index.d.ts
0 → 100644
View file @
7d487b3b
/**
* Created by weijian on 2017/1/6.
*/
export
function
isZip
()
interface
isZip
{
(
f
:
Buffer
|
Uint8Array
):
boolean
}
declare
module
"
is-zip
"
{
export
=
is_zip
;
}
declare
var
is_zip
:
isZip
;
package.json
View file @
7d487b3b
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
"
core-js
"
:
"
^2.4.1
"
,
"
core-js
"
:
"
^2.4.1
"
,
"
font-awesome
"
:
"
^4.7.0
"
,
"
font-awesome
"
:
"
^4.7.0
"
,
"
hammerjs
"
:
"
^2.0.8
"
,
"
hammerjs
"
:
"
^2.0.8
"
,
"
is-zip
"
:
"
^1.0.0
"
,
"
koa
"
:
"
^2.0.0
"
,
"
koa
"
:
"
^2.0.0
"
,
"
koa-bodyparser
"
:
"
^3.2.0
"
,
"
koa-bodyparser
"
:
"
^3.2.0
"
,
"
koa-log4
"
:
"
^2.1.0
"
,
"
koa-log4
"
:
"
^2.1.0
"
,
...
@@ -35,6 +36,7 @@
...
@@ -35,6 +36,7 @@
"
reflect-metadata
"
:
"
^0.1.9
"
,
"
reflect-metadata
"
:
"
^0.1.9
"
,
"
rxjs
"
:
"
5.0.1
"
,
"
rxjs
"
:
"
5.0.1
"
,
"
systemjs
"
:
"
0.19.40
"
,
"
systemjs
"
:
"
0.19.40
"
,
"
tmp
"
:
"
0.0.31
"
,
"
zone.js
"
:
"
^0.7.4
"
"
zone.js
"
:
"
^0.7.4
"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
...
@@ -47,6 +49,7 @@
...
@@ -47,6 +49,7 @@
"
@types/mongodb
"
:
"
^2.1.36
"
,
"
@types/mongodb
"
:
"
^2.1.36
"
,
"
@types/node
"
:
"
^6.0.55
"
,
"
@types/node
"
:
"
^6.0.55
"
,
"
@types/pluralize
"
:
"
0.0.27
"
,
"
@types/pluralize
"
:
"
0.0.27
"
,
"
@types/tmp
"
:
"
0.0.32
"
,
"
concurrently
"
:
"
^3.1.0
"
,
"
concurrently
"
:
"
^3.1.0
"
,
"
lite-server
"
:
"
^2.2.2
"
,
"
lite-server
"
:
"
^2.2.2
"
,
"
tslint
"
:
"
^3.15.1
"
,
"
tslint
"
:
"
^3.15.1
"
,
...
...
routes/packages.ts
View file @
7d487b3b
...
@@ -5,10 +5,69 @@
...
@@ -5,10 +5,69 @@
import
Router
=
require
(
'
koa-router
'
);
import
Router
=
require
(
'
koa-router
'
);
import
{
NotFound
}
from
'
../koa/errors
'
;
import
{
NotFound
}
from
'
../koa/errors
'
;
import
{
Package
}
from
'
../models/package
'
;
import
{
Package
}
from
'
../models/package
'
;
import
*
as
tmp
from
'
tmp
'
;
import
{
ChildProcess
}
from
'
child_process
'
;
import
fs
=
require
(
'
fs
'
);
import
http
=
require
(
'
http
'
);
import
isZip
=
require
(
'
is-zip
'
);
import
path
=
require
(
'
path
'
);
import
child_process
=
require
(
'
child_process
'
);
const
router
=
new
Router
();
const
router
=
new
Router
();
router
.
get
(
'
/packages/all/:appId
'
,
async
(
ctx
,
next
)
=>
{
interface
Option
{
dir
?:
string
;
}
class
Archive
{
constructor
(
public
tarPath
=
'
tar
'
,
public
unzipPath
=
'
unzip
'
)
{
}
async
extract
(
options
?:
Option
)
{
}
private
async
isZip
(
file
:
string
):
Promise
<
boolean
>
{
return
new
Promise
<
boolean
>
((
resolve
,
reject
)
=>
{
fs
.
readFile
(
file
,
(
err
,
data
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
resolve
(
isZip
(
data
));
}
});
});
}
async
decompress
(
file
:
string
,
option
?:
Option
)
{
let
dir
=
'
.
'
;
if
(
option
)
{
if
(
option
.
dir
)
{
dir
=
option
.
dir
;
}
}
await
new
Promise
(
async
(
resolve
,
reject
)
=>
{
let
process
:
ChildProcess
;
if
(
await
this
.
isZip
(
file
))
{
// TODO zip解压
process
=
child_process
.
spawn
(
this
.
unzipPath
);
}
else
{
process
=
child_process
.
spawn
(
this
.
tarPath
,
[
'
xvf
'
,
file
,
'
-c
'
,
dir
]);
}
process
.
on
(
'
exit
'
,
(
code
,
signal
)
=>
{
if
(
code
!==
0
)
{
reject
(
`tar exited by accident, code
${
code
}
`
);
}
else
{
resolve
();
}
});
});
}
}
router
.
get
(
'
/packages/all/:appId
'
,
async
(
ctx
,
next
)
=>
{
let
appId
=
ctx
.
params
.
appId
;
ctx
.
body
=
await
Package
.
findAllByApp
(
appId
);
});
});
router
.
get
(
'
/packages/:id
'
,
async
(
ctx
,
next
)
=>
{
router
.
get
(
'
/packages/:id
'
,
async
(
ctx
,
next
)
=>
{
let
p
:
Package
|
null
=
await
Package
.
findOne
({
id
:
ctx
.
params
.
id
});
let
p
:
Package
|
null
=
await
Package
.
findOne
({
id
:
ctx
.
params
.
id
});
...
@@ -18,7 +77,25 @@ router.get('/packages/:id', async(ctx, next) => {
...
@@ -18,7 +77,25 @@ router.get('/packages/:id', async(ctx, next) => {
ctx
.
body
=
p
;
ctx
.
body
=
p
;
});
});
router
.
post
(
'
/packages/:id
'
,
async
(
ctx
,
next
)
=>
{
router
.
post
(
'
/packages/:id
'
,
async
(
ctx
,
next
)
=>
{
let
p
=
new
Package
(
ctx
.
request
.
body
);
new
Promise
<
string
|
Buffer
>
((
resolve
,
reject
)
=>
{
console
.
log
(
p
,
p
.
version
);
let
downloadUrl
=
ctx
.
request
.
body
.
downloadUrl
;
tmp
.
tmpName
((
e
,
file
)
=>
{
if
(
e
)
{
reject
(
e
);
}
else
{
let
writeStream
=
fs
.
createWriteStream
(
file
);
http
.
get
(
downloadUrl
,
(
response
)
=>
{
response
.
pipe
(
writeStream
);
writeStream
.
on
(
'
finish
'
,
()
=>
{
resolve
(
writeStream
.
path
);
});
}).
on
(
'
error
'
,
(
err
)
=>
{
reject
(
err
);
});
}
});
});
// TODO 打包
});
});
export
default
router
;
export
default
router
;
server.ts
View file @
7d487b3b
...
@@ -26,7 +26,7 @@ app.use(async(ctx, next) => {
...
@@ -26,7 +26,7 @@ app.use(async(ctx, next) => {
await
next
();
await
next
();
}
catch
(
err
)
{
}
catch
(
err
)
{
// will only respond with JSON
// will only respond with JSON
console
.
log
(
err
.
status
);
console
.
log
(
err
);
ctx
.
status
=
err
.
status
||
500
;
ctx
.
status
=
err
.
status
||
500
;
ctx
.
body
=
{
ctx
.
body
=
{
message
:
err
.
message
,
message
:
err
.
message
,
...
...
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