Skip to content

Commit

Permalink
Merge pull request #30 from sunnybraille/request
Browse files Browse the repository at this point in the history
Feat: getting fileName from server when downloading
  • Loading branch information
jun-brro authored Mar 5, 2024
2 parents 8273dde + 14d927c commit 5b58c43
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
3 changes: 0 additions & 3 deletions my-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
Expand Down
4 changes: 2 additions & 2 deletions my-app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "Sunny Braille",
"name": "Online Braille Transcription Service, Sunny Braille",
"icons": [
{
"src": "favicon.ico",
Expand Down
18 changes: 14 additions & 4 deletions my-app/src/components/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ const DownloadButton = () => {
const downloadFile = async (fileId: string) => {
try {
const apiUrl = process.env.REACT_APP_API_URL;
const response = await fetch(`${apiUrl}/translations/${fileId}`);
if (!response.ok) {



const fileResponse = await fetch(`${apiUrl}/translations/${fileId}`);
if (!fileResponse.ok) {
throw new Error("File not found on server");
}
const blob = await response.blob();

const filedata = await fileResponse.json();
const originalFileName = filedata.originalFileName;
if (!originalFileName) {
throw new Error("Original file name is missing");
}

const blob = await fileResponse.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.download = `${fileId}.brf`;
a.download = `${originalFileName}.brf`;
a.href = url;
document.body.appendChild(a);
a.click();
Expand Down
1 change: 0 additions & 1 deletion my-app/src/components/TranslationProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ const TranslationProgress: React.FC<TranslationProgressProps> = ({
}
} catch (error) {
console.error("Error checking the translation status:", error);
// 오류 메시지도 언어에 따라 설정
setProgressMessage(
language === "ko"
? "진행 상황을 불러오는 중 오류가 발생했습니다"
Expand Down
2 changes: 1 addition & 1 deletion my-app/src/pages/DownloadPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const DownloadPage = () => {
if (fileId) {
try {
const response = await axios.get(`/translations/${fileId}`);
setFileName(response.data.convertedFileName);
setFileName(response.data.originalFileName);
} catch (error) {
console.error("파일 정보를 불러오는데 실패했습니다.", error);
}
Expand Down

0 comments on commit 5b58c43

Please sign in to comment.