s3Client = Storage::disk('s3')->getClient(); // $this->bucket = config('filesystems.disks.s3.bucket'); // } // /** // * Generate a secure token for content access // */ // public function generateSecureToken(string $contentKey, int $userId, int $expiryMinutes = 30): string // { // $token = Str::random(64); // // Store token with content info in cache // Cache::put("content_token:{$token}", [ // 'content_key' => $contentKey, // 'user_id' => $userId, // 'created_at' => now(), // ], now()->addMinutes($expiryMinutes)); // return $token; // } // /** // * Get secure streaming URL for multimedia content // */ // public function getStreamingUrl(string $contentKey, int $userId): array // { // // Generate signed CloudFront URL or S3 presigned URL // $command = $this->s3Client->getCommand('GetObject', [ // 'Bucket' => $this->bucket, // 'Key' => $contentKey // ]); // $request = $this->s3Client->createPresignedRequest($command, '+30 minutes'); // $signedUrl = (string) $request->getUri(); // // Generate secure token for validation // $token = $this->generateSecureToken($contentKey, $userId); // return [ // 'streaming_url' => $signedUrl, // 'access_token' => $token, // 'expires_in' => 1800 // 30 minutes in seconds // ]; // } // /** // * Get secure PDF viewing URL // */ // public function getPdfViewUrl(string $contentKey, int $userId): array // { // $command = $this->s3Client->getCommand('GetObject', [ // 'Bucket' => $this->bucket, // 'Key' => $contentKey // ]); // $request = $this->s3Client->createPresignedRequest($command, '+30 minutes'); // $signedUrl = (string) $request->getUri(); // $token = $this->generateSecureToken($contentKey, $userId); // return [ // 'pdf_url' => $signedUrl, // 'access_token' => $token, // 'expires_in' => 1800 // ]; // } // /** // * Validate access token // */ // public function validateToken(string $token, int $userId): bool // { // $cacheKey = "content_token:{$token}"; // $tokenData = Cache::get($cacheKey); // if (!$tokenData) { // return false; // } // return $tokenData['user_id'] === $userId; // } // private BookService $bookService; // private SecureContentService $secureContentService; // public function __construct( // BookService $bookService, // SecureContentService $secureContentService // ) { // $this->bookService = $bookService; // $this->secureContentService = $secureContentService; // } // /** // * Get secure content access URLs // */ // public function getSecureContentUrls(Book $book): JsonResponse // { // $this->authorize('view', $book); // $userId = auth()->id(); // if ($book->book_type === 'PDF') { // $accessData = $this->secureContentService->getPdfViewUrl( // $book->download_link, // $userId // ); // } else { // $accessData = $this->secureContentService->getStreamingUrl( // $book->download_link, // $userId // ); // } // return response()->json($accessData); // } // /** // * Validate content access token // */ // public function validateContentAccess(Request $request): JsonResponse // { // $request->validate([ // 'token' => 'required|string' // ]); // $isValid = $this->secureContentService->validateToken( // $request->token, // auth()->id() // ); // return response()->json(['valid' => $isValid]); // } // } // Route::middleware(['auth:api'])->group(function () { // Route::get('/books/{book}/secure-content', [BookController::class, 'getSecureContentUrls']); // Route::post('/content/validate-token', [BookController::class, 'validateContentAccess']); // }); // In SecureContentService // private function logContentAccess(int $userId, string $contentKey): void // { // ContentAccess::create([ // 'user_id' => $userId, // 'content_key' => $contentKey, // 'accessed_at' => now(), // 'ip_address' => request()->ip() // ]); // } // In RouteServiceProvider Route::middleware(['auth:api', 'throttle:60,1'])->group(function () { // Content routes // }); // In SecureContentService // private function addWatermark(string $pdfUrl, User $user): string // { // // Add dynamic watermark with user info and timestamp // // Return watermarked PDF URL // } // import React, { useState, useEffect } from 'react'; // import { Document, Page } from 'react-pdf'; // import axios from 'axios'; // const SecurePDFViewer = ({ bookId }) => { // const [pdfData, setPdfData] = useState(null); // const [numPages, setNumPages] = useState(null); // const [pageNumber, setPageNumber] = useState(1); // const [loading, setLoading] = useState(true); // useEffect(() => { // const fetchSecureContent = async () => { // try { // setLoading(true); // const response = await axios.get(`/api/books/${bookId}/secure-content`); // setPdfData(response.data); // } catch (error) { // console.error('Failed to fetch secure content:', error); // } finally { // setLoading(false); // } // }; // fetchSecureContent(); // // Refresh URL before it expires // const refreshInterval = setInterval(fetchSecureContent, 25 * 60 * 1000); // Refresh every 25 minutes // return () => clearInterval(refreshInterval); // }, [bookId]); // const onDocumentLoadSuccess = ({ numPages }) => { // setNumPages(numPages); // }; // if (loading) { // return