refactor: use new endpoint
This commit is contained in:
parent
42aa7e7037
commit
4aef7c144b
1 changed files with 14 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
import axios from 'axios'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import axiosClient from '@/services/HttpService'
|
||||
import api from '@/services/HttpService'
|
||||
|
||||
import type { StorageFile } from '@/stores/storage'
|
||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||
|
|
@ -14,22 +14,22 @@ const filePath =
|
|||
(fileInfo.value?.pathname || '').split('/').slice(0, -1).join(' / ') + ' / '
|
||||
|
||||
async function downloadSubmit(path: string | undefined) {
|
||||
if (path) {
|
||||
let formatPath: string
|
||||
if (!path) return
|
||||
|
||||
if (path.split('/').length - 1 === 3) {
|
||||
const [cabinet, drawer, folder, file] = path.split('/')
|
||||
formatPath = `cabinet/${cabinet}/drawer/${drawer}/folder/${folder}/file/${file}`
|
||||
} else {
|
||||
const [cabinet, drawer, folder, subfolder, file] = path.split('/')
|
||||
formatPath = `cabinet/${cabinet}/drawer/${drawer}/folder/${folder}/subfolder/${subfolder}/file/${file}`
|
||||
}
|
||||
const arr = path.split('/')
|
||||
|
||||
const res = await axiosClient.get<StorageFile & { download: string }>(
|
||||
`${import.meta.env.VITE_API_ENDPOINT}${formatPath}`,
|
||||
)
|
||||
if (arr.length < 3 || arr.length > 4) return
|
||||
|
||||
const file = arr.pop()
|
||||
|
||||
const res = await api.post<StorageFile & { downloadUrl: string }>(
|
||||
`${import.meta.env.VITE_API_ENDPOINT}storage/file/download`,
|
||||
{ path: arr, file },
|
||||
)
|
||||
|
||||
if (res.status === 200 && res.data && res.data.downloadUrl) {
|
||||
await axios
|
||||
.get(res.data.download, {
|
||||
.get(res.data.downloadUrl, {
|
||||
method: 'GET',
|
||||
responseType: 'blob',
|
||||
headers: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue