From 844a5a7b9c8350d96226926053b47fa503206190 Mon Sep 17 00:00:00 2001 From: shinmj Date: Wed, 29 Dec 2021 14:54:14 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20download=20url=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/admin/src/service/Attachment.ts | 25 +++++++++++++------ .../portal/src/pages/auth/logout/index.tsx | 22 +++++++++++----- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/frontend/admin/src/service/Attachment.ts b/frontend/admin/src/service/Attachment.ts index a779ae7..1948378 100644 --- a/frontend/admin/src/service/Attachment.ts +++ b/frontend/admin/src/service/Attachment.ts @@ -1,7 +1,7 @@ +import { Page } from '@utils' import axios, { AxiosError } from 'axios' import useSWR from 'swr' import { common, SearchPayload } from './common' -import { Page } from '@utils' /** * request payload @@ -55,14 +55,23 @@ export const attachmentService = { errorCallback(error) } }, - download: (id: string) => { // 첨부파일 다운로드 - 삭제 파일 가능 - axios.get(`${ATTACHMENT_API}/download/${id}`, { - responseType: 'blob', - }) - .then(response =>{ - const downloadFileName = decodeURIComponent(response.headers['content-disposition'].replace('attachment; filename*=UTF-8\'\'', '')) + download: (id: string) => { + // 첨부파일 다운로드 - 삭제 파일 가능 + axios + .get(`/portal-service/api/v1/download/${id}`, { + responseType: 'blob', + }) + .then(response => { + const downloadFileName = decodeURIComponent( + response.headers['content-disposition'].replace( + "attachment; filename*=UTF-8''", + '', + ), + ) - const url = window.URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type'] })) + const url = window.URL.createObjectURL( + new Blob([response.data], { type: response.headers['content-type'] }), + ) let link = document.createElement('a') link.href = url link.setAttribute('download', downloadFileName) diff --git a/frontend/portal/src/pages/auth/logout/index.tsx b/frontend/portal/src/pages/auth/logout/index.tsx index 018b76b..8081d6f 100644 --- a/frontend/portal/src/pages/auth/logout/index.tsx +++ b/frontend/portal/src/pages/auth/logout/index.tsx @@ -16,7 +16,12 @@ function Logout() { ) } -export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { +export const getServerSideProps: GetServerSideProps = async ({ + req, + res, + query, +}) => { + console.log(query) if (!process.browser) { const Cookies = require('cookies') const cookies = new Cookies(req, res) @@ -26,12 +31,17 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { axios.defaults.headers.common[CLAIM_NAME] = '' axios.defaults.headers.common[AUTH_USER_ID] = '' - const { redirect } = req['query'] + try { + const { redirect } = req['query'] - res.writeHead(307, { - Location: typeof redirect !== 'undefined' ? redirect : '/', - }) - res.end() + res.writeHead(307, { + Location: typeof redirect !== 'undefined' ? redirect : '/', + }) + res.end() + } catch (error) { + res.writeHead(307, { Location: '/' }) + res.end() + } } return {