Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

62 파일별 다운로드 페이지 라우팅 #84

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const App: React.FC = () => (
}
>
<Route index element={<MainPage />} />
<Route path="/download" element={<DownloadPage />} />
<Route path="/download/:fileid" element={<DownloadPage />} />
<Route path="/delete" element={<DeletePage />} />
<Route path="/filelist" element={<FileListPage />} />
<Route path="/api/*" element={<ApiPage />} />
Expand Down
30 changes: 17 additions & 13 deletions src/pages/download/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import { useParams } from 'react-router-dom';
import { toast } from 'react-toastify';

import { Button, FileBox, SkeletonUI } from '../../components';
Expand All @@ -14,6 +15,7 @@ export const DownloadPage: React.FC = () => {
const navigate = useNavigate();
const downloadFileProps: any = useSelector((state: RootState) => state.DownloadFileProps);
const [loading, setLoading] = useState(true);
const { fileid } = useParams<{ fileid: string }>();
const [fileProps, setFileProps] = useState({
filename: '',
// fileId: '',
Expand All @@ -34,7 +36,7 @@ export const DownloadPage: React.FC = () => {
const getFileProps = async () => {
await axios({
method: 'get',
url: `${process.env.REACT_APP_BACKEND_BASEURL}/file/${downloadFileProps.fileId}${
url: `${process.env.REACT_APP_BACKEND_BASEURL}/file/${fileid}${
downloadFileProps.isEncrypted ? `?token=${downloadFileProps.token}` : ''
}`,
})
Expand All @@ -51,20 +53,22 @@ export const DownloadPage: React.FC = () => {
});
})
.catch((err) => {
navigate(-1);
toast.error(`error 문의해주세요. ${err.response.status}`, {
autoClose: 1000,
position: toast.POSITION.BOTTOM_RIGHT,
});
console.log(err);
navigate('/');
if (err.response.status != 401) {
toast.error(`error 문의해주세요. ${err.response.status}`, {
autoClose: 1000,
position: toast.POSITION.BOTTOM_RIGHT,
});
} else {
toast.error(`잘못된 링크입니다`, {
autoClose: 1000,
position: toast.POSITION.BOTTOM_RIGHT,
});
}
});
};
if (downloadFileProps.fileId != null) {
getFileProps();
} else {
navigate('/');
}
}, [downloadFileProps, navigate]);
getFileProps();
}, [downloadFileProps, navigate, fileid]);
return (
<S.DownloadPageContainer>
{!loading ? (
Expand Down
3 changes: 1 addition & 2 deletions src/pages/filelist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ export const FileListPage: React.FC = () => {
navigate('/checkpw');
} else {
SetDownloadFileProps({
filename: item.filename,
fileId: item.fileId,
isEncrypted: item.isEncrypted,
token: null,
});
navigate('/download');
navigate(`/download/${item.fileId}`);
}
}}
/>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ export const MainPage: React.FC = () => {
position: toast.POSITION.BOTTOM_RIGHT,
});
SetDownloadFileProps({
filename: res.data.filename,
fileId: res.data.fileId,
token: res.data.isEncrypted ? res.data.token : null,
isEncrypted: res.data.isEncrypted,
//추후에 기한,다운로드횟수 추가예정
});
navigate('/download');
navigate(`/download/${res.data.fileId}`);
})
.catch((err) => {
console.log(err);
Expand Down