Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cos-uploader
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewenhao
cos-uploader
Commits
a25f17a2
Commit
a25f17a2
authored
May 10, 2021
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: production config
parent
63dcf18a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
11 deletions
+24
-11
.gitignore
.gitignore
+2
-0
config.js
config.js
+6
-0
index.js
index.js
+16
-11
No files found.
.gitignore
View file @
a25f17a2
...
@@ -19,4 +19,5 @@ _staging
...
@@ -19,4 +19,5 @@ _staging
_production
_production
_testing
_testing
/test.js
/test.js
/product-config.js
/mock/static
/mock/static
\ No newline at end of file
config.js
0 → 100644
View file @
a25f17a2
module
.
exports
=
{
SecretId
:
'AKIDmMhgQGAJbkjZ8bfpa5LNAoJfuvkJJuwh'
,
SecretKey
:
'gCTs8h8btRo00mIcgYBZh16zd7YpvqRn'
,
Bucket
:
'test-1257124244'
}
\ No newline at end of file
index.js
View file @
a25f17a2
...
@@ -7,28 +7,31 @@ const rawArgv = process.argv.slice(2);
...
@@ -7,28 +7,31 @@ const rawArgv = process.argv.slice(2);
const
args
=
require
(
"minimist"
)(
rawArgv
);
const
args
=
require
(
"minimist"
)(
rawArgv
);
const
getContentType
=
require
(
'./utils'
);
const
getContentType
=
require
(
'./utils'
);
const
{
f
=
'reward-day'
,
s
=
'
\
0_None'
}
=
args
;
const
{
f
:
folderName
=
'reward-day'
,
s
:
subFolder
=
'
\
0_None'
,
env
=
'development'
}
=
args
;
const
isProduction
=
env
===
'production'
;
const
config
=
isProduction
?
require
(
'./product-config'
)
:
require
(
'./config'
);
const
cos
=
new
COS
({
const
cos
=
new
COS
({
SecretId
:
'AKIDmMhgQGAJbkjZ8bfpa5LNAoJfuvkJJuwh'
,
SecretId
:
config
.
SecretId
,
SecretKey
:
'gCTs8h8btRo00mIcgYBZh16zd7YpvqRn'
SecretKey
:
config
.
SecretKey
});
});
const
folderList
=
fastglob
const
folderList
=
fastglob
.
sync
(
'**'
,
{
onlyFiles
:
false
,
deep
:
1
,
cwd
:
`./
${
f
}
`
})
.
sync
(
'**'
,
{
onlyFiles
:
false
,
deep
:
1
,
cwd
:
`./
${
f
olderName
}
`
})
.
filter
(
item
=>
{
.
filter
(
item
=>
{
return
s
===
'*'
||
item
===
s
return
s
ubFolder
===
'*'
||
item
===
subFolder
});
});
if
(
folderList
.
length
<
1
)
{
if
(
folderList
.
length
<
1
)
{
console
.
log
(
'empty folder'
,
f
);
console
.
log
(
'empty folder'
,
f
older
);
}
}
const
list
=
folderList
const
list
=
folderList
.
map
(
item
=>
{
.
map
(
item
=>
{
const
subFolderPath
=
`./
${
f
}
/
${
item
}
`
const
subFolderPath
=
`./
${
f
olderName
}
/
${
item
}
`
const
subList
=
fastglob
.
sync
(
`**`
,
{
onlyFiles
:
true
,
deep
:
1
,
cwd
:
subFolderPath
})
const
subList
=
fastglob
.
sync
(
`**`
,
{
onlyFiles
:
true
,
deep
:
1
,
cwd
:
subFolderPath
})
const
outputFileName
=
`./dist/
${
f
}
_
${
item
}
.js`
;
const
outputFileName
=
`./dist/
${
f
olderName
}
_
${
item
}
.js`
;
return
{
return
{
folderPath
:
subFolderPath
,
folderPath
:
subFolderPath
,
outputFileName
,
outputFileName
,
...
@@ -71,7 +74,7 @@ function uploadFile ({ fileName, filePath, relativePath }) {
...
@@ -71,7 +74,7 @@ function uploadFile ({ fileName, filePath, relativePath }) {
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
dimensions
=
sizeOf
(
filePath
);
const
dimensions
=
sizeOf
(
filePath
);
cos
.
sliceUploadFile
({
cos
.
sliceUploadFile
({
Bucket
:
'test-1257124244'
,
// Bucket 格式:test-1250000000
Bucket
:
config
.
Bucket
,
//
'test-1257124244', // Bucket 格式:test-1250000000
Region
:
'ap-chengdu'
,
Region
:
'ap-chengdu'
,
Key
:
getFileName
(
relativePath
,
filePath
),
Key
:
getFileName
(
relativePath
,
filePath
),
ContentType
:
getContentType
(
filePath
),
ContentType
:
getContentType
(
filePath
),
...
@@ -86,7 +89,9 @@ function uploadFile ({ fileName, filePath, relativePath }) {
...
@@ -86,7 +89,9 @@ function uploadFile ({ fileName, filePath, relativePath }) {
width
:
dimensions
.
width
,
width
:
dimensions
.
width
,
height
:
dimensions
.
height
,
height
:
dimensions
.
height
,
// originPath,
// originPath,
url
:
`https://
${
data
.
Location
}
`
url
:
isProduction
?
`https://
${
data
.
Location
}
`
.
replace
(
`
${
config
.
Bucket
}
.cos.ap-chengdu.myqcloud.com`
,
'cdn.jkwljy.com'
)
:
`https://
${
data
.
Location
}
`
})
})
}
}
});
});
...
@@ -102,7 +107,7 @@ function getFileName(filePath, absolutPath) {
...
@@ -102,7 +107,7 @@ function getFileName(filePath, absolutPath) {
.
update
(
fs
.
readFileSync
(
absolutPath
,
{
encoding
:
'binary'
}))
.
update
(
fs
.
readFileSync
(
absolutPath
,
{
encoding
:
'binary'
}))
.
digest
(
'base64'
)
.
digest
(
'base64'
)
.
replace
(
/
\.
|
\-
|
\=
|
\+
|
\/
/g
,
'_'
)
.
replace
(
/
\.
|
\-
|
\=
|
\+
|
\/
/g
,
'_'
)
return
`
${
str
.
substring
(
0
,
4
)}
/
${
str
.
substring
(
4
)}
`
return
`
/
${
folderName
}
/
${
str
}
`
;
}
}
// // 分片上传
// // 分片上传
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