// 如果不重新赋值,第二次create后,执行到这里会空指针

dev_unstable
hjm 6 years ago
parent a20e258185
commit 96cefd80dd

@ -61,13 +61,13 @@
"rc-select": "^8.0.12",
"rc-tree": "^1.7.11",
"rc-upload": "^2.5.1",
"react": "^16.8.0",
"react": "^16.9.0",
"react-beautiful-dnd": "^10.0.4",
"react-codemirror": "^1.0.0",
"react-codemirror2": "^6.0.0",
"react-content-loader": "^3.1.1",
"react-dev-utils": "^5.0.0",
"react-dom": "^16.8.0",
"react-dom": "^16.9.0",
"react-hot-loader": "^4.0.0",
"react-infinite-scroller": "^1.2.4",
"react-loadable": "^5.3.1",

@ -59,7 +59,9 @@ function doCreateUploader (options) {
// 如果 uploadInfo.videoId 不存在,调用 获取视频上传地址和凭证接口(https://help.aliyun.com/document_detail/55407.html)
const fileName = uploadInfo.file.name
// 如果不重新赋值第二次create后执行到这里会空指针
const _uploader = uploader;
if (!uploadInfo.videoId) {
var createUrl = `${_testHost}/users/${login}/video_auths.json?debug=true`
@ -72,14 +74,14 @@ function doCreateUploader (options) {
var uploadAuth = data.UploadAuth
var uploadAddress = data.UploadAddress
var videoId = data.VideoId
uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
_uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
options.addFileSuccess && options.addFileSuccess(uploadInfo)
}).catch((error) => {
// 删除当前出错的,并执行下一个任务
uploader.deleteFile(uploader._curIndex)
uploader.nextUpload()
_uploader.deleteFile(_uploader._curIndex)
_uploader.nextUpload()
console.log(error)
})
@ -101,12 +103,12 @@ function doCreateUploader (options) {
var uploadAuth = data.UploadAuth
var uploadAddress = data.UploadAddress
var videoId = data.VideoId
uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
_uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
options.addFileSuccess && options.addFileSuccess(uploadInfo)
}).catch((error) => {
uploader.deleteFile(uploader._curIndex)
uploader.nextUpload()
_uploader.deleteFile(_uploader._curIndex)
_uploader.nextUpload()
console.log(error)
})
}
@ -143,13 +145,15 @@ function doCreateUploader (options) {
// 然后调用 resumeUploadWithAuth 方法, 这里是测试接口, 所以我直接获取了 UploadAuth
$('#status').text('文件上传超时!')
var refreshUrl = `${_testHost}/users/${login}/video_auths.json?debug=true`
const _uploader = uploader;
axios.put(refreshUrl, {
video_id: uploadInfo.videoId,
}).then((response) => {
const data = response.data.data
var uploadAuth = data.UploadAuth
uploader.resumeUploadWithAuth(uploadAuth)
_uploader.resumeUploadWithAuth(uploadAuth)
}).catch((error) => {
console.log(error)
})

@ -19,7 +19,7 @@ const MAX_FILE_SIZE = 200
let noUploads = true
function VideoUploadList (props) {
const [videoes, setVideoes] = useState([]);
// const [videoes, setVideoes] = useState([]);
const [state, dispatch] = useReducer(reducer, initialState);
const theme = useContext(ThemeContext)
@ -27,6 +27,7 @@ function VideoUploadList (props) {
window.addEventListener("beforeunload", beforeunload);
return () => {
uploader = null;
window.removeEventListener("beforeunload", beforeunload);
}
}, [])
@ -80,6 +81,7 @@ function VideoUploadList (props) {
getUploader(username,
// Object.assign(uploaderOptions,
{
create: !uploader,
addFileSuccess: (uploadInfo) => {
const file = uploadInfo.file
console.log('addFileSuccess', uploadInfo)
@ -96,22 +98,22 @@ function VideoUploadList (props) {
// setVideoes(newVideoes)
// files.push(file)
clearInput()
dispatch({type: 'addVideo', uploadInfo})
},
onUploadProgress: (uploadInfo, totalSize, progress) => {
var progressPercent = Math.ceil(progress * 100)
let _index = -1;
videoes.some((item, index) => {
// addFileSuccess的时候没有fileHash
// if (uploadInfo.fileHash == item.fileHash) {
if (uploadInfo.file.name == item.name) {
_index = index
return true;
}
})
// let _index = -1;
// videoes.some((item, index) => {
// // addFileSuccess的时候没有fileHash
// // if (uploadInfo.fileHash == item.fileHash) {
// if (uploadInfo.file.name == item.name) {
// _index = index
// return true;
// }
// })
// TODO 这里不用reducer会出现state被重置的问题

Loading…
Cancel
Save