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
24bbadbe
Commit
24bbadbe
authored
Apr 21, 2017
by
nano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix checksum
parent
ca8fddda
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
197 additions
and
138 deletions
+197
-138
.idea/workspace.xml
.idea/workspace.xml
+164
-109
Dockerfile
Dockerfile
+0
-2
package/main.ts
package/main.ts
+7
-4
src/models/Package.ts
src/models/Package.ts
+2
-5
src/routes/package.ts
src/routes/package.ts
+16
-10
src/routes/upload.ts
src/routes/upload.ts
+4
-8
src/utils.ts
src/utils.ts
+4
-0
No files found.
.idea/workspace.xml
View file @
24bbadbe
This diff is collapsed.
Click to expand it.
Dockerfile
View file @
24bbadbe
FROM
node:alpine
MAINTAINER
nanoo
RUN
mkdir
-p
/usr/src/app
WORKDIR
/usr/src/app
...
...
package/main.ts
View file @
24bbadbe
...
...
@@ -39,11 +39,12 @@ export async function bundle(...args) {
await
crawlPath
(
package_path
,
{
relative
:
true
,
onFile
:
async
(
file
)
=>
{
let
file_hash
=
await
caculateSHA256
(
file
)
files
.
set
(
file
,
{
path
:
file
,
path
:
path
.
relative
(
package_path
,
file
)
,
hash
:
file_hash
,
size
:
(
await
fs
.
statAsync
(
file
)).
size
})
...
...
@@ -55,14 +56,17 @@ export async function bundle(...args) {
let
sand_hash
=
await
caculateSHA256
(
sand_file
)
archives
.
set
(
sand_file
,
{
path
:
sand_file
,
path
:
path
.
relative
(
sand_path
,
sand_file
)
,
hash
:
sand_hash
,
size
:
(
await
fs
.
statAsync
(
sand_file
)).
size
})
await
fs
.
renameAsync
(
sand_file
,
path
.
join
(
path
.
dirname
(
sand_file
),
`
${
sand_hash
}
.tar.gz`
))
},
onDir
:
async
(
files
,
_path
,
depth
)
=>
{
onDir
:
async
(
_files
,
_path
,
depth
)
=>
{
files
.
set
(
_path
,
{
path
:
path
.
relative
(
package_path
,
_path
),
})
},
})
...
...
@@ -80,7 +84,6 @@ export async function bundle(...args) {
return
{
files
:
Array
.
from
(
files
.
values
()),
archives
:
Array
.
from
(
archives
.
values
()),
fullPath
,
fullSize
,
fullHash
}
...
...
src/models/Package.ts
View file @
24bbadbe
...
...
@@ -12,8 +12,8 @@ export interface Action {
export
interface
File
{
path
:
string
;
size
:
number
;
hash
:
string
;
size
?
:
number
;
hash
?
:
string
;
}
export
interface
Archive
{
...
...
@@ -28,7 +28,6 @@ export interface Package {
appId
:
string
;
fullSize
:
number
;
fullHash
:
string
;
fullPath
:
string
;
version
:
string
;
status
:
string
;
type
:
string
;
...
...
@@ -52,8 +51,6 @@ export class PackageSchema extends Instance<Package, PackageSchema> implements P
fullSize
:
number
;
@
Property
(
String
,
false
)
fullHash
:
string
;
@
Property
(
String
,
false
)
fullPath
:
string
;
@
Property
(
String
,
true
)
type
:
string
;
@
Property
(
String
,
true
)
...
...
src/routes/package.ts
View file @
24bbadbe
...
...
@@ -4,33 +4,39 @@ import {mongodb} from '../models/iridium'
import
{
Context
}
from
"
koa
"
;
import
config
from
'
../../config
'
import
{
Archive
,
Package
}
from
"
../models/Package
"
;
import
{
renderChecksum
}
from
"
../utils
"
;
const
router
=
new
Router
();
router
.
get
(
'
/v2/packages
'
,
async
(
ctx
:
Context
,
next
)
=>
{
if
(
!
ctx
.
request
.
query
.
appId
)
{
ctx
.
throw
(
400
,
"
appId must be required!
"
)
}
let
packs
=
await
mongodb
.
Packages
.
find
({
appId
:
ctx
.
params
.
id
,
status
:
'
uploaded
'
}
)
let
packs
=
await
mongodb
.
Packages
.
find
({
appId
:
ctx
.
request
.
query
.
appId
,
status
:
'
uploaded
'
}).
toArray
(
)
ctx
.
body
=
{
[
ctx
.
request
.
query
.
appId
]:
packs
}
})
router
.
get
(
'
/v2/package/:id
'
,
async
(
ctx
:
Context
,
next
)
=>
{
//TODO
router
.
get
(
'
/v2/package/:id/checksum
'
,
async
(
ctx
:
Context
,
next
)
=>
{
let
pack
=
await
mongodb
.
Packages
.
findOne
({
id
:
ctx
.
params
.
id
,
status
:
'
uploaded
'
})
if
(
!
pack
)
{
return
ctx
.
throw
(
400
,
'
pack error
'
)
}
ctx
.
body
=
renderChecksum
(
pack
.
files
)
})
router
.
get
(
'
/v2/package/:id/meta
'
,
async
(
ctx
:
Context
,
next
)
=>
{
let
{
fullHash
,
fullSize
,
fullPath
}
=
await
mongodb
.
Packages
.
findOne
({
id
:
ctx
.
params
.
id
,
status
:
'
uploaded
'
})
||
{}
if
(
!
fullHash
||
!
fullSize
||
!
fullPath
)
{
ctx
.
throw
(
400
,
'
pack error
'
)
let
pack
=
await
mongodb
.
Packages
.
findOne
({
id
:
ctx
.
params
.
id
,
status
:
'
uploaded
'
})
if
(
!
pack
)
{
return
ctx
.
throw
(
400
,
'
pack error
'
)
}
await
ctx
[
'
render
'
](
'
update
'
,
{
files
:
{
name
:
fullPath
,
size
:
fullSize
,
hash
:
fullHash
name
:
pack
.
id
,
size
:
pack
.
fullSize
,
hash
:
pack
.
fullHash
}})
})
...
...
@@ -69,7 +75,7 @@ router.post('/v2/package/:id/update', async (ctx: Context, next) => {
if
(
sandSize
<=
fullSize
)
{
files
=
[{
path
:
pack
.
fullPath
,
path
:
pack
.
id
,
size
:
pack
.
fullSize
,
hash
:
pack
.
fullHash
}]
...
...
src/routes/upload.ts
View file @
24bbadbe
...
...
@@ -21,8 +21,9 @@ import config from '../../config'
// }
const
checkPackage
=
async
(
file
)
=>
{
const
ext
=
mime
.
extension
(
file
.
mime
);
if
([
'
zip
'
,
'
gz
'
,
'
rar
'
,
'
7z
'
].
indexOf
(
ext
)
===
-
1
)
{
// const ext = mime.extension(file.mime);
if
([
'
zip
'
,
'
gz
'
,
'
rar
'
,
'
7z
'
,
'
application/x-gzip
'
].
indexOf
(
file
.
mime
)
===
-
1
)
{
throw
new
Error
(
'
Unsupported file type
'
);
}
}
...
...
@@ -77,10 +78,7 @@ export const UploadPackage = 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
([
'
zip
'
,
'
gz
'
,
'
rar
'
,
'
7z
'
].
indexOf
(
ext
)
===
-
1
)
{
throw
new
Error
(
'
Unsupported file type
'
);
}
await
checkPackage
(
file
)
const
filename
=
uuid
.
v1
()
...
...
@@ -97,8 +95,6 @@ export const UploadPackage = async (ctx: Context) => {
file
.
on
(
'
close
'
,
async
()
=>
{
try
{
pack
.
status
=
'
uploading
'
await
pack
.
save
()
...
...
src/utils.ts
View file @
24bbadbe
...
...
@@ -12,4 +12,8 @@ export const handleImg = (img) => {
}
else
{
return
'
https://cdn01.moecube.com/accounts/default_avatar.jpg
'
;
}
}
export
function
renderChecksum
(
files
:
{
path
:
string
,
hash
?:
string
}[])
{
return
files
.
map
(({
path
,
hash
})
=>
`
${
hash
||
''
}
${
path
}
`
).
join
(
'
\n
'
);
}
\ No newline at end of file
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