Kaynağa Gözat

feat(upload): support image resolution reporting

Casper Dai 3 yıl önce
ebeveyn
işleme
26d7c8c614
1 değiştirilmiş dosya ile 23 ekleme ve 17 silme
  1. 23 17
      src/utils/upload.js

+ 23 - 17
src/utils/upload.js

@@ -60,7 +60,7 @@ export function appendFile (file) {
   console.log(`添加文件${obj.name}, ${obj.totalSize}, ${file.type}`)
   files.push(obj)
   emitChange()
-  if (ANALYSIS_FILE && (fileType === AssetType.VIDEO || fileType === AssetType.AUDIO)) {
+  if (ANALYSIS_FILE) {
     analyzeQueue.push(obj)
     analyzeMediaInfo()
   } else {
@@ -94,28 +94,33 @@ function analyzeByWorker (obj) {
     const worker = new Worker('/mediainfo.js')
     worker.onmessage = e => {
       const { error, media } = e.data
+
       if (error) {
         console.log(`解析文件${obj.name}失败`, error)
-        resolve()
       } else {
         console.log(media)
-        const generalTrack = media.track.find(track => track['@type'] === 'General')
-        obj.duration = generalTrack ? parseInt(generalTrack.Duration) | 0 : 0
-
-        const videoTrack = media.track.find(track => track['@type'] === 'Video')
-        if (videoTrack) {
-          if (videoTrack.Format !== 'AVC') {
-            MessageBox.confirm(
-              `视频 ${obj.name} 非H264编码将无法预览,确定上传?`,
-              { type: 'warning' }
-            ).then(resolve, reject)
-          } else {
-            resolve()
+
+        if (obj.type === AssetType.IMAGE) {
+          const imageTrack = media.track.find(track => track['@type'] === 'Image')
+          if (imageTrack) {
+            obj.resolutionRatio = `${imageTrack.Width}x${imageTrack.Height}`
           }
         } else {
-          resolve()
+          const generalTrack = media.track.find(track => track['@type'] === 'General')
+          obj.duration = generalTrack ? parseInt(generalTrack.Duration) | 0 : 0
+          if (obj.type === AssetType.VIDEO) {
+            const videoTrack = media.track.find(track => track['@type'] === 'Video')
+            if (videoTrack && videoTrack.Format !== 'AVC') {
+              return MessageBox.confirm(
+                `视频 ${obj.name} 非H264编码将无法预览,确定上传?`,
+                { type: 'warning' }
+              ).then(resolve, reject)
+            }
+          }
         }
       }
+
+      resolve()
       worker.terminate()
     }
     worker.onmessageerror = worker.onerror = e => {
@@ -633,7 +638,7 @@ function startChunkTask (obj) {
 }
 
 function startMerge (obj) {
-  const { hash, name, type, totalSize, totalChunks } = obj
+  const { hash, name, type, totalSize, totalChunks, resolutionRatio, duration } = obj
   console.log(`开始合并${name}`)
   setState(obj, State.MERGING)
   request({
@@ -645,7 +650,8 @@ function startMerge (obj) {
       type,
       totalSize,
       totalChunks,
-      duration: obj.duration
+      resolutionRatio,
+      duration
     },
     timeout: 0,
     custom: true,