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">
|
<script setup lang="ts">
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import axiosClient from '@/services/HttpService'
|
import api from '@/services/HttpService'
|
||||||
|
|
||||||
import type { StorageFile } from '@/stores/storage'
|
import type { StorageFile } from '@/stores/storage'
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
|
@ -14,22 +14,22 @@ const filePath =
|
||||||
(fileInfo.value?.pathname || '').split('/').slice(0, -1).join(' / ') + ' / '
|
(fileInfo.value?.pathname || '').split('/').slice(0, -1).join(' / ') + ' / '
|
||||||
|
|
||||||
async function downloadSubmit(path: string | undefined) {
|
async function downloadSubmit(path: string | undefined) {
|
||||||
if (path) {
|
if (!path) return
|
||||||
let formatPath: string
|
|
||||||
|
|
||||||
if (path.split('/').length - 1 === 3) {
|
const arr = path.split('/')
|
||||||
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 res = await axiosClient.get<StorageFile & { download: string }>(
|
if (arr.length < 3 || arr.length > 4) return
|
||||||
`${import.meta.env.VITE_API_ENDPOINT}${formatPath}`,
|
|
||||||
)
|
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
|
await axios
|
||||||
.get(res.data.download, {
|
.get(res.data.downloadUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue