1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-30 07:40:28 +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 .DS_Store
/data /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 { getFileListModel, AnalyzeFile, FileListGroupItem } from './model/fileListModel'
import { DownloadFile, FileStatus } from './model/fileModel' 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 } }) 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 * @description: Get file status
*/ */

View File

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

View File

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

View File

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