Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
learn-online-pc
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
learn-online-pc
Commits
78c7476b
提交
78c7476b
authored
4月 09, 2020
作者:
zyx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
64416a4d
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
55 行增加
和
57 行删除
+55
-57
.config.dev.js
client/.config.dev.js
+1
-7
.config.pro.js
client/.config.pro.js
+1
-7
.config.test.js
client/.config.test.js
+1
-7
uploadAliyunCDN.js
client/build/uploadAliyunCDN.js
+52
-36
没有找到文件。
client/.config.dev.js
浏览文件 @
78c7476b
...
...
@@ -15,12 +15,6 @@ module.exports = {
}
},
ProvidePlugin
:
{
CKEDITOR
:
'window.CKEDITOR'
,
VideoJs
:
'window.swfobject'
,
Base64
:
'window.Base64'
,
Md5
:
'window.md5'
,
$
:
'window.$'
,
Aliplayer
:
'window.Aliplayer'
,
AliPlayerComponent
:
'window.AliPlayerComponent'
}
}
client/.config.pro.js
浏览文件 @
78c7476b
...
...
@@ -15,12 +15,6 @@ module.exports = {
}
},
ProvidePlugin
:
{
CKEDITOR
:
'window.CKEDITOR'
,
VideoJs
:
'window.swfobject'
,
Base64
:
'window.Base64'
,
Md5
:
'window.md5'
,
$
:
'window.$'
,
Aliplayer
:
'window.Aliplayer'
,
AliPlayerComponent
:
'window.AliPlayerComponent'
}
}
client/.config.test.js
浏览文件 @
78c7476b
...
...
@@ -16,12 +16,6 @@ module.exports = {
}
},
ProvidePlugin
:
{
CKEDITOR
:
'window.CKEDITOR'
,
VideoJs
:
'window.swfobject'
,
Base64
:
'window.Base64'
,
Md5
:
'window.md5'
,
$
:
'window.$'
,
Aliplayer
:
'window.Aliplayer'
,
AliPlayerComponent
:
'window.AliPlayerComponent'
}
}
client/build/uploadAliyunCDN.js
浏览文件 @
78c7476b
/**
* 本文件执行,需要 node -v >= v8.11.3
* 原因:其中使用很多es6新特性,需要高版本才能直接识别并运行
* 放服务器上 上传慢,而且经常报错(没找到原因),最后改为打包完成后自动上传不在服务器上deploy时再上传了
*/
const
fs
=
require
(
'fs'
)
const
path
=
require
(
'path'
)
// 这个包本身也是用es6语法写的,低版本node编译解析不了
const
OSS
=
require
(
'ali-oss'
)
const
conf
=
require
(
'./config'
)
...
...
@@ -13,53 +18,64 @@ const client = new OSS({
bucket
:
'zws-imgs-pub'
})
let
DIR_PATH
=
path
.
join
(
__dirname
,
'../'
+
conf
.
DesDir
)
let
PREFIX_PATH
=
conf
.
CDN_DIR
/* 定位到对应 public目录下 */
const
DIR_PATH
=
path
.
join
(
__dirname
,
'../'
+
conf
.
DesDir
)
/* 上传对应目录 */
const
PREFIX_PATH
=
conf
.
CDN_DIR
/* 是否上传static目录 */
const
isUploadStatic
=
conf
.
isUploadStatic
let
count
=
1
let
fileCount
=
1
/**
* 调用接口,单个文件上传
* @param {string} dirPath 传入对应需要遍历的路径
* @param {function} callback 加入一个回调方法,执行文件上传
*/
async
function
uploadFile
(
prefixPath
,
dirFileName
)
{
try
{
const
upFilePath
=
prefixPath
.
replace
(
new
RegExp
(
DIR_PATH
,
'gi'
),
''
)
+
path
.
basename
(
dirFileName
)
let
result
=
await
client
.
put
(
prefixPath
+
path
.
basename
(
dirFileName
),
dirFileName
)
if
(
result
.
res
.
status
===
200
)
{
console
.
log
(
'第'
+
(
count
++
)
+
'个文件:'
+
path
.
basename
(
dirFileName
)
+
',已上传。'
)
console
.
log
(
'第'
+
fileCount
++
+
'个文件,已上传:'
+
conf
.
CDN_BASE
+
upFilePath
)
return
{
status
:
200
}
}
}
catch
(
err
)
{
console
.
log
(
err
)
let
text
=
await
function
()
{
return
1
}
console
.
log
(
text
)
console
.
log
(
'第'
+
fileCount
++
+
'个文件,上传失败:'
+
conf
.
CDN_BASE
+
upFilePath
)
return
{
status
:
500
,
err
:
err
}
}
}
function
findfiles
(
dirPath
,
callback
)
{
fs
.
readdir
(
dirPath
,
function
(
err
,
files
)
{
if
(
err
)
{
console
.
log
(
err
)
}
else
{
files
.
forEach
(
function
(
filename
)
{
var
filedir
=
path
.
join
(
dirPath
,
filename
)
fs
.
stat
(
filedir
,
function
(
error
,
stats
)
{
if
(
error
)
{
console
.
log
(
'获取文件stats失败'
)
}
else
{
var
isFile
=
stats
.
isFile
()
var
isDir
=
stats
.
isDirectory
()
if
(
isFile
&&
typeof
callback
===
'function'
)
{
callback
(
filedir
)
}
if
(
isDir
&&
(
conf
.
isUploadStatic
?
true
:
filename
!==
'static'
))
{
var
morePath
=
filedir
.
replace
(
new
RegExp
(
DIR_PATH
+
'/'
,
'g'
),
''
)
+
'/'
findfiles
(
filedir
,
function
(
filedir
)
{
uploadFile
(
PREFIX_PATH
+
morePath
,
filedir
)
})
}
}
})
/**
* 循环遍历文件,准备上传文件
* 原生js 遍历方法
* @param {string} dirPath 传入对应需要遍历的路径
* @param {function} callback 加入一个回调方法,执行文件上传
*/
function
uploadfiles
(
dirPath
,
callback
)
{
/* 根据文件路径读取文件 */
const
files
=
fs
.
readdirSync
(
dirPath
)
files
.
forEach
(
function
(
filename
,
i
)
{
const
filedir
=
path
.
join
(
dirPath
,
filename
)
const
info
=
fs
.
statSync
(
filedir
)
if
(
info
.
isDirectory
())
{
/* 确定是否上传 */
if
(
!
(
isUploadStatic
?
true
:
filename
!==
'static'
))
{
return
}
/* 得到对应目录结构 */
const
morePath
=
filedir
.
replace
(
new
RegExp
(
DIR_PATH
,
'gi'
),
''
)
+
'/'
/* 递归,如果是文件夹,就继续遍历该文件夹下面的文件 */
uploadfiles
(
filedir
,
function
(
filedir
)
{
uploadFile
(
path
.
join
(
PREFIX_PATH
,
morePath
),
filedir
)
})
}
else
{
if
(
typeof
callback
===
'function'
)
{
callback
(
filedir
)
}
else
{
uploadFile
(
PREFIX_PATH
,
filedir
)
}
}
})
return
true
}
findfiles
(
DIR_PATH
,
function
(
filedir
)
{
uploadFile
(
PREFIX_PATH
,
filedir
)
})
/* 批量上传文件 */
uploadfiles
(
DIR_PATH
,
null
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论