|
|
@@ -32,7 +32,7 @@ const CHUNK_SIZE = 10 * 1024 * 1024
|
|
|
// 开启后,空闲线程优先满足单个文件
|
|
|
// 关闭时,多线程数为同时上传的文件数最大数,当一个块上传完时会启用空闲线程协助上传
|
|
|
const COMPLETE_FIRST = false
|
|
|
-const CHECK_H264 = false
|
|
|
+const CHECK_VIDEO = false
|
|
|
|
|
|
const files = []
|
|
|
const analyzeQueue = []
|
|
|
@@ -60,7 +60,7 @@ export function appendFile (file) {
|
|
|
console.log(`添加文件${obj.name}, ${obj.totalSize}, ${file.type}`)
|
|
|
files.push(obj)
|
|
|
emitChange()
|
|
|
- if (CHECK_H264 && fileType === AssetType.VIDEO) {
|
|
|
+ if (CHECK_VIDEO && fileType === AssetType.VIDEO) {
|
|
|
analyzeQueue.push(obj)
|
|
|
analyzeMediaInfo()
|
|
|
} else {
|
|
|
@@ -99,16 +99,22 @@ function analyzeByWorker (obj) {
|
|
|
resolve()
|
|
|
} else {
|
|
|
console.log(media)
|
|
|
- if (media.track[1].Format !== 'AVC') {
|
|
|
- MessageBox.confirm(
|
|
|
- `视频 ${obj.name} 非H264编码将无法预览,确定上传?`,
|
|
|
- '提示',
|
|
|
- {
|
|
|
- type: 'warning',
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消'
|
|
|
- }
|
|
|
- ).then(resolve, reject)
|
|
|
+ const videoTrack = media.track.find(({ type }) => type === 'VIDEO')
|
|
|
+ if (videoTrack) {
|
|
|
+ obj.duration = parseInt(videoTrack.Duration) | 0
|
|
|
+ if (videoTrack.Format !== 'AVC') {
|
|
|
+ MessageBox.confirm(
|
|
|
+ `视频 ${obj.name} 非H264编码将无法预览,确定上传?`,
|
|
|
+ '提示',
|
|
|
+ {
|
|
|
+ type: 'warning',
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消'
|
|
|
+ }
|
|
|
+ ).then(resolve, reject)
|
|
|
+ } else {
|
|
|
+ resolve()
|
|
|
+ }
|
|
|
} else {
|
|
|
resolve()
|
|
|
}
|
|
|
@@ -539,7 +545,6 @@ function shuntTask () {
|
|
|
}
|
|
|
obj.source = CancelToken.source()
|
|
|
setState(obj, State.UPLOADING)
|
|
|
- // startSimpleTask(obj)
|
|
|
startChunkTask(obj)
|
|
|
}
|
|
|
|
|
|
@@ -548,15 +553,6 @@ function idleTask () {
|
|
|
shuntTask()
|
|
|
}
|
|
|
|
|
|
-function idleTaskByError (obj, error) {
|
|
|
- if (!isResolved(obj)) {
|
|
|
- obj.source?.cancel(error)
|
|
|
- obj.source = null
|
|
|
- setInvalid(obj, `${obj.name}上传失败`, error)
|
|
|
- }
|
|
|
- idleTask()
|
|
|
-}
|
|
|
-
|
|
|
function finish (obj) {
|
|
|
const { id, hash, name, type } = obj
|
|
|
Message({
|
|
|
@@ -571,42 +567,6 @@ function transformName (name) {
|
|
|
return name.replace(/\.[^.]+$/, '')
|
|
|
}
|
|
|
|
|
|
-/* eslint-disable */
|
|
|
-async function startSimpleTask (obj) {
|
|
|
- idle -= 1
|
|
|
- try {
|
|
|
- const { source, name, type, totalSize, hash, file } = obj
|
|
|
- const formData = new FormData()
|
|
|
- formData.append('identifier', hash)
|
|
|
- formData.append('filename', transformName(name))
|
|
|
- formData.append('size', totalSize)
|
|
|
- formData.append('file', file)
|
|
|
- console.log(`开始上传${name}`)
|
|
|
- await request({
|
|
|
- url: '/minio-data/upload',
|
|
|
- method: 'post',
|
|
|
- params: { type },
|
|
|
- data: formData,
|
|
|
- timeout: 0,
|
|
|
- onUploadProgress ({ loaded, total }) {
|
|
|
- obj.uploaded = loaded
|
|
|
- obj.totalChunks = total
|
|
|
- emitChange()
|
|
|
- },
|
|
|
- cancelToken: source.token,
|
|
|
- custom: true,
|
|
|
- background: true
|
|
|
- })
|
|
|
- obj.uploaded = 1
|
|
|
- obj.totalChunks = 1
|
|
|
- idleTask()
|
|
|
- finish(obj)
|
|
|
- } catch (e) {
|
|
|
- idleTaskByError(obj, e)
|
|
|
- }
|
|
|
-}
|
|
|
-/* eslint-enable */
|
|
|
-
|
|
|
function startChunkTask (obj) {
|
|
|
idle -= 1
|
|
|
const { name, hash, source, chunks, totalChunks } = obj
|
|
|
@@ -664,7 +624,10 @@ function startChunkTask (obj) {
|
|
|
console.log(`${name}第${index + 1}个切片上传失败第${chunk.error}次`, e)
|
|
|
if (chunk.error === 3) {
|
|
|
chunk.error = 0
|
|
|
- idleTaskByError(obj, { index })
|
|
|
+ obj.source?.cancel(e)
|
|
|
+ obj.source = null
|
|
|
+ setInvalid(obj, `${name}上传失败`)
|
|
|
+ idleTask()
|
|
|
} else {
|
|
|
start(sub)
|
|
|
}
|
|
|
@@ -679,9 +642,9 @@ function startChunkTask (obj) {
|
|
|
}
|
|
|
|
|
|
function startMerge (obj) {
|
|
|
+ const { hash, name, type, totalSize, totalChunks } = obj
|
|
|
console.log(`开始合并${name}`)
|
|
|
setState(obj, State.MERGING)
|
|
|
- const { hash, name, type, totalSize, totalChunks } = obj
|
|
|
request({
|
|
|
url: '/minio-data/chunk/reduce',
|
|
|
method: 'post',
|
|
|
@@ -690,7 +653,8 @@ function startMerge (obj) {
|
|
|
filename: transformName(name),
|
|
|
type,
|
|
|
totalSize,
|
|
|
- totalChunks
|
|
|
+ totalChunks,
|
|
|
+ duration: type === AssetType.VIDEO ? obj.duration : void 0
|
|
|
},
|
|
|
timeout: 0,
|
|
|
custom: true,
|