1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-10 02:40:23 +08:00

finish getFileBlob

This commit is contained in:
源文雨
2023-04-15 23:50:59 +08:00
parent 0e55371ffb
commit 2286438097
5 changed files with 23 additions and 18 deletions

1
.gitignore vendored
View File

@@ -18,3 +18,4 @@
.DS_Store
/data
paper-manager

View File

@@ -1,4 +1,4 @@
import { defHttp } from '/@/utils/http/axios'
import { defHttp, paperHttp } from '/@/utils/http/axios'
import { getFileListModel, AnalyzeFile, FileListGroupItem } from './model/fileListModel'
import { DownloadFile, FileStatus } from './model/fileModel'
@@ -57,6 +57,16 @@ export const downloadFile = (id: number) => {
return defHttp.get<DownloadFile>({ url: Api.DlFile, params: { id: id } })
}
/**
* @description: Download file to blob
*/
export const getFileBlob = (url: string) => {
return paperHttp.get<any>({
responseType: 'blob',
url: url,
})
}
/**
* @description: Get file status
*/

View File

@@ -258,10 +258,11 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
}
export const defHttp = createAxios()
// other api url
// export const otherHttp = createAxios({
// requestOptions: {
// apiUrl: 'xxx',
// urlPrefix: 'xxx',
// },
// });
// download paper
export const paperHttp = createAxios({
requestOptions: {
apiUrl: '',
urlPrefix: '',
isTransformResponse: false,
},
})

View File

@@ -15,15 +15,13 @@
import { PageWrapper } from '/@/components/Page'
import { useECharts } from '/@/hooks/web/useECharts'
import { renderAsync } from 'docx-preview'
import { downloadFile, getFileStatus } from '/@/api/page'
import { downloadFile, getFileStatus, getFileBlob } from '/@/api/page'
import { useMessage } from '/@/hooks/web/useMessage'
import { useGo } from '/@/hooks/web/usePage'
import { useTabs } from '/@/hooks/web/useTabs'
import { PageEnum } from '/@/enums/pageEnum'
import { useI18n } from '/@/hooks/web/useI18n'
import { downloadByData } from '/@/utils/file/download'
import { getToken } from '/@/utils/auth'
import axios from 'axios'
const { t } = useI18n()
@@ -86,13 +84,7 @@
try {
const ret = await downloadFile(Number(params.value.id))
if (ret && ret.url) {
const token = getToken() as string
const { data } = await axios({
method: 'get',
responseType: 'blob',
url: ret.url,
headers: { Authorization: token },
})
const data = await getFileBlob(ret.url)
if (data) {
loadDocx(data)
return

View File

@@ -31,6 +31,7 @@ func main() {
http.HandleFunc("/api/", backend.APIHandler)
http.HandleFunc("/file/", backend.FileHandler)
http.HandleFunc("/paper/", backend.PaperHandler)
http.HandleFunc("/upload", backend.UploadHandler)
logrus.Infoln("[http.Serve] start at", l.Addr())