101 lines
4.1 KiB
JavaScript
101 lines
4.1 KiB
JavaScript
// import React, { useState, useEffect } from 'react';
|
|
// //import gapi from 'gapi';
|
|
|
|
// // // import { Document, Page } from 'react-pdf';
|
|
|
|
|
|
// // const CLIENT_ID = '926212607479-d3m8hm8f8esp3rf1639prskn445sa01v.apps.googleusercontent.com';
|
|
// // const API_KEY = 'AIzaSyBUtqjxvCLv2GVcVFEPVym7vRtVW-qP4Jw';
|
|
// // const DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"];
|
|
// // const SCOPES = 'https://www.googleapis.com/auth/drive.readonly';
|
|
|
|
|
|
const GoogleDriveFolderPreview = ({ folderId }) => {
|
|
// const folderUrl = `https://drive.google.com/drive/folders/${folderId}`;
|
|
// const [files, setFiles] = useState([]);
|
|
|
|
// useEffect(() =>
|
|
// fetch(folderUrl)
|
|
// .then(res => res.text())
|
|
// .then(text => {
|
|
// const parser = new DOMParser();
|
|
// const htmlDocument = parser.parseFromString(text, 'text/html');
|
|
// const fileElements = htmlDocument.querySelectorAll('.Q5txwe');
|
|
// const files = Array.from(fileElements).map(fileElement => {
|
|
// const fileUrl = fileElement.getAttribute('href');
|
|
// const fileName = fileElement.querySelector('.Q5txwe').textContent;
|
|
// return { fileUrl, fileName };
|
|
// });
|
|
// setFiles(files);
|
|
// })
|
|
// , [folderUrl]);
|
|
|
|
// return (
|
|
// <div className="grid grid-cols-3 gap-4">
|
|
// {files.map(file => (
|
|
// <div key={file.fileUrl} className="pdf-preview">
|
|
// <iframe src={`https://drive.google.com/file/d/${file.fileUrl}/preview`} width="640" height="480"></iframe>
|
|
// </div>
|
|
// ))}
|
|
// </div>
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
// // useEffect(() => {
|
|
// // // Initialize the Google API client library
|
|
// // gapi.load('client:auth2', () => {
|
|
// // gapi.client.init({
|
|
// // apiKey: API_KEY,
|
|
// // clientId: CLIENT_ID,
|
|
// // discoveryDocs: DISCOVERY_DOCS,
|
|
// // scope: SCOPES
|
|
// // }).then(() => {
|
|
// // // Listen for sign-in state changes and handle the signed-in state
|
|
// // gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
|
|
// // updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
|
|
// // });
|
|
// // });
|
|
|
|
// // const updateSigninStatus = (isSignedIn) => {
|
|
// // if (isSignedIn) {
|
|
// // fetchFiles();
|
|
// // } else {
|
|
// // gapi.auth2.getAuthInstance().signIn();
|
|
// // }
|
|
// // };
|
|
|
|
// // const fetchFiles = async () => {
|
|
// // const response = await gapi.client.drive.files.list({
|
|
// // q: `'${folderId}' in parents and mimeType = 'application/pdf'`,
|
|
// // fields: 'files(id, name, webContentLink)'
|
|
// // });
|
|
// // setFiles(response.result.files);
|
|
// // };
|
|
// // }, [folderId]);
|
|
|
|
|
|
// // const PdfDocument = ({ file }) => {
|
|
// // return (
|
|
// // <Document file={file}>
|
|
// // <Page pageNumber={1} />
|
|
// // {/* Render other pages as needed */}
|
|
// // </Document>
|
|
// // );
|
|
// // };
|
|
|
|
// // return (
|
|
// // <div className="grid grid-cols-3 gap-4">
|
|
// // {files.map(file => (
|
|
// // <div key={file.id} className="pdf-preview">
|
|
// // <PdfDocument fileUrl={file.url} />
|
|
// // </div>
|
|
// // ))}
|
|
// // </div>
|
|
// // );
|
|
};
|
|
|
|
export default GoogleDriveFolderPreview;
|