compressVideo.ts 743 字节
Newer Older
inkwalk's avatar
inkwalk 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import { extend } from '@vue/shared'
import { getFileName } from '../../../helpers/file'
import { TEMP_PATH } from '../constants'
import {
  API_COMPRESS_VIDEO,
  API_TYPE_COMPRESS_VIDEO,
  defineAsyncApi,
  CompressVideoOptions,
  CompressVideoProtocol,
} from '@dcloudio/uni-api'

export const compressVideo = defineAsyncApi<API_TYPE_COMPRESS_VIDEO>(
  API_COMPRESS_VIDEO,
  (options, { resolve, reject }) => {
    const dst = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(
      options.src
    )}`
    plus.zip.compressVideo(
      extend({}, options, {
        dst,
      }),
      () => {
        resolve({
          tempFilePath: dst,
        })
      },
      reject
    )
  },
  CompressVideoProtocol,
  CompressVideoOptions
)