@@ -6,7 +6,6 @@ import axios, { type AxiosError } from "axios";
66import { Button } from "@/components/ui/button" ;
77import { type IPaper , type Filters } from "@/interface" ;
88import Card from "./Card" ;
9- import { extractBracketContent } from "@/util/utils" ;
109import { useRouter } from "next/navigation" ;
1110import Loader from "./ui/loader" ;
1211import SideBar from "../components/SideBar" ;
@@ -15,6 +14,7 @@ import { Filter } from "lucide-react";
1514import { Sheet , SheetContent , SheetTrigger } from "./ui/sheet" ;
1615import { Pin } from "lucide-react" ;
1716import { StoredSubjects } from "@/interface" ;
17+ import { getSecureUrl , generateFileName , downloadFile } from "@/util/download" ;
1818
1919const CatalogueContent = ( ) => {
2020 const router = useRouter ( ) ;
@@ -163,28 +163,6 @@ const CatalogueContent = () => {
163163 [ ] ,
164164 ) ;
165165
166- const getSecureUrl = ( url : string ) : string =>
167- url . startsWith ( "http://" ) ? url . replace ( "http://" , "https://" ) : url ;
168-
169- const generateFileName = ( paper : IPaper ) : string => {
170- const extension = paper . final_url . split ( "." ) . pop ( ) ;
171- return `${ extractBracketContent ( paper . subject ) } -${ paper . exam } -${ paper . slot } -${ paper . year } .${ extension } ` ;
172- } ;
173-
174- const downloadFile = async ( url : string , filename : string ) : Promise < void > => {
175- try {
176- const response = await axios . get ( url , { responseType : "blob" } ) ;
177- const blob = new Blob ( [ response . data ] ) ;
178- const link = document . createElement ( "a" ) ;
179- link . href = window . URL . createObjectURL ( blob ) ;
180- link . download = filename ;
181- link . click ( ) ;
182- window . URL . revokeObjectURL ( link . href ) ;
183- } catch ( error ) {
184- console . error ( "Download failed:" , error ) ;
185- }
186- } ;
187-
188166 const handleDownloadAll = useCallback ( async ( ) => {
189167 const uniquePapers = Array . from (
190168 new Set ( selectedPapers . map ( ( paper ) => paper . _id ) ) ,
0 commit comments