删除当前出错的,并执行下一个任务

dev_hjm
hjm 6 years ago
parent 702b471d0b
commit d36da7c2c9

@ -4,7 +4,7 @@ import axios from 'axios'
let _url_origin = getUrl2()
let _path = _isDev ? 'public' : 'build'
let _testHost = 'http://192.168.2.63:3001/api' ; // '' ;
let _testHost = '' ; // 'http://192.168.2.63:3001/api' ; // '' ;
let login = 'innov'
let uploader;
@ -44,7 +44,6 @@ function doCreateUploader (options) {
userId: $('#userId').val() || 1202060945918292, // 1303984639806000,
// 添加文件成功
addFileSuccess: function (uploadInfo) {
options.addFileSuccess && options.addFileSuccess(uploadInfo)
console.log("addFileSuccess: " + uploadInfo.file.name)
@ -74,7 +73,13 @@ function doCreateUploader (options) {
var uploadAddress = data.UploadAddress
var videoId = data.VideoId
uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
options.addFileSuccess && options.addFileSuccess(uploadInfo)
}).catch((error) => {
// 删除当前出错的,并执行下一个任务
uploader.deleteFile(uploader._curIndex)
uploader.nextUpload()
console.log(error)
})
@ -88,12 +93,20 @@ function doCreateUploader (options) {
axios.put(refreshUrl, {
video_id: uploadInfo.videoId,
}).then((response) => {
if (response.data.status == -1) {
options.onUploadError && options.onUploadError(uploadInfo)
return;
}
const data = response.data.data
var uploadAuth = data.UploadAuth
var uploadAddress = data.UploadAddress
var videoId = data.VideoId
uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
options.addFileSuccess && options.addFileSuccess(uploadInfo)
}).catch((error) => {
uploader.deleteFile(uploader._curIndex)
uploader.nextUpload()
console.log(error)
})
}

@ -4,9 +4,42 @@ import {Link} from 'react-router-dom';
import { getUrl2, isDev } from 'educoder'
import axios from 'axios'
const PAGE_SIZE = 12
function InfoVideo (props) {
const username = props.match.params.username
function fetchVideoes() {
const fetchUrl = `/users/${username}/videos.json`
axios.get(fetchUrl, {
params: {
per_page: PAGE_SIZE
}
})
.then((response) => {
}).catch(() => {
})
}
function fetchReviewVideoes() {
const fetchUrl = `/users/${username}/videos/review.json`
axios.get(fetchUrl, {
params: {
per_page: 200
}
})
.then((response) => {
}).catch(() => {
})
}
useEffect(() => {
fetchVideoes()
fetchReviewVideoes()
}, [])
return (
<div>123

@ -14,6 +14,10 @@ export function reducer(state, action) {
videoId: uploadInfo.videoId, // "719b82c875c34ac39f94feb145d25ad2"
loaded: 0
}]};
case 'removeVideo':
return {
videoes: update(state.videoes, {$splice: [[action.index, 1]]})
}
case 'updateProgress':
let _index = -1;
state.videoes.some((item, index) => {
@ -26,6 +30,7 @@ export function reducer(state, action) {
})
return {videoes: update(state.videoes, {[_index]: {
loaded: {$set: action.progressPercent},
videoId: {$set: action.uploadInfo.videoId},
fileHash: {$set: action.uploadInfo.fileHash}
}})};
default:

@ -22,7 +22,7 @@ function VideoUpload (props) {
const [title, setTitle] = useState('')
const username = props.match.params.username
function titleChange () {
function titleChange (e) {
setTitle(e.target.value)
}
return (
@ -32,7 +32,7 @@ function VideoUpload (props) {
<Progress percent={loaded}
status={state == "Uploading" ? "active" : ''}
/>
<ActionBtn className="cancelUpload" onClick={() => cancelUpload(index)}>取消上传</ActionBtn>
<ActionBtn className="cancelUpload" onClick={() => cancelUpload(index, loaded == '100' )}>{loaded == '100' ? "删除" : "取消上传"}</ActionBtn>
</div>
<Input placeholder={`标题支持最多${MAX_LENGTH}个字符`} onInput={titleChange} maxLength={MAX_LENGTH} suffix ={

@ -1,6 +1,6 @@
import React, { useState, useEffect, useReducer, memo } from 'react';
import { getUrl2, isDev, CBreadcrumb } from 'educoder'
import { getUrl2, isDev, CBreadcrumb, ActionBtn } from 'educoder'
import axios from 'axios'
import VideoUpload from './VideoUpload'
@ -15,6 +15,7 @@ function VideoUploadList (props) {
const [videoes, setVideoes] = useState([]);
const [state, dispatch] = useReducer(reducer, initialState);
const username = props.match.params.username
const uploaderOptions = {
@ -49,7 +50,7 @@ function VideoUploadList (props) {
// }]
// setVideoes(newVideoes)
files.push(file)
// files.push(file)
dispatch({type: 'addVideo', uploadInfo})
},
@ -98,6 +99,9 @@ function VideoUploadList (props) {
onUploadSucceed: (uploadInfo) => {
console.log('onUploadSucceed', uploadInfo)
},
onUploadError: (uploadInfo) => {
},
// 可能需要等lib加载完毕才能执行
gotUploader: (_uploader) => {
@ -116,15 +120,44 @@ function VideoUploadList (props) {
}
}
// uploader.deleteFile(index);
function cancelUpload(index) {
function cancelUpload(index, isSuccess) {
// 确定取消?
setVideoes([...videoes.splice(index, 1)])
const file = files[index]
uploader.cancelFile(file)
files.splice(index, 1)
// const file = files[index]
if (isSuccess) {
uploader.deleteFile(index)
} else {
uploader.cancelFile(index)
}
// files.splice(index, 1)
dispatch({type: 'removeVideo', index})
// setVideoes([...videoes.splice(index, 1)])
}
function onPublish() {
if (state.videoes.length == 0) {
this.props.showNotification('请先上传视频')
return;
}
const publishUrl = `/users/${username}/videos/batch_publish.json`
axios.post(publishUrl, {
videos: state.videoes.map(item => {
return {
video_id: item.videoId,
// todo
title: item.name
}
})
}).then((response) => {
// to success page
if (response.data.status == 0) {
}
}).catch((error) => {
console.log(error)
})
}
// login
const username = props.match.params.username
return (
<div className="educontent videoUploadList">
<style>{`
@ -144,7 +177,7 @@ function VideoUploadList (props) {
<CBreadcrumb
separator=" > "
items={[
{ to: `users/${username}/videoes`, name: '视频'},
{ to: `/users/${username}/videoes`, name: '视频'},
{ name: '上传'}
]}
></CBreadcrumb>
@ -154,7 +187,7 @@ function VideoUploadList (props) {
{state.videoes.map((item, vIndex) => {
return (
<VideoUpload {...props} {...item} className="section"
cancelUpload={cancelUpload}
cancelUpload={cancelUpload} key={vIndex}
index={vIndex}
></VideoUpload>
)
@ -171,6 +204,7 @@ function VideoUploadList (props) {
</Button>
<input type="file" id="fileUpload" style={{display: 'none'}} onChange={onUploadChange}></input>
<ActionBtn className="publishBtn" onClick={() => onPublish()}>立即发布</ActionBtn>
</div>
)
}

Loading…
Cancel
Save