Skip to content

Commit 0295777

Browse files
authored
Merge pull request #123 from Coding-Club-IITG/aditya
Resolved Conflicts
2 parents fc68111 + 4fb7dd7 commit 0295777

5 files changed

Lines changed: 34 additions & 17 deletions

File tree

client/src/api/File.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,22 @@ export const getThumbnail = async (fileId) => {
5353
});
5454
console.log("Thumbnail Refreshed");
5555
};
56+
57+
export const getFileDownloadLink = async (fileId) => {
58+
const response = await fetch( serverRoot + '/api/files/download',{
59+
method: 'POST',
60+
headers: {
61+
'Content-Type': 'application/json',
62+
},
63+
body: JSON.stringify({ url: fileId }),
64+
})
65+
66+
if (!response.ok) {
67+
throw new Error(`Error fetching download link: ${response.statusText}`);
68+
}
69+
70+
const data = await response.json();
71+
return data.downloadLink;
72+
};
73+
74+

client/src/api/Folder.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ export const deleteFolder = async ({ folder, parentFolderId }) => {
2929
});
3030
return data;
3131
};
32+
33+
export const fetchFolder = async (folderId) => {
34+
const response = await API.get(`/folder/content/${folderId}`);
35+
if (response.status !== 200) {
36+
throw new Error("Failed to fetch folder data");
37+
}
38+
const data = response.data;
39+
return data;
40+
}

client/src/screens/browse/components/file-display/index.jsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Share from "../../../share";
1414
import { verifyFile, unverifyFile } from "../../../../api/File";
1515
import { RemoveFileFromFolder, UpdateFileVerificationStatus } from "../../../../actions/filebrowser_actions.js";
1616
import ConfirmDialog from "./components/ConfirmDialog.jsx";
17+
import { getFileDownloadLink } from "../../../../api/File";
1718
import server from "../../../../api/server.js";
1819

1920
const FileDisplay = ({ file, path, code }) => {
@@ -66,16 +67,7 @@ const FileDisplay = ({ file, path, code }) => {
6667
return;
6768
}
6869

69-
const response = await fetch( server + '/api/files/download',{
70-
method: 'POST',
71-
headers: {
72-
'Content-Type': 'application/json',
73-
},
74-
body: JSON.stringify({ url: file.webUrl }),
75-
})
76-
77-
const data = await response.json();
78-
const downloadLink = data.downloadLink;
70+
const downloadLink = await getFileDownloadLink(file.webUrl);
7971

8072
if (!downloadLink) {
8173
toast.error("Failed to generate download link.");

client/src/screens/browse/components/folder-info/index.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ConfirmDialog } from "./confirmDialog";
1919
import server from "../../../../api/server";
2020
import JSZip from "jszip";
2121
import { saveAs } from "file-saver";
22+
import { fetchFolder } from "../../../../api/Folder";
2223

2324
const FolderInfo = ({
2425
isBR,
@@ -107,13 +108,8 @@ const FolderInfo = ({
107108

108109
const downloadFolder = async (id, folderPath = "") => {
109110
try {
110-
const response = await fetch(`${server}/api/folder/content/${id}`);
111-
if (!response.ok) {
112-
toast.error("Failed to download folder content.");
113-
return null;
114-
}
111+
const data = await fetchFolder(id);
115112

116-
const data = await response.json();
117113
const zip = new JSZip();
118114

119115
// Process all children

server/scripts/downloadFile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ const encodeGraphShareUrl = (shareUrl) => {
1515
return `u!${base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`;
1616
};
1717

18-
const access = await getAccessToken();
18+
1919

2020
export const downloadFiles = async (req, res) => {
21+
const access = await getAccessToken();
2122
try {
2223
const inputUrl = req.body?.url;
2324
if (!inputUrl) {

0 commit comments

Comments
 (0)