import request from 'libs/request'
const UploadUrl = '//127.0.0.1:1935'
export function uploadFile (file, opts) {
  if (!file) return new Promise(resolve => resolve())
  if (file.type === 'image/png' || file.type === 'image/jpeg') {
    return uploadPic(file, opts)
  }
  return uploadVideo(file)
}

export function uploadPic (file, opts) {
  let formData = new FormData()
  formData.append('file', file)
  if (opts) {
    Object.keys(opts).forEach(item => {
      formData.append(item, opts[item])
    })
  }
  return request.post(`../node-upload/uploadfile`, formData)
}

// export function uploadPic (file) {
//   let formData = new FormData()
//   formData.append('file', file)
//   formData.append('quality', 90)
//   return request.post(`../node-upload/localfile`, formData)
// }


export function uploadVideo (file) {
  let formData = new FormData()

  formData.append('file', file)
  return request.post(`../node-upload/upLoadVideo`, formData)
}

export function getVideoFirstImage (object_name) {
  return request.get('house/getFirstImage', { params: { object_name }})
}