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
a513cfe6
Commit
a513cfe6
authored
Apr 20, 2017
by
nano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sso login
parent
ad75b565
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
85 deletions
+120
-85
.idea/workspace.xml
.idea/workspace.xml
+88
-73
src/routes/app.ts
src/routes/app.ts
+20
-8
src/routes/upload.ts
src/routes/upload.ts
+12
-4
No files found.
.idea/workspace.xml
View file @
a513cfe6
This diff is collapsed.
Click to expand it.
src/routes/app.ts
View file @
a513cfe6
import
Router
=
require
(
'
koa-router
'
);
import
{
toObjectID
}
from
'
iridium
'
import
{
mongodb
}
from
'
../models/iridium
'
import
{
App
,
AppSchema
}
from
"
../models/App
"
;
import
*
as
vercomp
from
'
vercomp
'
import
{
Context
}
from
"
koa
"
;
import
{
Package
}
from
"
../models/Package
"
;
const
router
=
new
Router
();
// router.get('/apps', async (ctx: Context, next) => {
...
...
@@ -24,20 +21,35 @@ const router = new Router();
// });
router
.
get
(
'
/v1/apps
'
,
async
(
ctx
:
Context
,
next
)
=>
{
ctx
.
body
=
await
mongodb
.
Apps
.
find
({}).
toArray
()
let
payload
=
ctx
.
request
.
query
if
((
!
payload
.
author
&&
!
payload
.
admin
))
{
ctx
.
throw
(
400
,
'
params error
'
)
}
let
apps
=
{}
if
(
payload
.
admin
==
'
true
'
)
{
apps
=
await
mongodb
.
Apps
.
find
({}).
toArray
()
}
else
{
apps
=
await
mongodb
.
Apps
.
find
({
author
:
payload
.
author
}).
toArray
()
}
ctx
.
body
=
apps
})
router
.
post
(
'
/v1/app/:id
'
,
async
(
ctx
:
Context
,
next
)
=>
{
if
(
!
ctx
.
request
.
body
.
id
||
ctx
.
params
.
id
!==
ctx
.
request
.
body
.
id
)
{
let
payload
=
ctx
.
request
.
body
if
(
!
payload
.
id
)
{
ctx
.
throw
(
400
,
'
params error
'
)
}
if
(
ctx
.
params
.
id
!==
payload
.
id
)
{
ctx
.
throw
(
400
,
"
App is not same
"
)
}
let
exists
=
await
mongodb
.
Apps
.
findOne
({
id
:
ctx
.
request
.
body
.
id
});
let
exists
=
await
mongodb
.
Apps
.
findOne
({
id
:
payload
.
id
});
if
(
exists
)
{
ctx
.
throw
(
400
,
"
App i
d i
s exists
"
)
ctx
.
throw
(
400
,
"
App is exists
"
)
}
try
{
ctx
.
body
=
await
mongodb
.
Apps
.
insert
(
ctx
.
request
.
body
)
ctx
.
body
=
await
mongodb
.
Apps
.
insert
(
payload
)
}
catch
(
e
)
{
ctx
.
throw
(
400
,
e
)
}
...
...
src/routes/upload.ts
View file @
a513cfe6
...
...
@@ -20,13 +20,21 @@ import config from '../../config'
// path: path.join(__dirname, '../../test/upload')
// }
const
check
Extension
=
async
(
file
)
=>
{
const
check
Package
=
async
(
file
)
=>
{
const
ext
=
mime
.
extension
(
file
.
mime
);
if
([
'
zip
'
,
'
gz
'
,
'
rar
'
,
'
7z
'
].
indexOf
(
ext
)
===
-
1
)
{
throw
new
Error
(
'
Unsupported file type
'
);
}
}
const
checkImage
=
async
(
file
)
=>
{
const
ext
=
mime
.
extension
(
file
.
mime
);
if
([
'
png
'
,
'
jpg
'
,
'
jpeg
'
,
'
gif
'
,
'
webp
'
].
indexOf
(
ext
)
===
-
1
)
{
throw
new
Error
(
'
Unsupported file type
'
);
}
}
import
Router
=
require
(
'
koa-router
'
);
const
ossStream
=
Client
(
new
OSS
({
accessKeyId
:
process
.
env
[
"
OSS_ACCESS_ID
"
],
...
...
@@ -42,7 +50,7 @@ const UploadImage = async (ctx: Context) => {
const
{
files
}
=
await
busboy
(
ctx
.
req
);
ctx
.
body
=
await
Promise
.
all
(
files
.
map
(
async
file
=>
{
await
check
Extension
(
file
)
await
check
Image
(
file
)
const
filename
=
`test/
${
uuid
.
v1
()}
`
;
...
...
@@ -112,7 +120,7 @@ export const UploadPackage = async (ctx: Context) => {
await
pack
.
save
()
}
})
file
.
on
(
'
error
'
,
async
(
error
)
=>
{
pack
.
status
=
'
failed
'
await
pack
.
save
()
...
...
@@ -150,7 +158,7 @@ const uploadPackageUrl = async (ctx: Context) => {
const
[
file
]
=
files
try
{
await
check
Extension
(
file
)
await
check
Package
(
file
)
// 打包
const
bundled
=
await
bundle
(
path
.
basename
(
file
.
path
))
...
...
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