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
ad75b565
Commit
ad75b565
authored
Apr 20, 2017
by
nano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
error handing
parent
c3f4ecc2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
120 deletions
+109
-120
.idea/workspace.xml
.idea/workspace.xml
+61
-91
package/main.ts
package/main.ts
+5
-5
src/routes/package.ts
src/routes/package.ts
+1
-3
src/routes/upload.ts
src/routes/upload.ts
+42
-21
No files found.
.idea/workspace.xml
View file @
ad75b565
This diff is collapsed.
Click to expand it.
package/main.ts
View file @
ad75b565
...
...
@@ -43,18 +43,18 @@ export async function bundle(...args) {
files
.
set
(
file
,
{
path
:
file
,
hash
:
file_hash
,
size
:
(
await
fs
.
statAsync
(
file
)).
size
.
toString
()
size
:
(
await
fs
.
statAsync
(
file
)).
size
})
let
sand_file
=
path
.
join
(
sand_path
,
`
${
file_hash
}
.tar.gz`
)
await
archiveSingle
(
sand_file
,
[
file
],
package_path
)
archives
.
set
(
sand_file
,
{
path
:
sand_file
,
hash
:
await
caculateSHA256
(
sand_file
),
size
:
(
await
fs
.
statAsync
(
sand_file
)).
size
.
toString
()
size
:
(
await
fs
.
statAsync
(
sand_file
)).
size
})
await
archiveSingle
(
sand_file
,
[
file
],
package_path
)
},
onDir
:
async
(
files
,
_path
,
depth
)
=>
{
},
...
...
@@ -68,7 +68,7 @@ export async function bundle(...args) {
// TODO: 上传meta
const
fullHash
=
await
caculateSHA256
(
fullFile
)
const
fullSize
=
(
await
fs
.
statAsync
(
fullFile
)).
size
.
toString
()
const
fullSize
=
(
await
fs
.
statAsync
(
fullFile
)).
size
// TODO: 增量包
...
...
src/routes/package.ts
View file @
ad75b565
...
...
@@ -23,7 +23,7 @@ router.post('/v2/package/:id/update', async (ctx: Context, next) => {
let
sandSize
=
ctx
.
request
.
body
.
length
*
request_overhead
let
pack
=
await
mongodb
.
Packages
.
findOne
({
id
:
package_id
,
status
:
'
ready
'
})
let
pack
=
await
mongodb
.
Packages
.
findOne
({
id
:
package_id
,
status
:
'
uploaded
'
})
let
{
fullSize
,
fullPath
}
=
pack
!
...
...
@@ -61,8 +61,6 @@ router.post('/v2/package/:id/update', async (ctx: Context, next) => {
})
router
.
get
(
'
/v1/packages
'
,
async
(
ctx
:
Context
,
next
)
=>
{
if
(
!
ctx
.
request
.
query
.
appId
)
{
ctx
.
throw
(
400
,
"
appId must be required!
"
)
...
...
src/routes/upload.ts
View file @
ad75b565
...
...
@@ -20,6 +20,12 @@ import config from '../../config'
// path: path.join(__dirname, '../../test/upload')
// }
const
checkExtension
=
async
(
file
)
=>
{
const
ext
=
mime
.
extension
(
file
.
mime
);
if
([
'
zip
'
,
'
gz
'
,
'
rar
'
,
'
7z
'
].
indexOf
(
ext
)
===
-
1
)
{
throw
new
Error
(
'
Unsupported file type
'
);
}
}
import
Router
=
require
(
'
koa-router
'
);
const
ossStream
=
Client
(
new
OSS
({
...
...
@@ -36,10 +42,7 @@ const UploadImage = async (ctx: Context) => {
const
{
files
}
=
await
busboy
(
ctx
.
req
);
ctx
.
body
=
await
Promise
.
all
(
files
.
map
(
async
file
=>
{
const
ext
=
mime
.
extension
(
file
.
mime
);
if
([
'
png
'
,
'
jpg
'
,
'
jpeg
'
,
'
gif
'
,
'
webp
'
].
indexOf
(
ext
)
===
-
1
)
{
throw
new
Error
(
'
Unsupported image type
'
);
}
await
checkExtension
(
file
)
const
filename
=
`test/
${
uuid
.
v1
()}
`
;
...
...
@@ -86,23 +89,33 @@ export const UploadPackage = async (ctx: Context) => {
file
.
on
(
'
close
'
,
async
()
=>
{
pack
!
.
status
=
'
uploading
'
await
pack
!
.
save
()
resolve
(
pack
!
)
// 上传完, 打包
const
bundled
=
await
bundle
(
filename
)
Object
.
assign
(
pack
,
bundled
)
pack
!
.
status
=
'
uploaded
'
await
pack
!
.
save
()
try
{
pack
.
status
=
'
uploading
'
await
pack
.
save
()
resolve
(
pack
)
// 上传完, 打包
const
bundled
=
await
bundle
(
filename
)
Object
.
assign
(
pack
,
bundled
)
pack
.
status
=
'
uploaded
'
// 打包完,上传阿里云
await
mongodb
.
Packages
.
update
({
id
:
pack
.
id
},
{
$set
:
{
status
:
'
deprecated
'
}},
{
multi
:
true
})
await
pack
.
save
()
// 打包完,上传阿里云
}
catch
(
e
)
{
pack
.
status
=
'
failed
'
await
pack
.
save
()
}
})
file
.
on
(
'
error
'
,
async
(
error
)
=>
{
pack
!
.
status
=
'
failed
'
await
pack
!
.
save
()
pack
.
status
=
'
failed
'
await
pack
.
save
()
reject
(
error
)
})
...
...
@@ -136,13 +149,21 @@ const uploadPackageUrl = async (ctx: Context) => {
const
{
files
}
=
await
downloader
.
send
(
'
tellStatus
'
,
m
.
gid
)
const
[
file
]
=
files
// 打包
const
bundled
=
await
bundle
(
path
.
basename
(
file
.
path
)
)
try
{
await
checkExtension
(
file
)
// 打包完, 上传阿里云
pack
.
files
=
bundled
.
files
pack
.
status
=
'
uploaded
'
await
pack
.
save
()
// 打包
const
bundled
=
await
bundle
(
path
.
basename
(
file
.
path
))
// 打包完, 上传阿里云
pack
.
files
=
bundled
.
files
pack
.
status
=
'
uploaded
'
await
pack
.
save
()
}
catch
(
e
)
{
pack
.
status
=
'
failed
'
await
pack
.
save
()
}
}
downloader
.
onDownloadError
=
async
(
err
)
=>
{
...
...
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