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
f319ba21
Commit
f319ba21
authored
Apr 26, 2017
by
nano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oss upload
parent
29f1a5a8
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
163 deletions
+121
-163
.idea/workspace.xml
.idea/workspace.xml
+92
-153
Dockerfile
Dockerfile
+4
-0
package/main.ts
package/main.ts
+1
-0
src/routes/upload.ts
src/routes/upload.ts
+7
-10
src/utils.ts
src/utils.ts
+17
-0
No files found.
.idea/workspace.xml
View file @
f319ba21
This diff is collapsed.
Click to expand it.
Dockerfile
View file @
f319ba21
...
...
@@ -2,6 +2,10 @@ FROM node
RUN
apt-get update
RUN
apt-get
install
aria2
-y
RUN
apt-get curl
RUN
curl
--location
--retry
5
--output
ossutil
'https://github.com/mycard/ossutil/releases/download/1.0.0.Beta2/ossutil
RUN
chmod
+x ossutil
&&
mv
ossutil /usr/local/bin/ossutil
RUN
mkdir
-p
/usr/src/app
WORKDIR
/usr/src/app
...
...
package/main.ts
View file @
f319ba21
...
...
@@ -80,6 +80,7 @@ export async function bundle(...args) {
await
fs
.
renameAsync
(
filePath
,
fullPath
);
return
{
distPath
:
dist_path
,
files
:
Array
.
from
(
files
.
values
()),
archives
:
Array
.
from
(
archives
.
values
()),
fullSize
,
...
...
src/routes/upload.ts
View file @
f319ba21
...
...
@@ -7,18 +7,12 @@ import * as Client from 'aliyun-oss-upload-stream';
import
*
as
fs
from
'
fs-extra-promise
'
;
import
*
as
path
from
'
path
'
;
import
*
as
Aria2
from
'
aria2
'
;
import
Router
=
require
(
'
koa-router
'
);
import
{
bundle
}
from
'
../../package/main
'
;
import
{
mongodb
}
from
'
../models/Iridium
'
;
import
{
toObjectID
}
from
'
iridium
'
;
import
config
from
'
../../config
'
;
// const Aria2Options = {
// host: 'localhost',
// port: 6800,
// secure: false,
// secret: '',
// path: path.join(__dirname, '../../test/upload')
// }
import
{
UploadOSS
}
from
'
../utils
'
const
checkPackage
=
async
(
file
)
=>
{
if
([
'
application/zip
'
,
'
application/gz
'
,
'
application/rar
'
,
'
application/7z
'
,
'
application/x-gzip
'
].
indexOf
(
file
.
mime
)
===
-
1
)
{
...
...
@@ -35,13 +29,13 @@ const checkImage = async (file) => {
};
import
Router
=
require
(
'
koa-router
'
);
const
ossStream
=
Client
(
new
OSS
({
accessKeyId
:
process
.
env
[
'
OSS_ACCESS_ID
'
],
secretAccessKey
:
process
.
env
[
'
OSS_ACCESS_KEY
'
],
endpoint
:
process
.
env
[
'
OSS_ENDPOINT
'
],
apiVersion
:
'
2013-10-15
'
}));
const
router
=
new
Router
();
const
UploadImage
=
async
(
ctx
:
Context
)
=>
{
...
...
@@ -105,13 +99,15 @@ export const UploadPackage = async (ctx: Context) => {
// 上传完, 打包
const
bundled
=
await
bundle
(
filename
);
// 打包完,上传阿里云
await
UploadOSS
(
bundled
.
distPath
)
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
'
;
...
...
@@ -166,6 +162,7 @@ const uploadPackageUrl = async (ctx: Context) => {
const
bundled
=
await
bundle
(
path
.
basename
(
file
.
path
));
// 打包完, 上传阿里云
await
UploadOSS
(
bundled
.
distPath
)
Object
.
assign
(
pack
,
bundled
);
pack
!
.
status
=
'
uploaded
'
;
...
...
src/utils.ts
View file @
f319ba21
import
{
URL
}
from
'
url
'
;
import
*
as
child_process
from
'
child_process
'
;
export
const
handleImg
=
(
img
)
=>
{
if
(
img
)
{
...
...
@@ -17,3 +18,19 @@ export const handleImg = (img) => {
export
function
renderChecksum
(
files
:
{
path
:
string
,
hash
?:
string
}[])
{
return
files
.
map
(({
path
,
hash
})
=>
`
${
hash
||
''
}
${
path
}
`
).
join
(
'
\n
'
);
}
export
function
UploadOSS
(
dist
:
string
):
Promise
<
void
>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
let
child
=
child_process
.
spawn
(
'
ossutil
'
,
[
'
cp
'
,
dist
,
'
oss://mycard/test-release
'
],
{
stdio
:
'
inherit
'
});
child
.
on
(
'
exit
'
,
(
code
)
=>
{
if
(
code
==
0
)
{
resolve
();
}
else
{
reject
(
code
);
}
});
child
.
on
(
'
error
'
,
(
error
)
=>
{
reject
(
error
);
});
});
}
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