From 508867ad13998e4b08e88d220e7a502257436797 Mon Sep 17 00:00:00 2001 From: Mayank Arya Date: Sun, 6 Sep 2026 00:43:59 +0530 Subject: [PATCH 1/3] Added View and Download Option --- admin/src/apis/courses.js | 18 +++++++ admin/src/pages/CourseDashboard.jsx | 53 +++++++++++++++++-- client/.env.example | 2 - .../contribution/contribution.model.js | 2 +- 4 files changed, 68 insertions(+), 7 deletions(-) delete mode 100644 client/.env.example diff --git a/admin/src/apis/courses.js b/admin/src/apis/courses.js index 2308f46c..886c3f92 100644 --- a/admin/src/apis/courses.js +++ b/admin/src/apis/courses.js @@ -246,3 +246,21 @@ export const deleteNode = async(type,id) => } } + +export const getFileDownloadUrl = async (fileId) => { + try { + const response = await fetch(`${API_BASE_URL}api/file/download/${fileId}`, { + headers: { + Authorization: "Bearer admin-coursehub-cc23-golang", + }, + credentials: "include", + }); + if (!response.ok) { + throw new Error("Failed to get download link"); + } + return await response.json(); // { url: "..." } + } catch (error) { + console.error("Error getting download link:", error); + throw error; + } +}; \ No newline at end of file diff --git a/admin/src/pages/CourseDashboard.jsx b/admin/src/pages/CourseDashboard.jsx index c45885c6..28745bea 100644 --- a/admin/src/pages/CourseDashboard.jsx +++ b/admin/src/pages/CourseDashboard.jsx @@ -1,6 +1,6 @@ import { useParams} from "react-router-dom"; import React, { useEffect, useState } from "react"; -import { fetchCourseDashboardData, deleteNode, handleContribution } from "@/apis/courses"; +import { fetchCourseDashboardData, deleteNode, handleContribution, getFileDownloadUrl } from "@/apis/courses"; import { FiFolder, FiFile, @@ -70,6 +70,7 @@ function LoadStructure({ node, onDelete, depth = 0 }) { ); } + export default function CourseDashboard() { const { code } = useParams(); @@ -154,6 +155,23 @@ export default function CourseDashboard() { const pendingContributions = data?.contributions?.filter(c => !c.approved) || []; + const handleDownload = async(fileId) => + { + try + { + const data = await getFileDownloadUrl(fileId); + if(data?.url) + { + window.location.href = data.url; + } + } + catch(error) + { + console.log(error); + alert("Failed to get download "); + } + }; + return (
@@ -232,10 +250,37 @@ export default function CourseDashboard() {
-
- {contribution.files?.map(f => f.name).join(", ") || contribution.contributionId} +
+ {contribution.files && contribution.files.length > 0 ? ( +
+ {contribution.files.map((file) => ( +
+ {file.name} + {file.webUrl && ( + + View + + )} + {file.downloadUrl && ( + + )} +
+ ))} +
+ ) : ( + contribution.contributionId + )}
-
Awaiting review