<script setup name="fileView">
// import { renderAsync } from 'docx-preview'
import { downloadToPdfStreamFileUrl, downloadFileUrl } from '@/utils/uploadAction.js'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { downFileById } from '@/http/apis/commonApi'
const route = useRoute(),
  fileRef = ref()
onMounted(async () => {
  if (import.meta.env.MODE === 'production') {
    window.location.href = await downloadToPdfStreamFileUrl(route.query.id)
  } else {
    const res = await downFileById({ fileId: route.query.id })
    if (
      res.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || res.type === 'application/msword'
    ) {
      window.location.href = await downloadToPdfStreamFileUrl(route.query.id)
    } else {
      window.location.href = await downloadFileUrl(route.query.id)
    }
  }
})
</script>

<template>
  <div ref="fileRef"></div>
</template>
